- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
01-21-2015 03:15 AM - last edited on 10-07-2015 07:37 PM by kathleen_jo
Hi guys,
I am using a utag.view on a Javascript extension to track page views based on clicks on a page that does not reload (so it's dynamic) , and it works fine the first time you click an element.
On the other hand, if you do more clicks, you get 2, 4, 8... page views for each click. I assume the thing here is that the utag.link, as it loads all extensions, is adding more listeners to the same elements that cause these multiple page views. Here is an example of my approach:
jQuery(document).on("mousedown","#texample", function(){
utag.view({
Page_Name: 'example',
});
});
Is there any way of avoiding this to happen?
Thanks a lot in advance.
Best regards,
Martin McNulty
Solved! Go to Solution.
01-21-2015 03:25 AM
utag.runonce = utag.runonce || {}; if (!utag.runonce["ext_mousedown"]) { utag.runonce["ext_mousedown"] = 1; jQuery(document).on("mousedown","#texample", function(){ utag.view({Page_Name: 'example'}); }); }Adrian
01-21-2015 03:38 AM
01-21-2015 07:31 AM - last edited on 10-07-2015 07:39 PM by kathleen_jo
Martin,
The other option is to simply scope the extension to DOM Ready, instead of All Tags. The DOM Ready scope already has the "if statement" logic built into it so it won't repeatedly add the event listeners.
Copyright All Rights Reserved © 2008-2023