Time difference tracking between two events?

Gold Contributor
Gold Contributor

Hi Team,

Can you find me any implementation method wherein I can track time difference between any two events.

I tried using the plugin "s.getTimeToComplete " but for some reason it isnt working.

Any suggestion would be much apprecaited.

Thanks.

 

1 REPLY 1

Time difference tracking between two events?

Tealium Employee

Hi @parth_gupta199 

Here is a snippet:

            (function () {   
                var currentTimeStamp;

                var getLastTimeStamp = function () {
                    return window.parseInt(window.localStorage.getItem("teal_last_event_time") || Date.now());
                };

                var setCurrentTimeStamp = function (epoch) {
                    window.localStorage.setItem("teal_last_event_time", epoch);
                };

                var process = function () {
                    var lastTimeStamp = getLastTimeStamp();
                    var timeSinceLastEventTimeStamp = Math.abs(currentTimeStamp - lastTimeStamp);
                    var secondsSinceLastEvent = Math.round(timeSinceLastEventTimeStamp / 1000);
                    setCurrentTimeStamp(currentTimeStamp);                    
                    window.console.log("seconds since last event: " + secondsSinceLastEvent);
                    b["secondsSinceLastEvent"] = secondsSinceLastEvent;
                };

                var init = function () {
                    currentTimeStamp = Date.now();
                    process();    
                };

                init();
            })();

Implementation:

  • Add a JS extension and scope it to "All Tags"

The code will:

  • Run on any event that is tracked by Tealium
  • Provide a variable in the datalayer called "secondsSinceLastEvent" with the seconds since the last event.
  • Information is also printed to the console for reference

Demo:

2019-11-14_10h47_21.gif

 

 

 

 

Public