Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A more flexible SiteCatalyst link tracking script wrapper
// Wrapper function for native Omniture SiteCatalyst link tracking (
var trackLink = function (referenceObject, trackingData, targetReportSuite) {
if (typeof referenceObject === 'undefined' || typeof trackingData === 'undefined') {
// If you're missing your settings object or any variables/events to fire, you fail
var linkTrackVarsArray = [],
// Get values out of the configuration object
tEvents =, // String || undefined
tVars = trackingData.variables, // Object || undefined
tEventName = trackingData.eventName, // String || undefined
// Allow specification of a target reporting suite, to allow testing
// of new events in Dev prior to rollout in Production
reportSuite = targetReportSuite || s_account,
s = s_gi(reportSuite);
s.linkTrackEvents = 'None';
s.linkTrackVars = 'None';
if (tEvents && typeof tEvents === 'string') {
s.linkTrackVars = linkTrackVarsArray.join(',');
s.linkTrackEvents = tEvents; = tEvents;
if (tVars && typeof tVars === 'object') {
for (var key in tVars) {
if (tVars.hasOwnProperty(key)) {
// tVars should be in format { eVar1: 'value', prop5: 'value' }
s.linkTrackVars = linkTrackVarsArray.join(',');
s[key] = tVars[key]; // Assign the value
// Fire event, 'o', tEventName);
// Create an event handler that uses this event
$('.container').on('click', 'a.track', function(e) {
trackLink(this, {
events: 'event5,prodView',
variables: {
eVar1: 'Relevant Value',
eVar2: 'Other Relevant Value',
prop7: 'some value'
eventName: 'Human Readable Name for this event'
}, 'yourReportingSuiteID');
Copy link

kadamwhite commented Apr 23, 2012

There are other examples of how to create a wrapper for out on the web (notably Steven Benner's), but I couldn't find any that were flexible enough for our needs.

Copy link

peterh-capella commented May 13, 2013

Thanks for posting this. The one further option I'd include is the ability to use different codes for the type of link, to allow for 'd'-download, and 'e'-exit link tracking if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment