Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Apr 23, 2012

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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.