Do tealium has any plugin or tag to capture visitor time spend on specific set of pages aggregated.

Gold Contributor
Gold Contributor

looking for a solution for launching and external page or survey after user is 180 sec on the pages . Not looking for the counter on page but should be session level also don't impact the user exp for checking the time every sec .

2 REPLIES 2

Do tealium has any plugin or tag to capture visitor time spend on specific set of pages aggregated.

Tealium Employee

Hello @santosh_sharma. Tealium does not provide any specific tools for this use case, but combining a bit of JavaScript and Tealium session cookies it is quite possible to achieve your desired results with minimal effort.

 

There are a set of first-party cookies set by Tealium, including a session start boolean and the session start time. More information regarding the Tealium cookies can be found here: https://community.tealiumiq.com/t5/User-Documentation/Tealium-Cookies/ta-p/138

 

Outline

 

The basic outline of what we'll do for this use case:

  1. Set a cookie at session start indicating that our tag based on the timing interval has not fired.
  2. If the timing tag fired cookie is false, set an interval to run a function every X seconds (the code below is set to 3 seconds)
  3. In this interval function, check if the current time is more than 180 seconds than the session start time
  4. If it is greater than 180 seconds, stop the interval, set the timing tag fired cookie to true, and fire the timed tag.

 

Steps

 

Enable the use of the Tealium session start cookie variable (utag_main__ss) within the UI by creating a new data source for it.

 

Tealium Management Console 2015-11-03 10-21-45.png

 

Create a new data source for your timing tag fired cookie (I named it timing_tag_fired in my example).

 

Tealium Management Console 2015-11-03 10-22-47.png

 

Using a Persist Data Values extension, set the timing tag fired cookie to 0 when session start is true.

 

Tealium Management Console 2015-11-03 10-23-48.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Finally, set up a JavaScript extension for the setInterval function with the following code.

 

//only begin setInterval if timing tag has not been fired. interval is set to 3 seconds (3000 milliseconds)
if (b['cp.timing_tag_fired'] == "0") {
  var interval = setInterval(function(){
    //check if current time > 180 seconds from session start time
    if (((new Date).getTime() - b['cp.utag_main_ses_id']) / 1000 > 180) {
      //clear interval
      clearInterval(interval);
//set the timing tag cookie using the utag set cookie function utag.loader.SC("timing_tag_fired","1");
// fire the tag utag.view({event_name: 'timing_event'},null,[5]}); } },3000); }

 utag.view takes three parameters - data, callback, array of tag UIDs

more info is here: https://community.tealiumiq.com/t5/Developers/utag-link-and-utag-view/m-p/75

 

In this example, we are specifically firing the tag with UID of 5. You can find the UID for the tag you want to fire on the right hand side of the tag list in TiQ

 

Tealium Management Console 2015-11-03 10-32-04.png

 

 

Finally, I assume you only want this tag to fire for this particular utag.view call. To prevent the tag from firing on other page views, set up a load rule for this tag to fire only when a particular data layer element is set to a particular value and pass this value in your utag.view call. In the example here, you would attach a load rule to the tag to fire when event_name = "timing_event".

 

Do tealium has any plugin or tag to capture visitor time spend on specific set of pages aggregated.

Silver Contributor
Silver Contributor
There is a syntax error on the above code, the correct extension code is below ( ]} !! )

A working example can be seen on berlowrahman.scot

//only begin setInterval if timing tag has not been fired. interval is set to 3 seconds (3000 milliseconds)
if (b['cp.timing_tag_fired'] == "0") {
var interval = setInterval(function(){
//check if current time > 180 seconds from session start time
if (((new Date).getTime() - b['cp.utag_main_ses_id']) / 1000 > 180) {
//clear interval
clearInterval(interval);
//set the timing tag cookie using the utag set cookie function
utag.loader.SC("timing_tag_fired","1");
// fire the tag
utag.view({event_name: 'timing_event'},null,[5]);
}
},3000);
}
Barry Mann
Public