analytics ninja
analytics ninja

Reputation: 83

DTM Fire Rule at session start and only once per session?

Our client wants to track the Session Start time (down to the second). The site has DTM implemented. In DTM I am using JS Date() as Timestamp and storing it in a cookie so it has a fixed value and is not updated with the time. Is there a way to send it to analytics at the start of a session. In other words, what should be the condition to fire this rule (using Page Load Rule in this case). I'm open to using other ways to track it if those are efficient than what the route I'm thinking to take.

Upvotes: 1

Views: 497

Answers (1)

BrettAHale
BrettAHale

Reputation: 800

Create a data element to read the cookie and then in your analytics settings under global variables, you can have the prop or evar always send it with the request.

eVar1="%data element name%"

If you need it to send once, you can use another cookie as the same value. Then with some custom code, you can read both cookies and only send it if the second data element value is not the same as the first.

var sessionStart = _satellite.getVar('data element name'); //timestamp
var sentTimestamp = _satellite.readCookie('didIsendTheTimestamp');
if (sentTimestamp !== sessionStart) {
    /** send tiemstamp in variable **/
    s.evar1 = sessionStart;
    _satellite.setCookie('didIsendTheTimestamp', sessionStart);
}

Upvotes: 2

Related Questions