项目作者: wearejust

项目描述 :
Goole Analytics automator
高级语言: JavaScript
项目地址: git://github.com/wearejust/gtrack.git
创建时间: 2017-08-24T13:39:56Z
项目社区:https://github.com/wearejust/gtrack

开源协议:MIT License

下载


GTrack

Automatically track outbound links, mailto:, tel: and hashtags. Track custom events with the [data-gtrack] attribute. Includes default Google Analytics pageviews.

Installation

  1. npm install @wearejust/gtrack --save

Usage

  1. var GTrack = require('@wearejust/gtrack');
  2. $(function() {
  3. GTrack.init('UA-XXXXXXXX-X');
  4. });

With options

  1. var GTrack = require('@wearejust/gtrack');
  2. $(function() {
  3. GTrack.init({
  4. id: 'UA-XXXXXXXX-X', // Google Analytics id
  5. exclude: '', // Selector to exclude items
  6. parseOnInit: true, // Parse the body on init
  7. removeUtm: true, // Remove UTM codes from URL
  8. timeout: 1000 // Timeout in miliseconds (use 0 to disable)
  9. });
  10. });

Methods

  1. // Parse anchors in the body or a container (used for AJAX calls for example)
  2. GTrack.parse();
  3. GTrack.parse(container);
  4. // Track the current or custom location, with optional callback
  5. GTrack.pageview();
  6. GTrack.pageview(custom_url, callback);
  7. // Track event with category and action, and optional label, value and callback
  8. GTrack.event(category, action, label, value, callback);

HTML

  1. Automatic inbound and outbound tracking (no extra class required)
  2. <a href="/contact">Contact</a>
  3. <a href="https://wearejust.com/">Just</a>
  4. Track 'Test' as 'Anchor' event
  5. <a href="#test">Test</a>
  6. Track 'emre.koc@wearejust.com' as 'Mail' event
  7. <a href="mailto:emre.koc@wearejust.com">Mail</a>
  8. Track custom event, with optional category, action, label and value
  9. <button data-gtrack="Category,Action,Label,value">Custom</button>
  10. Track only once (until parsed again)
  11. <a href="#once" data-gtrack-once>Once</a>
  12. Disable tracking
  13. <a href="https://wearejust.com/" class="no-gtrack">Just</a>