1.0.0 • Published 7 years ago

trackthis.js v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

trackThis.js

Simple tracking plugins for Google Analytics inspired by (googleanalytics/autotrack)<https://github.com/googleanalytics/autotrack>

trackThis.js assumes you're using universal analytics and have included it in your project as per Google's instructions

Plugins

PluginDescriptionDefault
trackThisIntraPageLinkAutomatically track links which change the current page hash
trackThisLinkProtocolTrack links matching the given protocolmailto, tel
trackThisFileDownloadTrack file download linkspdf, zip, 7zip, doc, docx
trackThisOpenExternalInTabHelper function to open all links pointing to a different domain in a new tab

Installation

You can simply include the dist/trackThis.js file in your page, after your Google Analytics code if you like.

Webpack, Browserify, etc...

Install from npm (using the [githubUsername]/[project] format)

npm install --save-dev DashMedia/trackThis.js
import 'trackthis.js';

ga('require', 'trackThisIntraPageLink');
ga('require', 'trackThisLinkProtocol');
ga('require', 'trackThisFileDownload');
ga('require', 'trackThisOpenExternalInTab');

Or, just include the plugins you're interested in

import 'trackthis.js/src/plugins/TrackThisFileDownload';

ga('require', 'trackThisFileDownload');

Setting Up

  • Add universal analytics to your project
  • Include trackThis.js
  • Enable trackThis plugins via ga('require', [pluginName])
  • Enjoy extra data directly to your analytics account

Additional options

All examples provided below are the default values

trackThisFileDownload

We can define which file extensions to track

import 'trackthis.js';

const options = {
  extensions: ['pdf', 'zip', '7zip', 'doc', 'docx']
};

ga('require', 'trackThisFileDownload', options);

TrackThisLinkProtocol

Each protocol requires a category which is passed to Google Analytics as the eventCategory

import 'trackthis.js';

const options = {
  protocols: {
    'mailto:': {
      category: 'Mail send'
    },
    'tel:': {
      category: 'Phone number'
    }
  }
};

ga('require', 'trackThisLinkProtocol', options);