1

We use this Google Tag Manager (GTM) code on our website:

<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','XXX-XXXXXX');
</script>

How can I integrate this code

setTimeout("gtag('event', 'adjusted bounce rate', {'event_label':'more than 15 sec'})",15000 );"

into it?

or can I integrate it with the GTM backend, maybe as user defined HTML?

1

You can do this entirely within GTM, by using a Timer trigger to fire an Event tag.

(You could also use a setTimeout in your JavaScript or inserted via a custom HTML tag to push a custom event into the dataLayer after 15 seconds, and have a trigger that watches for that event, but it does not have any advantages over this method that I can see. In particular, it looks like if someone opens your page and then moves to a different tab in their browser, the 15 seconds will continue to count down whether it's a setTimeout or a GTM Timer. I think that's worth noting - visitors for whom this event makes the difference between a bounce and a non-bounce are not necessarily spending the whole 15 seconds on your page; they just haven't closed it.)

Piece 1: Set Up GTM Trigger

In GTM, create a new trigger of type Timer; event name can be what you like. Set the interval to 15000 and the limit to 1, and to have it operate on all pages set the enablement condition to "Page URL contains /".

screenshot of GTM trigger setup

Give the trigger itself a name as well and save.

Piece 2: Set Up GTM Tag

The trigger won't affect GA until you attach a tag to it.

The tag type is Google Analytics, with track type of event. Fill in whatever you'd like for Category, Action, and Label.

The important part here is that Non-Interaction Hit is set to False - fortunately False is the default. If you set it to True the event will have no effect on bounce rate (that is basically the definition of Non-Interaction Hit).

screenshot of GTM tag setup

Select your new trigger in the "triggering" section, below the tag configuration, give the tag a name and save it.

Once your GTM tag and trigger are created, you can preview in GTM and verify that the tag is firing fifteen seconds after page load. The data from preview will show up in your GA as well, so you can see it in the Real Time report (as long as you're not in a View where you're filtering yourself out!).

  • 100% agree with this approach. Good explanation! – Julia-Alessa Mäntz Nov 13 '18 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.