We recently upgraded to the newest version of the Omniture code, AppMeasurement 1.2.3. We're trying to use the s.tl function to record when the user clicks on different links in our site. Unfortunately, I'm having great trouble getting it to work in Chrome.
Our links have a data-track attribute which contains a string to identify what type of link the user's clicking:
<a href="latest-news.php" data-track="Latest News">Latest News</a>
Then we have this click handler:
$('#pageBody')
.off('click.omniture')
.on('click.omniture', '[data-track]', function () {
var track = this.getAttribute('data-track') || 'generic-link';
OmnitureUtil.trackWidgetLink(track, this);
});
Which calls this kind of function which handles the Omniture call:
OmnitureUtil.trackWidgetLink : function(linkName, linkElement) {
s = s_gi(s_account);
s.tl(linkElement, 'e', linkName, null, 'navigate');
return false;
},
'trackWidgetLink' gets called in Chrome, and the navigation happens, but the Charles proxy client shows that no Omniture image request is made. So the click event isn't tracked. This works fine in Firefox. I'm aware of the issue with WebKit browsers, where the browser cancels the image request before the JS can get a chance to send it. But that was supposedly fixed in H25, and AFAIK I'm using the method Omniture recommend to get around this.
A direct call to the method works fine in the console, and it does work as an inline click handler, for example
<a href="latest-news.php" data-track="Latest News" onclick="s.tl(this,'e','xxx',null,'navigate');return false">Latest News</a>
But I'd rather not go round adding inline handlers to all our links. Has anyone else had this kind of issue with the new Omniture code? Can anyone see what I'm doing wrong?
Whoops, I just needed to return false from my click handler instead of trackWidgetLink
, so:
$('#pageBody')
.off('click.omniture')
.on('click.omniture', '[data-track]', function () {
var track = this.getAttribute('data-track') || 'generic-link';
OmnitureUtil.trackWidgetLink(track, this);
return false;
});
This allows the code to work in Chrome.