-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkeepalive.html
More file actions
91 lines (83 loc) · 3.25 KB
/
Copy pathkeepalive.html
File metadata and controls
91 lines (83 loc) · 3.25 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Segment Keepalive Test (v5.2.0)</title>
</head>
<body>
<h1>Segment Keepalive Test</h1>
<p>This simulates a flow where a Segment event is fired before redirecting the user.</p>
<button id="redirectBtn">Fire Event & Redirect</button>
<script>
!function(){
var i="analytics",analytics=window[i]=window[i]||[];
if(!analytics.initialize) {
if(analytics.invoked) {
window.console && console.error && console.error("Segment snippet included twice.");
} else {
analytics.invoked = true;
analytics.methods = ["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","screen","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware","register"];
analytics.factory = function(e){
return function(){
if(window[i].initialized) return window[i][e].apply(window[i], arguments);
var n = Array.prototype.slice.call(arguments);
if(["track","screen","alias","group","page","identify"].indexOf(e) > -1){
var c = document.querySelector("link[rel='canonical']");
n.push({
__t:"bpc",
c: c && c.getAttribute("href") || void 0,
p: location.pathname,
u: location.href,
s: location.search,
t: document.title,
r: document.referrer
});
}
n.unshift(e);
analytics.push(n);
return analytics;
};
};
for(var n=0; n<analytics.methods.length; n++){
var key=analytics.methods[n];
analytics[key]=analytics.factory(key);
}
analytics.load = function(key, options){
var t = document.createElement("script");
t.type = "text/javascript";
t.async = true;
t.setAttribute("data-global-segment-analytics-key", i);
t.src = "https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js";
var r = document.getElementsByTagName("script")[0];
r.parentNode.insertBefore(t, r);
analytics._loadOptions = options;
};
analytics._writeKey = "dlWOgBCqvyMNui1UGuk78vkZT7zfGLE2";
analytics.SNIPPET_VERSION = "5.2.0";
analytics.load("dlWOgBCqvyMNui1UGuk78vkZT7zfGLE2", {
integrations: {
"Segment.io": {
deliveryStrategy: {
config: {
keepalive: true
}
}
}
}
});
analytics.page();
}
}
}();
</script>
<script>
document.getElementById("redirectBtn").addEventListener("click", function () {
analytics.track("Signup Completed", { plan: "Pro" });
// Simulate redirect immediately after firing the event
setTimeout(function () {
window.location.href = "https://prigiattiperrut.github.io/ajsnext.html";
}, 50); // 50ms delay to allow event to fire
});
</script>
</body>
</html>