Instantly share code, notes, and snippets.

What would you like to do?
<body dir="ltr">
Blah blah blah
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
ga('create', 'UA-46076570-1', 'auto');
ga('require', 'dAKTestPlugin');
ga('send', 'pageview');
//this script could and should be loaded async
// Assign the ga variable to the Google Analytics global function
var ga = window[window['GoogleAnalyticsObject'] || 'ga'];
// Helper function for registering the Plugin
var providePlugin = function(pluginName, pluginConstructor) {
if(ga) {
ga('provide', pluginName, pluginConstructor);
// Constructor for dAKTestPlugin
// Copies payload to custom host
var dAKTestPlugin = function(tracker) {
this.tracker = tracker;
// Copy the original hit dispatch function
var originalSendHitTask = this.tracker.get('sendHitTask');
// Modify the existing hit dispatcher to send a local copy of the hit
this.tracker.set('sendHitTask', function(model) {
var hitPayload = model.get('hitPayload');//.replace('2560x1440', '800x600');
// Updates the hitPayload string for the current hit.
hitPayload += '&cd1=myUniqueVal' //this is our marker: we add constant value for Custom Dimension with index 1
model.set('hitPayload', hitPayload, true);
originalSendHitTask(model); // Send the original hit as usual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment