Last active
August 29, 2015 14:27
-
-
Save ortense/9e5d2c150885d62110b0 to your computer and use it in GitHub Desktop.
Manage Cross-Domain Tracking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @fileoverview Manage Cross-Domain Tracking | |
* @author Marcus Ortense | |
* @see http://lucida-brasil.github.io/clientes/bluehive/ford-crossdomain.html | |
*/ | |
/** | |
* url_decorate | |
* @global | |
* @param {string} url | |
* @return {string} url with linker param | |
*/ | |
window.url_decorate = (function(d, w, $) { | |
'use strict'; | |
/** | |
* Crate Linker Object | |
* Need ga('require', 'linker'); | |
*/ | |
ga(function(tracker) { | |
w.linker = w.linker || new w.gaplugins.Linker(tracker); | |
}); | |
//Add Events | |
$(d).on('mousedown', '[data-linker="true"]', function(){ | |
this.href = decorate(this.href); | |
}); | |
/** | |
* decorate | |
* @private | |
* @param {string} url | |
* @return {string} url with linker param | |
*/ | |
var decorate = function (url) { | |
if ('string' === typeof url && linker && linker.decorate) { | |
return linker.decorate(url, false); | |
} | |
return url; | |
}; | |
//public api | |
return function ga_decorate_url (url) { | |
return decorate(url); | |
}; | |
}(document, window, window.jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment