Highlighted

Reducing the Time on Page to trigger an event to the Google Analytics

shailesh_gaikwa
Visitor
shailesh_gaikwa

We need to consder bounce rate for those users whose time on page is less than 30 seconds.

 

We want to trigger an event when user spends at least 30 seconds on the site. We want to send this to only Google Analytics and also for a particular website. As this configuration will be done in the profile which hosts more than 30 websites so we dont want this to be applied for other sites.

 

Any suggestion?

 

 

4 REPLIES 4

Reducing the Time on Page to trigger an event to the Google Analytics

Yoosuf
Visitor
Yoosuf

Prior to answering your question, I wish to clarify that the approach which you are intending to take to trigger an event on bounced users isn't a good option; as you could filter down on such sessions in your analysis later but you cannot get back the lost data.

 

Regarding the use of a single profile on multiple websites I strongly discourage this as well since it would complicate tagging across your marketing needs. The benefit would be that you only to update a given change once, but managing them for 30 distnct sites would complicate tasks a lot.

 

Nevertheless, if you wish to proceed with the above, you could do so by using a JavaScript extension and writing a bit of code to trigger when the user is closing the tab or browser. Thereafter you could use location.hostname to check for the particular website which you want to trigger the event on. You may need to manually code the event such as,

ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);

As if you could the utag view or link calls it would cause other issues if you have other events in place on the same page.

 

 

 

 

 

Reducing the Time on Page to trigger an event to the Google Analytics

Tealium Employee

@shailesh_gaikwa

 

Just to add to @Yoosuf comment.

 

If you want to track a user after x amount of time you can use:

 

window.setTimeout(function(){
    utag.view({<....data...>}, null, []);
},30000);

 

This can be done in a JS extension, where you can now also set conditions for this to run.

 

https://community.tealiumiq.com/t5/iQ-Tag-Management/JavaScript-Code-Extension/ta-p/11925#toc-hId--4...

 

Adrian

Ask me anything Tealium related or Javascript, or NodeJS. But not cooking, can't do that.
Please remember to mark solutions as accepted for future searchers.

Reducing the Time on Page to trigger an event to the Google Analytics

per_lundqvist
Frequent Visitor
per_lundqvist Frequent Visitor

Hello @shailesh_gaikwa. Another way is to just calculate the session time spent for every new page request:

var sessionTime = b._t_session_id;
var currentTime = new Date().getTime();
var elapsedTime = new Date(currentTime - sessionTime).getTime();
b._bContext_session_time = Math.floor(elapsedTime / 1000);

Put the result in a utag variable and use it in your load rule.

Reducing the Time on Page to trigger an event to the Google Analytics

shailesh_gaikwa
Visitor
shailesh_gaikwa

Hi @per_lundqvist,

'i tried using the following syntax but nothing is not happening, neither any event is being triggedred - 

 

var sessionTime = b._t_session_id;
var currentTime = new Date().getTime();
var elapsedTime = new Date(currentTime - sessionTime).getTime();
b.TimeOnPage = Math.floor(elapsedTime / 1000);

 

I am using "TimeOnPage" to store the time spent by user. since it is divinding by 1000 so it should convert the value for seconds.

I have put a condition that if TimeOnePage = 30 then it should fire an event but it isn;t firing any event.

 

Any further guidance over this?