-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.js
More file actions
34 lines (26 loc) · 999 Bytes
/
template.js
File metadata and controls
34 lines (26 loc) · 999 Bytes
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
const copyFromDataLayer = require('copyFromDataLayer');
const setInWindow = require('setInWindow');
const copyFromWindow = require('copyFromWindow');
const getTimestampMillis = require('getTimestampMillis');
const generateRandom = require('generateRandom');
const localStorage = require('localStorage');
return getBrowserId() + '_' + getPageLoadId() + getGtmUniqueEventId();
function getGtmUniqueEventId() {
return copyFromDataLayer('gtm.uniqueEventId') || '0';
}
function getBrowserId() {
let gtmBrowserId = localStorage.getItem('gtmBrowserId');
if (!gtmBrowserId) {
gtmBrowserId = getTimestampMillis() + generateRandom(100000, 999999);
localStorage.setItem('gtmBrowserId', gtmBrowserId);
}
return gtmBrowserId;
}
function getPageLoadId() {
let eventId = copyFromWindow('gtmPageLoadId');
if (!eventId) {
eventId = getTimestampMillis() + generateRandom(100000, 999999);
setInWindow('gtmPageLoadId', eventId, false);
}
return eventId;
}