@guivic/vue-segment

0.0.2 • Public • Published

Vue Segment Build Status Maintainability Test Coverage

A vue 2.0 plugin for the Segment Analytics.

// In your main.js
import VueSegment from 'vue-segment';

Vue.use(VueSegment);

// In your components
this.$segment.track({
	event: 'visit my page',
	awesome: true,
});

Installation

This is a Node.js module available through the npm registry.

Installation is done using the

$ yarn add @guivic/vue-segment
$ npm install @guivic/vue-segment

Features

  • Auto generate an anonymousId if userId is not provided and add it to the localStorage
  • Add the userId to localStorage once provided with the identify method
  • Focus on high performance
  • Super-high test coverage
  • Super easy to use

Security Issues

If you discover a bug in Vue Segment, please open an issue.

Quick Start

Install the plugin:

$ yarn add @guivic/vue-segment

Install the plugin into Vue:

import VueSegment from 'vue-segment';

Vue.use(VueSegment); // Use process.env.SEGMENT_WRITE_KEY by default for the Segment write key

But you can provide it if you want:

import VueSegment from 'vue-segment';

Vue.use(VueSegment, { writeKey: '12346789AZERTYUIOPQSDFGHJKLM' });

You can also provide the path where the anonymousId and userId can be stored/retrieved:

import VueSegment from 'vue-segment';

Vue.use(VueSegment, { anonymousIdStoragePath: 'analytics-segment-id', userIdStoragePath: 'analytics-user-id' });

Add this into any methods, like when someone click on a button, of your components:

this.$segment.track({
	event: 'visit my page',
	awesome: true,
});

If your user logging in, you can identify him:

this.$segment.identify({
	event: 'Authentification',
	method: 'Facebook',
	userId: 'XYUIHH789OIUHKOIUHBF4567' // Likely the ID in your database
});

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

People

The author of Vue Segment is Guillaume Galas

License

MIT

TO DO

  • Vuex integration for retrieving userId on logging
  • userId location can retrieve a object, so it must be possible to access one attributes from it

Readme

Keywords

none

Package Sidebar

Install

npm i @guivic/vue-segment

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

7.78 kB

Total Files

5

Last publish

Collaborators

  • guillaume-g
  • lludol