-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathevents.html
More file actions
326 lines (300 loc) · 8.57 KB
/
events.html
File metadata and controls
326 lines (300 loc) · 8.57 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Simple Analytics Playground</title>
<meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Simple Analytics events queue -->
<script>
window.sa_event =
window.sa_event ||
function () {
var a = [].slice.call(arguments);
window.sa_event.q
? window.sa_event.q.push(a)
: (window.sa_event.q = [a]);
};
sa_event(
"before_script_load",
{
date: new Date(),
modified_at: new Date().toISOString().slice(0, 16) + "Z",
deletedAt: new Date().toISOString().slice(0, 16).replace("T", " "),
false: false,
true: true,
null: null,
undefined: undefined,
zero: 0,
one: 1,
minus_one: -1,
},
() => {
console.info(
"Simple Analytics auto events: collected before_script_load",
);
},
);
</script>
<style>
/* Basics */
body,
html {
margin: 0;
padding: 0;
height: 100%;
}
body {
background: #eef9ff;
word-break: break-word;
display: flex;
justify-content: center;
color: #415659;
font-family: "Space Grotesk", Arial, sans-serif;
font-weight: 400;
}
main {
margin: auto;
}
* {
box-sizing: border-box;
}
/* Fonts */
@font-face {
font-family: "Space Grotesk";
font-weight: 500;
src:
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Medium.woff2")
format("woff2"),
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Medium.woff")
format("woff");
}
@font-face {
font-family: "Space Grotesk";
font-weight: 400;
src:
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Regular.woff2")
format("woff2"),
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Regular.woff")
format("woff");
}
h1,
h2,
h3,
h4 {
margin: 0 0 1rem 0;
line-height: 1.5;
font-weight: 500;
}
p {
font-size: 1rem;
line-height: 150%;
}
a {
color: #415659;
}
a:hover {
text-decoration: none;
}
/* Layouts */
main {
padding: 2rem;
flex: 0 1 auto;
text-align: center;
}
textarea,
input {
border: 1px solid #232e2f;
border-radius: 5px;
}
@media (prefers-color-scheme: dark) {
body {
background: #2a3638;
}
textarea,
input {
background: #232e2f;
}
body,
a,
textarea,
input {
color: #a4bdc0;
}
}
textarea {
width: 1000px;
max-width: calc(100vw - 2rem);
height: 200px;
padding: 0.5rem;
margin: 1rem;
}
</style>
</head>
<body>
<main>
<svg
width="70"
height="70"
viewBox="0 0 400 400"
fill="none"
xmlns="http://www.w3.org/2000/svg"
style="margin-bottom: 1rem"
>
<circle cx="200" cy="200" r="200" fill="#FF4F64" />
<path d="M132.414 201.448H100V298.69H132.414V201.448Z" fill="white" />
<path
d="M210.206 143.103H177.793V298.69H210.206V143.103Z"
fill="white"
/>
<path d="M288 88H255.586V298.69H288V88Z" fill="white" />
</svg>
<h2>Automated events</h2>
<p>A test site to test automated events for Simple Analytics.</p>
<p>
<a href="https://example.com" target="_blank" rel="nofollow noopener"
>Outbound link</a
><br />
<a href="mailto:user@example.com">Email link</a><br />
<a href="/file.pdf">Download PDF link</a><br />
<a
href="https://example.com"
data-sa-link-event="navigated_to_example_com"
>data-sa-link-event</a
>
</p>
<textarea readonly>Loading JavaScript...</textarea>
<p>
In the above console you should see "Auto events" and "Normal embed"
script is loaded.<br />
Further you should see events show up when you click the links.
</p>
</main>
<!-- Some test code for this page specifically -->
<script>
document.querySelector("textarea").value = "";
var logger = {
log: console.log,
error: console.error,
warn: console.warn,
info: console.info,
};
function log(type = "info", ...text) {
logger[type](...text);
write(type, ...text);
}
function write(type = "info", ...params) {
var line = params
.map((param) => {
if (!param) return `${param}`;
if (typeof param === "object") return JSON.stringify(param);
return param;
})
.join(" ");
document.querySelector("textarea").value +=
`${type.toUpperCase()}: ${line}\n`;
}
console.log = function () {
write("log", ...arguments);
logger.log.apply(console, arguments);
};
console.error = function () {
write("error", ...arguments);
logger.error.apply(console, arguments);
};
console.warn = function () {
write("warn", ...arguments);
logger.warn.apply(console, arguments);
};
console.info = function () {
write("info", ...arguments);
logger.info.apply(console, arguments);
};
function scriptLoaded(type, ok) {
if (ok) {
log("info", `${type} script is loaded`);
} else {
log("error", `${type} script is blocked on your computer`);
}
}
</script>
<script>
function pathOverwriter(data) {
console.info("pathOverwriter", data);
return "/overwritter-by-pathOverwriter" + data.path;
}
function appendMetadata(data) {
console.info("appendMetadata", data);
if (data.type === "pageview")
return {
page_id: 123,
};
else
return {
event_id: 124,
modified_at: null,
};
}
</script>
<!-- Normal collect script -->
<script
async
data-allow-params="project"
data-path-overwriter="pathOverwriter"
data-metadata-collector="appendMetadata"
data-hostname="playground.simpleanalytics.com"
data-ignore-metrics="referrer,utm,country,session,timeonpage,scrolled,useragent,screensize,viewportsize,language"
onerror="scriptLoaded('Normal embed', false)"
onload="scriptLoaded('Normal embed', true)"
src="/dist/latest/latest.js"
></script>
<!-- Auto events script -->
<script
async
data-hostname="playground.simpleanalytics.com"
data-collect="outbound,emails,downloads"
data-extensions="pdf,csv,docx,xlsx,zip,doc,xls"
data-use-title="true"
data-full-urls="false"
onerror="scriptLoaded('Auto events', false)"
onload="scriptLoaded('Auto events', true)"
src="/dist/latest/auto-events.js"
></script>
<script>
(function () {
function saLoadedLinkEvents() {
document
.querySelectorAll("a[data-sa-link-event]")
.forEach(function (element) {
var href = element.getAttribute("href");
var eventName = element.getAttribute("data-sa-link-event");
if (!href || !window.sa_event || !window.sa_event_loaded) return;
element.addEventListener("click", function (event) {
var target = element.getAttribute("target");
if (target === "_blank") {
event.preventDefault();
window.sa_event(eventName, function () {
window.location.href = href;
});
return false;
} else {
window.sa_event(eventName);
return true;
}
});
});
}
if (
document.readyState === "ready" ||
document.readyState === "complete"
) {
saLoadedLinkEvents();
} else {
document.addEventListener("readystatechange", function (event) {
if (event.target.readyState === "complete") saLoadedLinkEvents();
});
}
})();
</script>
</body>
</html>