-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.js
35 lines (26 loc) · 989 Bytes
/
template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const copyFromDataLayer = require('copyFromDataLayer');
const setInWindow = require('setInWindow');
const copyFromWindow = require('copyFromWindow');
const getTimestampMillis = require('getTimestampMillis');
const generateRandom = require('generateRandom');
return getBrowserId() + '_' + getPageLoadId() + getGtmUniqueEventId();
function getGtmUniqueEventId() {
let gtmId = copyFromDataLayer('gtm.uniqueEventId') || 0;
return gtmId >= 0 ? gtmId : '00';
}
function getBrowserId() {
let gtmBrowserId = copyFromWindow('gtmBrowserId');
if (!gtmBrowserId) {
gtmBrowserId = getTimestampMillis() + generateRandom(100000, 999999);
setInWindow('gtmBrowserId', gtmBrowserId, false);
}
return gtmBrowserId;
}
function getPageLoadId() {
let eventId = copyFromWindow('gtmPageLoadId');
if (!eventId) {
eventId = getTimestampMillis() + generateRandom(100000, 999999);
setInWindow('gtmPageLoadId', eventId, false);
}
return eventId;
}