-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
54 lines (46 loc) · 1.66 KB
/
app.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(function () {
var STORAGE_KEY = "d5_gclid";
var PARAM_NAME = "gclid";
var CHECK_REFERRER = true;
// Checks if the local Storage Feature is there.
function hasSessionStorage() {
var test = 'test';
try {
window.sessionStorage.setItem(test, test);
window.sessionStorage.removeItem(test);
return true;
} catch (e) {
return false;
}
}
// Fail fast if local storage is not there
if (hasSessionStorage === false) {
return null;
}
// Get the current urls query parameters
var pStr = window.location.search;
// Try to extract the parameters from the referrer when
// the current url has none and this feature is enabled.
if (pStr === '' && document['referrer'] && CHECK_REFERRER) {
// TODO check here if the refererrer is the same hostname as the current location - do nothing otherwise
if(location.hostname === document.referrer.split('/')[2].split(':')[0].split('?')[0].split('#')[0]) {
var rStr = document['referrer'].split('?')[1];
pStr = (rStr !== undefined) ? '?' + rstr.split('#')[0] : '';
}
}
// Parse the parameter string and add the key/values to an object.
var params = {};
if (pStr !== '') {
pStr.substring(1).split('&').map(function (value) {
var kv = value.split('=');
params[kv[0]] = kv[1];
});
}
// Get the value from the session storage if it's set or
var storageValue = window.sessionStorage.getItem(STORAGE_KEY);
if (params[PARAM_NAME]) {
window.sessionStorage.setItem(STORAGE_KEY, params[PARAM_NAME]);
storageValue = params[PARAM_NAME];
}
return storageValue || "";
})();