Giter Club home page Giter Club logo

vue-keen-tracking's Introduction

npm badge

Vue plugin built on keen-tracking.js.

Install

npm install vue-keen-tracking --save
import VueKeen from "vue-keen-tracking";

const options = {
  projectId: "<KEEN_PROJECT_ID>",
  writeKey: "<KEEN_WRITE_KEY>"
};

Vue.use(VueKeen, options);

You can then access the KeenTracking object through this.$keen in any of your components/views.

Auto tracking

You can add autoTracking: { ... } to configure Keens auto-tracking.

const options = {
  projectId: "<KEEN_PROJECT_ID>",
  writeKey: "<KEEN_WRITE_KEY>",
  autoTracking: { 
    recordPageViews: true,
    ...
  }
};

Vue-Router and Vuex

To track events from vue-router or vuex, extend your config with this:

import VueRouter from "vue-router";
import Vuex from "vuex";

Vue.use(Vuex);
Vue.use(VueRouter);

const router = require("./router");
const store = require("./store");

const options = {
  projectId: "<KEEN_PROJECT_ID>",
  writeKey: "<KEEN_WRITE_KEY>",
  trackRoutes: {
    router: router
  },
  trackVuex: {
    store: store,
    mutations: true,
    actions: true
  }
};

Extend event properties

API reference

const user = await fetchUser();
this.$keen.extendEvents({ user })

Record an event

API reference

this.$keen.recordEvent("purchases", {
  item: "avocado"
});

vue-keen-tracking's People

Contributors

maxpaj avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

t0ster

vue-keen-tracking's Issues

Using Keen's AutoCollector

I have a nuxt project and would like to use this library in it.

I want to use it for tracking all page views. Keen provides an autocollector function client.initAutoTracking();

How can I use that in my Nuxt/Vue project using this library.

In my Vuex store, I have a user object. So, I would like to extend keen with the user object and then record all page views. Can you please help?

Using with Middleware in Nuxt

hello, I am using Nuxt and I want to track event in router middleware.

However this.$keen is not available in the middleware. What can I do?

Here is an example of the router middleware:

https://nuxtjs.org/examples/middleware/

I want to use it like this:

const user = store.state.auth.user

    console.log('user', user)
    if (user) {
      console.log('keen tracker')
      this.$keen.extendEvents({
        user
      })
      this.$keen.recordEvent("pageviews", {

      })

But this.$keen is not available.

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.