Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Google Analytics classic #597

Merged
merged 5 commits into from
Jun 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ end

gem 'plek', '1.7.0'

gem 'govuk_frontend_toolkit', '3.5.0'
gem 'govuk_frontend_toolkit', '4.0.0'
if ENV['GOVUK_TEMPLATE_DEV']
gem 'govuk_template', :path => "../govuk_template"
else
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ GEM
null_logger
plek
rest-client (~> 1.6.3)
govuk_frontend_toolkit (3.5.0)
govuk_frontend_toolkit (4.0.0)
rails (>= 3.1.0)
sass (>= 3.2.0)
govuk_template (0.13.0)
Expand Down Expand Up @@ -175,7 +175,7 @@ DEPENDENCIES
capybara (= 2.1.0)
exception_notification
gds-api-adapters (= 7.18.0)
govuk_frontend_toolkit (= 3.5.0)
govuk_frontend_toolkit (= 4.0.0)
govuk_template (= 0.13.0)
image_optim (= 0.17.1)
jasmine-rails (~> 0.10.6)
Expand Down
5 changes: 2 additions & 3 deletions app/assets/javascripts/analytics.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//= require govuk/analytics/google-analytics-universal-tracker
//= require govuk/analytics/google-analytics-classic-tracker
//= require govuk/analytics/tracker
//= require govuk/analytics/analytics
//= require govuk/analytics/print-intent
//= require govuk/analytics/error-tracking

//= require analytics/static-tracker
//= require analytics/static-analytics
//= require analytics/init
//= require analytics/scroll-tracker
7 changes: 3 additions & 4 deletions app/assets/javascripts/analytics/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
"use strict";

// Load Google Analytics libraries
GOVUK.StaticTracker.load();
GOVUK.StaticAnalytics.load();

// Use document.domain in dev, preview and staging so that tracking works
// Otherwise explicitly set the domain as www.gov.uk (and not gov.uk).
var cookieDomain = (document.domain == 'www.gov.uk') ? '.www.gov.uk' : document.domain;

// Configure profiles, setup custom vars, track initial pageview
var analytics = new GOVUK.StaticTracker({
universalId: 'UA-26179049-7',
classicId: 'UA-26179049-1',
var analytics = new GOVUK.StaticAnalytics({
universalId: 'UA-26179049-1',
cookieDomain: cookieDomain
});

Expand Down
160 changes: 160 additions & 0 deletions app/assets/javascripts/analytics/static-analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
(function() {
"use strict";
window.GOVUK = window.GOVUK || {};

var StaticAnalytics = function(config) {

// Create universal tracker
// https://github.com/alphagov/govuk_frontend_toolkit/blob/master/docs/analytics.md
// https://github.com/alphagov/govuk_frontend_toolkit/blob/master/javascripts/govuk/analytics/analytics.js
var analytics = new GOVUK.Analytics(config);
this.analytics = analytics;

setPixelDensityDimension();
setHTTPStatusCodeDimension();
this.setDimensionsFromMetaTags();
this.callMethodRequestedByPreviousPage();

// Track initial pageview
analytics.trackPageview();

// Begin error and print tracking
GOVUK.analyticsPlugins.error();
GOVUK.analyticsPlugins.printIntent();

function setPixelDensityDimension() {
if (window.devicePixelRatio) {
analytics.setDimension(11, window.devicePixelRatio);
}
}

function setHTTPStatusCodeDimension() {
analytics.setDimension(15, window.httpStatusCode || 200);
}

};

StaticAnalytics.prototype.callOnNextPage = function(method, params) {
params = params || [];

if (!$.isArray(params)) {
params = [params];
}

if (GOVUK.cookie && typeof this[method] === "function") {
params.unshift(method);
GOVUK.cookie('analytics_next_page_call', JSON.stringify(params));
}
};

StaticAnalytics.prototype.callMethodRequestedByPreviousPage = function() {
if (GOVUK.cookie && GOVUK.cookie('analytics_next_page_call') !== null) {
var params, method;

try {
params = JSON.parse(GOVUK.cookie('analytics_next_page_call'));
method = params.shift();
} catch(e) {}

if (method && typeof this[method] === "function") {
this[method].apply(this, params);
}

// Delete cookie
GOVUK.cookie('analytics_next_page_call', null);
}
};

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

StaticAnalytics.prototype.setDimensionsFromMetaTags = function() {
var $metas = $('meta[name^="govuk:"]'),
dimensions = {};

$metas.each(function() {
var $meta = $(this),
key = $meta.attr('name').split('govuk:')[1],
value = $meta.attr('content');

dimensions[key] = value;
});

this.setSectionDimension(dimensions['section']);
this.setFormatDimension(dimensions['format']);
this.setNeedIDsDimension(dimensions['need-ids']);
this.setResultCountDimension(dimensions['search-result-count']);
this.setPublishingGovernmentDimension(dimensions['publishing-government']);
this.setPoliticalStatusDimension(dimensions['political-status']);
this.setOrganisationsDimension(dimensions['analytics:organisations']);
this.setWorldLocationsDimension(dimensions['analytics:world-locations']);
this.setRenderingApplicationDimension(dimensions['rendering-application']);
};

StaticAnalytics.prototype.trackPageview = function(path, title) {
this.analytics.trackPageview(path, title);
};

StaticAnalytics.prototype.trackEvent = function(category, action, options) {
this.analytics.trackEvent(category, action, options);
};

StaticAnalytics.prototype.setDimension = function(index, value, name, scope) {
if (typeof value === "undefined") {
return;
}

this.analytics.setDimension(index, value, name, scope);
};

StaticAnalytics.prototype.trackShare = function(network) {
this.analytics.trackShare(network);
};

StaticAnalytics.prototype.addLinkedTrackerDomain = function(trackerId, name, domain) {
this.analytics.addLinkedTrackerDomain(trackerId, name, domain);
};

StaticAnalytics.prototype.setSectionDimension = function(section) {
this.setDimension(1, section);
};

StaticAnalytics.prototype.setFormatDimension = function(format) {
this.setDimension(2, format);
};

StaticAnalytics.prototype.setNeedIDsDimension = function(ids) {
this.setDimension(3, ids);
};

StaticAnalytics.prototype.setResultCountDimension = function(count) {
this.setDimension(5, count);
};

StaticAnalytics.prototype.setPublishingGovernmentDimension = function(government) {
this.setDimension(6, government);
};

StaticAnalytics.prototype.setPoliticalStatusDimension = function(status) {
this.setDimension(7, status);
};

StaticAnalytics.prototype.setOrganisationsDimension = function(orgs) {
this.setDimension(9, orgs);
};

StaticAnalytics.prototype.setWorldLocationsDimension = function(locations) {
this.setDimension(10, locations);
};

StaticAnalytics.prototype.setRenderingApplicationDimension = function(app) {
this.setDimension(20, app);
};

StaticAnalytics.prototype.setSearchPositionDimension = function(position) {
this.setDimension(21, position);
};

GOVUK.StaticAnalytics = StaticAnalytics;
})();
160 changes: 0 additions & 160 deletions app/assets/javascripts/analytics/static-tracker.js

This file was deleted.

Loading