ortense
8/14/2015 - 7:51 PM

Manage Cross-Domain Tracking

Manage Cross-Domain Tracking

/**
 * @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));