Skip to content

Instantly share code, notes, and snippets.

@kadamwhite
Created April 23, 2012 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kadamwhite/2470993 to your computer and use it in GitHub Desktop.
Save kadamwhite/2470993 to your computer and use it in GitHub Desktop.
A more flexible SiteCatalyst link tracking script wrapper
// Wrapper function for native Omniture SiteCatalyst link tracking (s.tl())
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
return;
}
var linkTrackVarsArray = [],
// Get values out of the configuration object
tEvents = trackingData.events, // 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') {
linkTrackVarsArray.push('events');
s.linkTrackVars = linkTrackVarsArray.join(',');
s.linkTrackEvents = tEvents;
s.events = tEvents;
}
if (tVars && typeof tVars === 'object') {
for (var key in tVars) {
if (tVars.hasOwnProperty(key)) {
// tVars should be in format { eVar1: 'value', prop5: 'value' }
linkTrackVarsArray.push(key);
s.linkTrackVars = linkTrackVarsArray.join(',');
s[key] = tVars[key]; // Assign the value
}
}
}
// Fire event
s.tl(referenceObject, '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');
});
@kadamwhite
Copy link
Author

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

@peterh-capella
Copy link

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