- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
12-29-2014 04:36 AM - last edited on 10-05-2015 10:47 AM by kathleen_jo
How to trigger a GUA events on page load.
Use Case: Let say I have a page and if that page has an id="test" then I need to fire GAU event on completion load of that page. If the page does not has id test, then no need to fire the event.
Can we do it in a JavaScript Code extension? If we can do it, can you share the code here.re.
Solved! Go to Solution.
12-29-2014 07:20 AM - last edited on 10-05-2015 10:48 AM by kathleen_jo
Bikash,
Because you would want this extension to run as late as possible we would want to use an Extension scoped to DOM Ready. This will give the "test" element the most time to load. However, we will need to use raw JS code to accomplish this.
You can do this using jQuery:
if(jQuery('#module').length>0){
utag.data.event_category = "testCat";
utag.data.event_action = "pageLoad";
}
Or you can use standard JS Code:
if(document.getElementById('module')!="test"){
utag.data.event_category = "testCat";
utag.data.event_action = "pageLoad";
}
Paste this into a JS Code extension. Scope the extension to DOM Ready. Within your GUA tag, you will then need to map "event_category" and "event_action" to their respective values. You can also add additional data sources like "event_label" and "event_value" if needed.
Hope this helps.
12-29-2014 08:13 AM - last edited on 10-05-2015 10:48 AM by kathleen_jo
Bikash,
You will also want to consider the impact this may have on bounce rate in Google Analytics. By default, an event will be counted as an "interaction" which means it will impact the bounce rate calculation for visitors whose landing page contains id="test" but did not continue to trigger another pageview or different event. For visitors who already continue to see a second page or trigger a different event, they should be okay.
You can override this behavior by flagging the desired event as a non-interaction (seehttps://developers.google.com/analytics/devguides/collection/analyticsjs/events) which would tell Google Analytics to not include this particular event in the bounce rate calculation but to preserve all other traditional event characteristics. You can accomplish this by passing an additional flag, such as
utag.data.event_noninteraction = "1";
and mapping it to Event Non-Interaction within Tealium iQ.
Copyright All Rights Reserved © 2008-2023