How to do Bounce Rate ajustment based on time spent and page scrolling?

Bronze Contributor
Bronze Contributor
I want to use the Bounce Rate Ajustement of Sima Ahava for our site but his code is for Universal Analytics and Google Tag Manager: http://www.simoahava.com/analytics/track-adjusted-bounce-rate-universal-analytics/ For "The advanced method: page load AND scroll" which part of the code would I have to change to make it work in Tealium (we also use Universal Analytics)?
7 REPLIES 7

How to do Bounce Rate ajustment based on time spent and page scrolling?

Employee Emeritus
Hi David, without diving in and testing the code but based on a quick review of Simo's post what you'll be doing is 1. creating appropriate data sources in the data layer tab (event_type, event_category, event_action as an example) 2. Adding a Custom JavaScript extension with Simo's code 3. Modify Simo's code by replacing the GTM call dataLayer.push(...) with the Tealium iQ call {code:javascript}utag.link({'event_type' : 'GAEvent', 'event_category' : 'no bounce', 'event_action' : 'scrolled the page' }){code} 4. Map event_type, event_category, and event_action to the corresponding destinations in the GUA tag within Tealium iQ

How to do Bounce Rate ajustment based on time spent and page scrolling?

Bronze Contributor
Bronze Contributor
Thanks Clint, that to make a lot of sense. I'll be trying this.

How to do Bounce Rate ajustment based on time spent and page scrolling?

Tealium Employee
As Clint outlined, you can pretty much copy and paste Simo's code as a Custom Javascript extension, replacing the push call with a utag.view call. The only gotcha is that with Simo's setTimeout call passing a string won't work, as they are evaluated in global scope and will not have access to the locally scoped timeElapsed function. You can solve this by moving the timeElapsed function contents into setTimeout: setTimeout(function(){ visitTookTime = true; sendNoBounce(); }, 30000);

How to do Bounce Rate ajustment based on time spent and page scrolling?

Employee Emeritus
Adding to Clint's response, the JavaScript Code extension would be scoped to DOM Ready so that it waits for the page to load, just as referenced in the article. Also, here is a modified version of the Advanced Code block that uses utag.link to fire the GUA event and updates the setTimeout slightly. I've tested this in a DOM Ready extension and it seems to work as described in the article. Hope this helps! Cheers. {code:javascript} var visitTookTime = false; var didScroll = false; var bounceSent = false; setTimeout(function(){timeElapsed()}, 30000); window.addEventListener ? window.addEventListener('scroll', testScroll, false) : window.attachEvent('onScroll', testScroll); var scrollCount = 0; function testScroll() { ++scrollCount; if (scrollCount == 2) { didScroll = true }; sendNoBounce(); } function timeElapsed() { visitTookTime = true; sendNoBounce(); } function sendNoBounce() { if ((didScroll) && (visitTookTime) && !(bounceSent)) { bounceSent = true; utag.link({ 'event_type': 'GAEvent', 'event_category': 'NoBounce', 'event_action': 'Time spent and page scrolled' }); } } {code}

How to do Bounce Rate ajustment based on time spent and page scrolling?

Gold Contributor
Gold Contributor

Hi @Clint,

 

I am looking at exactly the same code snippet from Simo Ahava and I am wondering if I could replace the dataLayer.push statement (alternatively utag.link) by the following:

 

_gaq.push([‘_trackEvent’, ’no bounce’, ’Time spent and page scrolled’, , , 1])

 

Thanks,

Mohamed

 

 

How to do Bounce Rate ajustment based on time spent and page scrolling?

Silver Contributor
Silver Contributor

hi Jared,

 

I'm just having a similar challenge with one of my clients.

The original request was to apply an adjusted bounce rate modification to the Google Universal Analytics script.

  setTimeout("_gaq.push(['_trackEvent', '30_seconds', 'read'])",30000); 

 

 

 

Would your slightly modified java extension do the trick (and more)?

(I've updated the UDO variables the way they are designated in my client's account)

 

{code:javascript} var visitTookTime = false; var didScroll = false; var bounceSent = false; setTimeout(function(){timeElapsed()}, 30000); window.addEventListener ? window.addEventListener('scroll', testScroll, false) : window.attachEvent('onScroll', testScroll); var scrollCount = 0; function testScroll() { ++scrollCount; if (scrollCount == 2) { didScroll = true }; sendNoBounce(); } function timeElapsed() { visitTookTime = true; sendNoBounce(); } function sendNoBounce() { if ((didScroll) && (visitTookTime) && !(bounceSent)) { bounceSent = true; utag.link({ 'event_type': 'GAEvent', 'ga_eventCategory': 'NoBounce', 'ga_event_action': 'Time spent and page scrolled' }); } } {code}

 

 

I'm keen to hear your thoughts.

 

cheers,


Ben

How to do Bounce Rate ajustment based on time spent and page scrolling?

Moderator
Moderator
Just to close the loop on this thread for future reference, here's a link to the related but separate thread discussing this topic, with a full solution: https://community.tealiumiq.com/t5/Tealium-iQ/Google-Universal-Analytics-Adjusted-Bounce-Rate-Script...
Check out our new Swift integration library for iOS, macOS, tvOS and watchOS: https://github.com/Tealium/tealium-swift with updated
documentation https://community.tealiumiq.com/t5/Swift/tkb-p/swift.
Public