Return to Snippet

Revision: 45249
at April 27, 2011 23:42 by freezy


Updated Code
var arrTracker = ['trackerName1', 'trackerName2']; // tracker names
// tracking form submit
function trackFormSubmit(form, category, action, opt_label, opt_value) {
    for (var i = 0, ii = arrTracker.length; i < ii; i++) {
        _gat._getTrackerByName(arrTracker[i])._trackEvent(category, action, opt_label, opt_value);
    }
    setTimeout("document.getElementById('"+form.id+"').submit();", 100);
    return false;
}

// tracking link click
function recordOutboundLink(link, category, action, opt_label, opt_value) {
    for (var i = 0, ii = arrTracker.length; i < ii; i++) {
        _gat._getTrackerByName(arrTracker[i])._trackEvent(category, action, opt_label, opt_value);
    }
    setTimeout('document.location = "' + link.href + '"', 100);
    return false;
}

<a href="" onclick="recordOutboundLink(link, category, action, opt_label, opt_value);return false;">
<form id="uniqueID" onsubmit="trackFormSubmit(form, category, action, opt_label, opt_value);return false;">

Revision: 45248
at April 27, 2011 23:30 by freezy


Initial Code
var arrTracker = ['trackerName1', 'trackerName2']; // tracker names
// tracking form submit
function trackFormSubmit(form, category, action, opt_label, opt_value) {
    for (var i = 0, ii = arrTracker.length; i < ii; i++) {
        _gat._getTrackerByName(arrTracker[i])._trackEvent(category, action, opt_label, opt_value);
    }
    setTimeout("document.getElementById('"+form.id+"').submit();", 100);
    return false;
}

// tracking link click
function recordOutboundLink(link, category, action, opt_label, opt_value) {
    for (var i = 0, ii = arrTracker.length; i < ii; i++) {
        _gat._getTrackerByName(arrTracker[i])._trackEvent(category, action, opt_label, opt_value);
    }
    setTimeout('document.location = "' + link.href + '"', 100);
    return false;
}

Initial URL


Initial Description
<p>usage: <br>
<code>&lt;a href="" onclick="recordOutboundLink(link, category, action, opt_label, opt_value);return false;"&gt; <br>
&lt;form id="uniqueID" onsubmit="trackFormSubmit(form, category, action, opt_label, opt_value);return false;"&gt;</code></p>

Initial Title
Google Analytics tracking link click and form submit to multiple trackers

Initial Tags
form, link, google

Initial Language
JavaScript