Giter Site home page Giter Site logo

vue-heatmapjs's Introduction

example

vue-heatmapjs

npm version

A vue directive for collecting and displaying user activity on a component

Install

You can use NPM or Yarn to add this plugin to your project

npm install vue-heatmapjs
# or
yarn add vue-heatmapjs

Usage

You need to install this plugin in you main.js

// main.js

import Vue from 'vue'
import heatmap from 'vue-heatmapjs'

Vue.use(heatmap)

v-heatmap

And then you can add the v-heatmap directive to the dom elements you want to track.

<!-- App.vue -->
<div v-heatmap>
  ...
</div>

v-scrollmap

You can use the v-scrollmap directive to collect scroll position data from your application

<!-- App.vue -->
<div v-scrollmap>
  ...
</div>

Toggle heatmap

You can toggle the heatmaps on and off by passing an expression into the directive, the example below will produce something similar to the image at the top of these docs

<template>
  ...
  <div v-heatmap="show" v-scrollmap="show"></div>
  <button @click="show = !show">Toggle Heatmap</button>
  ...
</template>

<script>
  ...
    data() {
      return {
        show: false,
      }
    },
  ...
</script>

Listen for events

Streams

You can pass in an Observable into the plugin options and subscribe to events captured for the heatmaps.

// main.js
import { Subject } from 'rxjs';

const stream = new Subject();
Vue.use(Vueheatmap, {
  stream,
});

stream.subscribe(console.log);

Callback

You can pass an afterAdd method through with the plugin options, this will allow you to access and process the events captured for the heatmap

// main.js

Vue.use(heatmap, {
  afterAdd(data) {
    console.log(data)
    // you can fire this back to your analytics server
  },
})

Pause collection

You can pass an RXJS Subject through with the plugin options that will allow you to toggle whether your directives collect data or not

//main.js
export const pauser = new Subject();

Vue.config.productionTip = false;
Vue.use(Vueheatmap, {
  pauser,
});
// Pause data collection
pauser.next(true);
// Resume data collection
pauser.next(false);

Preload heatmap

Once you have captured heatmap data and persisted the data somewhere you will probably need a way of loading this data back in to your heatmap.

You can pass in an array of heatmap events using the heatmap preload plugin option

//main.js
Vue.use(Vueheatmap, {
  heatmapPreload: [{ x: 10, y: 10, value: 100 }],
});

The plugin can also handle a Promise

//main.js
Vue.use(Vueheatmap, {
  heatmapPreload: fetch('http://api.example.com').then(response => response.json()),
});

vue-heatmapjs's People

Contributors

brockreece avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.