Sha256: cbcd60621d5188cc8176ec04bd6f56a5924cd58175ac769944be0351d0832107

Contents?: true

Size: 1.99 KB

Versions: 17

Compression:

Stored size: 1.99 KB

Contents

(function() {
  "use strict";
  window.GOVUK = window.GOVUK || {};

  // For usage and initialisation see:
  // https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md#create-an-analytics-tracker

  var Analytics = function(config) {
    this.trackers = [];
    if (typeof config.universalId != 'undefined') {
      this.trackers.push(new GOVUK.GoogleAnalyticsUniversalTracker(config.universalId, config.cookieDomain));
    }
  };

  Analytics.prototype.sendToTrackers = function(method, args) {
    for (var i = 0, l = this.trackers.length; i < l; i++) {
      var tracker = this.trackers[i],
          fn = tracker[method];

      if (typeof fn === "function") {
        fn.apply(tracker, args);
      }
    }
  };

  Analytics.load = function() {
    GOVUK.GoogleAnalyticsUniversalTracker.load();
  };

  Analytics.prototype.trackPageview = function(path, title, options) {
    this.sendToTrackers('trackPageview', arguments);
  };

  /*
    https://developers.google.com/analytics/devguides/collection/analyticsjs/events
    options.label – Useful for categorizing events (eg nav buttons)
    options.value – Values must be non-negative. Useful to pass counts
    options.nonInteraction – Prevent event from impacting bounce rate
  */
  Analytics.prototype.trackEvent = function(category, action, options) {
    this.sendToTrackers('trackEvent', arguments);
  };

  Analytics.prototype.trackShare = function(network) {
    this.sendToTrackers('trackSocial', [network, 'share', location.pathname]);
  };

  /*
    The custom dimension index must be configured within the
    Universal Analytics profile
   */
  Analytics.prototype.setDimension = function(index, value) {
    this.sendToTrackers('setDimension', arguments);
  };

  /*
   Add a beacon to track a page in another GA account on another domain.
   */
  Analytics.prototype.addLinkedTrackerDomain = function(trackerId, name, domain) {
    this.sendToTrackers('addLinkedTrackerDomain', arguments);
  };

  GOVUK.Analytics = Analytics;
})();

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
govuk_frontend_toolkit-4.13.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.12.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.11.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.10.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.9.1 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.9.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.8.2 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.8.1 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.8.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.7.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.6.1 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.6.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.5.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.4.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.3.0 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.2.1 app/assets/javascripts/govuk/analytics/analytics.js
govuk_frontend_toolkit-4.2.0 app/assets/javascripts/govuk/analytics/analytics.js