-
Notifications
You must be signed in to change notification settings - Fork 8
/
template.tpl
515 lines (487 loc) · 30.7 KB
/
template.tpl
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
___TERMS_OF_SERVICE___
By creating or modifying this file you agree to Google Tag Manager's Community
Template Gallery Developer Terms of Service available at
https://developers.google.com/tag-manager/gallery-tos (or such other URL as
Google may provide), as modified from time to time.
___INFO___
{
"type": "TAG",
"id": "cvt_temp_public_id",
"version": 1,
"securityGroups": [],
"displayName": "Core Web Vitals",
"categories": [
"UTILITY"
],
"__wm": "VGVtcGxhdGUtQXV0aG9yX0NvcmVXZWJWaXRhbHMtU2ltby1BaGF2YQ\u003d\u003d",
"brand": {
"id": "github.com_gtm-templates-simo-ahava",
"displayName": "gtm-templates-simo-ahava",
"thumbnail": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAAAEYZJREFUeJztnXu4XUV1wH/35iFJiICQBwgECRZBASltFRqxVWoRhYpC+CgF/MAWabG1pVpahRZoK6Dgsz6wVqU8pJZoFcFSBSuCgUCIqA2KCVESlEBCJAlJ87i3f6x7e8+Z89ozZ9ae2fus3/etv87eM2vmzNp7z8xaa8AwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDMMwDKMyDKVWoMZMBl4EzAfmAfsC+wCzgL2AYzzLuxd4GngSWAOsBlYBK4CfATtjKK3A0cB3UysRyuTUCtSEOcBRY3I48DLgIOL279Fdfvtf4FHgh8DDwDLgAWBtxPpDeBvweGIdjAS8GDgPuB54DBgNEF9C6lgF3ARcABxGuV8MRyF9Yw/hAWA6cBLwKWTQhQzWFAbiypPAjcDZyFtPiz0Q4/iAYh1GYmYCZwCLgOeIM0BTG0ijjCBzg4uQz8FYDANfGavj0IjlGhkwCTgB+AI6RpGTgbiyFPhLYO8A3Rp591h5l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hGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIZhGIYxmPwfFggecKkAfg8AAAAASUVORK5CYII\u003d"
},
"description": "Load the Core Web Vitals library from a CDN and have it push key milestones (CLS, FID, LCP) into dataLayer for use in tags.",
"containerContexts": [
"WEB"
]
}
___TEMPLATE_PARAMETERS___
[
{
"type": "GROUP",
"name": "config",
"displayName": "Configuration",
"groupStyle": "NO_ZIPPY",
"subParams": [
{
"type": "CHECKBOX",
"name": "namespace",
"checkboxText": "Namespace objects",
"simpleValueType": true,
"defaultValue": false,
"help": "If you check this option, then each measurement will be nested under its own property in the webVitalsMeasurement dataLayer object. If you leave this option unchecked, then each measurement will use a shared set of object properties (and thus overwrite previous values)."
},
{
"type": "CHECKBOX",
"name": "allMetrics",
"checkboxText": "Collect all (available) web vitals metrics",
"simpleValueType": true,
"help": "Check this box to collect data for all \u003ca href\u003d\"https://github.com/GoogleChrome/web-vitals#metric\"\u003ecurrently available web vitals metrics\u003c/a\u003e. This includes the Core Web Vitals (INP, FID, CLS, LCP) as well as FCP and TTFB.",
"defaultValue": false
},
{
"type": "CHECKBOX",
"name": "attribution",
"checkboxText": "Send attribution data",
"simpleValueType": true,
"defaultValue": false,
"help": "Check this box to send \u003ca href\u003d\"https://github.com/GoogleChrome/web-vitals?tab\u003dreadme-ov-file#send-attribution-data\"\u003eattribution data\u003c/a\u003e. Note that only the target is sent."
}
]
},
{
"type": "GROUP",
"name": "info",
"displayName": "Information",
"groupStyle": "NO_ZIPPY",
"subParams": [
{
"type": "LABEL",
"name": "Info",
"displayName": "This template adds measurement handlers for the three \u003ca href\u003d\"https://web.dev/vitals/\" target\u003d\"_blank\"\u003ecore web vitals\u003c/a\u003e of \u003cstrong\u003eLCP\u003c/strong\u003e (Largest Contentful Paint), \u003cstrong\u003eINP\u003c/strong\u003e (Interaction to Next Paint), and \u003cstrong\u003eCLS\u003c/strong\u003e (Cumulative Layout Shift). \u003cstrong\u003eFID\u003c/strong\u003e (First Input Delay) is kept for backwards compatibility. See \u003ca href\u003d\"https://www.simoahava.com/custom-templates/core-web-vitals/\" target\u003d\"_blank\"\u003ethis guide\u003c/a\u003e for instructions on how to use this template."
}
]
}
]
___SANDBOXED_JS_FOR_WEB_TEMPLATE___
// Load template APIs
const copyFromWindow = require('copyFromWindow');
const createQueue = require('createQueue');
const injectScript = require('injectScript');
const log = require('logToConsole');
const Math = require('Math');
const dataLayerPush = createQueue('dataLayer');
// Helper for failure handling
const fail = msg => {
log(msg);
data.gtmOnFailure();
};
const getDebugTarget = (obj) => {
if (!obj.attribution) {
return undefined;
}
switch(obj.name) {
case 'CLS':
return obj.attribution.largestShiftTarget;
case 'INP':
return obj.attribution.interactionTarget;
case 'LCP':
return obj.attribution.element;
}
};
// Process the web vitals object and push to dataLayer
const process = obj => {
const dlObj = {event: 'coreWebVitals', webVitalsMeasurement: {}};
const cwvObj = {
name: obj.name,
id: obj.id,
value: obj.value,
delta: obj.delta,
valueRounded: Math.round(obj.name === 'CLS' ? obj.value * 1000 : obj.value),
deltaRounded: Math.round(obj.name === 'CLS' ? obj.delta * 1000 : obj.delta),
rating: obj.rating,
navigationType: obj.navigationType
};
if (data.attribution) {
const debugTarget = getDebugTarget(obj);
if (typeof debugTarget !== 'undefined') {
cwvObj.debugTarget = debugTarget;
}
if (obj.attribution.loadState) cwvObj.loadState = obj.attribution.loadState;
}
if (data.namespace) {
// If namespaced, add the measurement under the name of the measurement
dlObj.webVitalsMeasurement[obj.name] = cwvObj;
} else {
// If not namespaced, add the measurement directly into webVitalsMeasurement
dlObj.webVitalsMeasurement = cwvObj;
}
dataLayerPush(dlObj);
};
// Set the handlers
const setMilestones = () => {
const wv = copyFromWindow('webVitals');
if (!wv) return fail('[GTM / Core Web Vitals]: window.webVitals failed to load.');
wv.onINP(process);
wv.onFID(process);
wv.onCLS(process);
wv.onLCP(process);
if (data.allMetrics) {
wv.onFCP(process);
wv.onTTFB(process);
}
data.gtmOnSuccess();
};
// Load the library
const scriptSuffix = data.attribution ? '.attribution.iife.js' : '.iife.js';
injectScript('https://unpkg.com/web-vitals/dist/web-vitals' + scriptSuffix, setMilestones, data.gtmOnFailure, 'web-vitals');
___WEB_PERMISSIONS___
[
{
"instance": {
"key": {
"publicId": "logging",
"versionId": "1"
},
"param": [
{
"key": "environments",
"value": {
"type": 1,
"string": "debug"
}
}
]
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "access_globals",
"versionId": "1"
},
"param": [
{
"key": "keys",
"value": {
"type": 2,
"listItem": [
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "key"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
},
{
"type": 1,
"string": "execute"
}
],
"mapValue": [
{
"type": 1,
"string": "webVitals"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": false
},
{
"type": 8,
"boolean": false
}
]
},
{
"type": 3,
"mapKey": [
{
"type": 1,
"string": "key"
},
{
"type": 1,
"string": "read"
},
{
"type": 1,
"string": "write"
},
{
"type": 1,
"string": "execute"
}
],
"mapValue": [
{
"type": 1,
"string": "dataLayer"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": false
}
]
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "inject_script",
"versionId": "1"
},
"param": [
{
"key": "urls",
"value": {
"type": 2,
"listItem": [
{
"type": 1,
"string": "https://unpkg.com/web-vitals/dist/web-vitals.iife.js"
},
{
"type": 1,
"string": "https://unpkg.com/web-vitals/dist/web-vitals.attribution.iife.js"
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
}
]
___TESTS___
scenarios:
- name: Main test
code: "let success, failure;\nlet milestoneCount = 0;\nmock('createQueue', q =>\
\ {\n return (obj) => {\n if (obj.webVitalsMeasurement.id === 'LCP') assertThat(obj,\
\ 'incorrect LCP object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n id: 'LCP',\n name: 'LCP',\n \
\ value: 1.23,\n delta: 1.55,\n valueRounded: 1,\n deltaRounded:\
\ 2,\n rating: 'good',\n navigationType: 'navigate' \n \
\ }\n });\n if (obj.webVitalsMeasurement.id === 'FID') assertThat(obj,\
\ 'incorrect FID object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n id: 'FID',\n name: 'FID',\n \
\ value: 1.23,\n delta: 1.55,\n valueRounded: 1,\n deltaRounded:\
\ 2,\n rating: 'good',\n navigationType: 'navigate' \n \
\ }\n });\n if (obj.webVitalsMeasurement.id === 'CLS') assertThat(obj,\
\ 'incorrect CLS object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n id: 'CLS',\n name: 'CLS',\n \
\ value: 0.00123,\n delta: 0.00155,\n valueRounded: 1,\n \
\ deltaRounded: 2,\n rating: 'good',\n navigationType: 'navigate'\
\ \n }\n });\n if (obj.webVitalsMeasurement.id === 'INP') assertThat(obj,\
\ 'incorrect INP object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n id: 'INP',\n name: 'INP',\n \
\ value: 40,\n delta: 40,\n valueRounded: 40,\n deltaRounded:\
\ 40,\n rating: 'good',\n navigationType: 'navigate'\n }\n\
\ });\n };\n});\n\nmock('injectScript', (url, onsuccess, onfailure, id) =>\
\ {\n success = onsuccess;\n failure = onfailure;\n onsuccess();\n});\n\nmock('copyFromWindow',\
\ globalVar => {\n assertThat(globalVar, 'Incorrect global variable loaded from\
\ window').isEqualTo('webVitals');\n return {\n onCLS: (cb) => { milestoneCount++;\
\ cb({name: 'CLS', id: 'CLS', value: 0.00123, delta: 0.00155, valueRounded: 1,\
\ deltaRounded: 2, rating: 'good', navigationType: 'navigate'}); },\n onLCP:\
\ (cb) => { milestoneCount++; cb({name: 'LCP', id: 'LCP', value: 1.23, delta:\
\ 1.55, valueRounded: 1, deltaRounded: 2, rating: 'good', navigationType: 'navigate'});\
\ },\n onFID: (cb) => { milestoneCount++; cb({name: 'FID', id: 'FID', value:\
\ 1.23, delta: 1.55, valueRounded: 1, deltaRounded: 2, rating: 'good', navigationType:\
\ 'navigate'}); },\n onINP: (cb) => { milestoneCount++; cb({name: 'INP', id:\
\ 'INP', value: 40, delta: 40, valueRounded: 40, deltaRounded: 40, rating: 'good',\
\ navigationType: 'navigate'}); } \n };\n});\n \n// Call runCode to run the\
\ template's code.\nrunCode({});\n\n// Verify that the tag finished successfully.\n\
assertApi('injectScript').wasCalledWith('https://unpkg.com/web-vitals/dist/web-vitals.iife.js',\
\ success, failure, 'web-vitals');\nassertThat(milestoneCount, 'webVitals called\
\ incorrect number of times').isEqualTo(4);\nassertApi('gtmOnSuccess').wasCalled();"
- name: Namespace test
code: "let success, failure;\nlet milestoneCount = 0;\nlet lcpPushed, fidPushed,\
\ clsPushed, inpPushed;\nmock('createQueue', q => {\n return (obj) => {\n \
\ if (obj.webVitalsMeasurement.LCP) {\n assertThat(obj, 'incorrect LCP object\
\ pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n \
\ webVitalsMeasurement: {\n LCP: {\n id: 'LCP',\n \
\ name: 'LCP',\n value: 1.23,\n delta: 1.55,\n \
\ valueRounded: 1,\n deltaRounded: 2,\n rating: 'good',\n\
\ navigationType: 'navigate' \n }\n }\n\
\ });\n lcpPushed = true;\n }\n if (obj.webVitalsMeasurement.FID)\
\ {\n assertThat(obj, 'incorrect FID object pushed to dataLayer').isEqualTo({\n\
\ event: 'coreWebVitals',\n webVitalsMeasurement: {\n FID:\
\ {\n id: 'FID',\n name: 'FID',\n value: 1.23,\n\
\ delta: 1.55,\n valueRounded: 1,\n deltaRounded:\
\ 2,\n rating: 'good',\n navigationType: 'navigate' \
\ \n }\n }\n });\n fidPushed = true;\n }\n\
\ if (obj.webVitalsMeasurement.CLS) {\n assertThat(obj, 'incorrect CLS\
\ object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n CLS: {\n id: 'CLS',\n \
\ name: 'CLS',\n value: 0.00123,\n delta: 0.00155,\n\
\ valueRounded: 1,\n deltaRounded: 2,\n rating:\
\ 'good',\n navigationType: 'navigate' \n }\n \
\ }\n });\n clsPushed = true;\n }\n if (obj.webVitalsMeasurement.INP)\
\ {\n assertThat(obj, 'incorrect INP object pushed to dataLayer').isEqualTo({\n\
\ event: 'coreWebVitals',\n webVitalsMeasurement: {\n INP:\
\ {\n id: 'INP',\n name: 'INP',\n value: 40,\n\
\ delta: 40,\n valueRounded: 40,\n deltaRounded:\
\ 40,\n rating: 'good',\n navigationType: 'navigate' \
\ \n }\n } \n });\n inpPushed = true;\n\
\ }\n };\n});\n\nmock('injectScript', (url, onsuccess, onfailure, id) => {\n\
\ success = onsuccess;\n failure = onfailure;\n onsuccess();\n});\n\nmock('copyFromWindow',\
\ globalVar => {\n assertThat(globalVar, 'Incorrect global variable loaded from\
\ window').isEqualTo('webVitals');\n return {\n onCLS: (cb) => { milestoneCount++;\
\ cb({name: 'CLS', id: 'CLS', value: 0.00123, delta: 0.00155, valueRounded: 1,\
\ deltaRounded: 2, rating: 'good', navigationType: 'navigate'}); },\n onLCP:\
\ (cb) => { milestoneCount++; cb({name: 'LCP', id: 'LCP', value: 1.23, delta:\
\ 1.55, valueRounded: 1, deltaRounded: 2, rating: 'good', navigationType: 'navigate'});\
\ },\n onFID: (cb) => { milestoneCount++; cb({name: 'FID', id: 'FID', value:\
\ 1.23, delta: 1.55, valueRounded: 1, deltaRounded: 2, rating: 'good', navigationType:\
\ 'navigate'}); },\n onINP: (cb) => { milestoneCount++; cb({name: 'INP', id:\
\ 'INP', value: 40, delta: 40, valueRounded: 40, deltaRounded: 40, rating: 'good',\
\ navigationType: 'navigate'}); } \n };\n});\n \n// Call runCode to run the\
\ template's code.\nrunCode({namespace: true});\n\n// Verify that the tag finished\
\ successfully.\nassertApi('injectScript').wasCalledWith('https://unpkg.com/web-vitals/dist/web-vitals.iife.js',\
\ success, failure, 'web-vitals');\nassertThat(milestoneCount, 'webVitals called\
\ incorrect number of times').isEqualTo(4);\nassertThat(lcpPushed, 'LCP object\
\ not pushed into dataLayer').isEqualTo(true);\nassertThat(fidPushed, 'FID object\
\ not pushed into dataLayer').isEqualTo(true);\nassertThat(clsPushed, 'CLS object\
\ not pushed into dataLayer').isEqualTo(true);\nassertThat(inpPushed, 'INP object\
\ not pushed into dataLayer').isEqualTo(true);\nassertApi('gtmOnSuccess').wasCalled();"
- name: All metrics
code: "let success, failure;\nlet milestoneCount = 0;\nmock('createQueue', q =>\
\ {\n return (obj) => {\n if (obj.webVitalsMeasurement.id === 'LCP') assertThat(obj,\
\ 'incorrect LCP object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n id: 'LCP',\n name: 'LCP',\n \
\ value: 1.23,\n delta: 1.55,\n valueRounded: 1,\n deltaRounded:\
\ 2,\n rating: 'good',\n navigationType: 'navigate' \n\
\ }\n });\n if (obj.webVitalsMeasurement.id === 'FID') assertThat(obj,\
\ 'incorrect FID object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n id: 'FID',\n name: 'FID',\n \
\ value: 1.23,\n delta: 1.55,\n valueRounded: 1,\n deltaRounded:\
\ 2,\n rating: 'good',\n navigationType: 'navigate' \
\ \n }\n });\n if (obj.webVitalsMeasurement.id === 'CLS') assertThat(obj,\
\ 'incorrect CLS object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n id: 'CLS',\n name: 'CLS',\n \
\ value: 0.00123,\n delta: 0.00155,\n valueRounded: 1,\n \
\ deltaRounded: 2,\n rating: 'good',\n navigationType: 'navigate'\
\ \n }\n });\n if (obj.webVitalsMeasurement.id ===\
\ 'FCP') assertThat(obj, 'incorrect FCP object pushed to dataLayer').isEqualTo({\n\
\ event: 'coreWebVitals',\n webVitalsMeasurement: {\n id: 'FCP',\n\
\ name: 'FCP',\n value: 123.4,\n delta: 123.5,\n valueRounded:\
\ 123,\n deltaRounded: 124,\n rating: 'good',\n navigationType:\
\ 'navigate' \n }\n });\n if (obj.webVitalsMeasurement.id\
\ === 'INP') assertThat(obj, 'incorrect INP object pushed to dataLayer').isEqualTo({\n\
\ event: 'coreWebVitals',\n webVitalsMeasurement: {\n id: 'INP',\n\
\ name: 'INP',\n value: 40,\n delta: 40,\n valueRounded:\
\ 40,\n deltaRounded: 40,\n rating: 'good',\n navigationType:\
\ 'navigate' \n }\n });\n if (obj.webVitalsMeasurement.id\
\ === 'TTFB') assertThat(obj, 'incorrect TTFB object pushed to dataLayer').isEqualTo({\n\
\ event: 'coreWebVitals',\n webVitalsMeasurement: {\n id: 'TTFB',\n\
\ name: 'TTFB',\n value: 123.4,\n delta: 123.5,\n \
\ valueRounded: 123,\n deltaRounded: 124,\n rating: 'good',\n \
\ navigationType: 'navigate' \n }\n });\n };\n\
});\n\nmock('injectScript', (url, onsuccess, onfailure, id) => {\n success =\
\ onsuccess;\n failure = onfailure;\n onsuccess();\n});\n\nmock('copyFromWindow',\
\ globalVar => {\n assertThat(globalVar, 'Incorrect global variable loaded from\
\ window').isEqualTo('webVitals');\n return {\n onCLS: (cb) => { milestoneCount++;\
\ cb({name: 'CLS', id: 'CLS', value: 0.00123, delta: 0.00155, valueRounded: 1,\
\ deltaRounded: 2, rating: 'good', navigationType: 'navigate'}); },\n onLCP:\
\ (cb) => { milestoneCount++; cb({name: 'LCP', id: 'LCP', value: 1.23, delta:\
\ 1.55, valueRounded: 1, deltaRounded: 2, rating: 'good', navigationType: 'navigate'});\
\ },\n onFID: (cb) => { milestoneCount++; cb({name: 'FID', id: 'FID', value:\
\ 1.23, delta: 1.55, valueRounded: 1, deltaRounded: 2, rating: 'good', navigationType:\
\ 'navigate'}); },\n onFCP: (cb) => { milestoneCount++; cb({name: 'FCP', id:\
\ 'FCP', value: 123.4, delta: 123.5, valueRounded: 123, deltaRounded: 124, rating:\
\ 'good', navigationType: 'navigate'}); },\n onINP: (cb) => { milestoneCount++;\
\ cb({name: 'INP', id: 'INP', value: 40, delta: 40, valueRounded: 40, deltaRounded:\
\ 40, rating: 'good', navigationType: 'navigate'}); },\n onTTFB: (cb) => {\
\ milestoneCount++; cb({name: 'TTFB', id: 'TTFB', value: 123.4, delta: 123.5,\
\ valueRounded: 123, deltaRounded: 124, rating: 'good', navigationType: 'navigate'});\
\ }\n };\n});\n \n// Call runCode to run the template's code.\nrunCode({allMetrics:\
\ true});\n\n// Verify that the tag finished successfully.\nassertApi('injectScript').wasCalledWith('https://unpkg.com/web-vitals/dist/web-vitals.iife.js',\
\ success, failure, 'web-vitals');\nassertThat(milestoneCount, 'webVitals called\
\ incorrect number of times').isEqualTo(6);\nassertApi('gtmOnSuccess').wasCalled();"
- name: Attribution test
code: "let success, failure;\nlet milestoneCount = 0;\nmock('createQueue', q =>\
\ {\n return (obj) => {\n if (obj.webVitalsMeasurement.id === 'LCP') assertThat(obj,\
\ 'incorrect LCP object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n id: 'LCP',\n name: 'LCP',\n \
\ value: 1.23,\n delta: 1.55,\n valueRounded: 1,\n deltaRounded:\
\ 2,\n rating: 'good',\n navigationType: 'navigate',\n debugTarget:\
\ '.mycss_lcp' \n }\n });\n if (obj.webVitalsMeasurement.id\
\ === 'FID') assertThat(obj, 'incorrect FID object pushed to dataLayer').isEqualTo({\n\
\ event: 'coreWebVitals',\n webVitalsMeasurement: {\n id: 'FID',\n\
\ name: 'FID',\n value: 1.23,\n delta: 1.55,\n valueRounded:\
\ 1,\n deltaRounded: 2,\n rating: 'good',\n navigationType:\
\ 'navigate' \n }\n });\n if (obj.webVitalsMeasurement.id ===\
\ 'CLS') assertThat(obj, 'incorrect CLS object pushed to dataLayer').isEqualTo({\n\
\ event: 'coreWebVitals',\n webVitalsMeasurement: {\n id: 'CLS',\n\
\ name: 'CLS',\n value: 0.00123,\n delta: 0.00155,\n \
\ valueRounded: 1,\n deltaRounded: 2,\n rating: 'good',\n \
\ navigationType: 'navigate',\n debugTarget: '.mycss_cls' \n\
\ }\n });\n if (obj.webVitalsMeasurement.id === 'INP') assertThat(obj,\
\ 'incorrect INP object pushed to dataLayer').isEqualTo({\n event: 'coreWebVitals',\n\
\ webVitalsMeasurement: {\n id: 'INP',\n name: 'INP',\n \
\ value: 40,\n delta: 40,\n valueRounded: 40,\n deltaRounded:\
\ 40,\n rating: 'good',\n navigationType: 'navigate',\n debugTarget:\
\ '.mycss_inp'\n }\n });\n };\n});\n\nmock('injectScript', (url, onsuccess,\
\ onfailure, id) => {\n success = onsuccess;\n failure = onfailure;\n onsuccess();\n\
});\n\nmock('copyFromWindow', globalVar => {\n assertThat(globalVar, 'Incorrect\
\ global variable loaded from window').isEqualTo('webVitals');\n return {\n \
\ onCLS: (cb) => { milestoneCount++; cb({name: 'CLS', id: 'CLS', value: 0.00123,\
\ delta: 0.00155, valueRounded: 1, deltaRounded: 2, rating: 'good', navigationType:\
\ 'navigate', attribution: {largestShiftTarget: '.mycss_cls'}}); },\n onLCP:\
\ (cb) => { milestoneCount++; cb({name: 'LCP', id: 'LCP', value: 1.23, delta:\
\ 1.55, valueRounded: 1, deltaRounded: 2, rating: 'good', navigationType: 'navigate',\
\ attribution: {element: '.mycss_lcp'}}); },\n onFID: (cb) => { milestoneCount++;\
\ cb({name: 'FID', id: 'FID', value: 1.23, delta: 1.55, valueRounded: 1, deltaRounded:\
\ 2, rating: 'good', navigationType: 'navigate'}); },\n onINP: (cb) => { milestoneCount++;\
\ cb({name: 'INP', id: 'INP', value: 40, delta: 40, valueRounded: 40, deltaRounded:\
\ 40, rating: 'good', navigationType: 'navigate', attribution: {interactionTarget:\
\ '.mycss_inp'}}); } \n };\n});\n \n// Call runCode to run the template's\
\ code.\nrunCode({attribution: true});\n\n// Verify that the tag finished successfully.\n\
assertApi('injectScript').wasCalledWith('https://unpkg.com/web-vitals/dist/web-vitals.attribution.iife.js',\
\ success, failure, 'web-vitals');\nassertThat(milestoneCount, 'webVitals called\
\ incorrect number of times').isEqualTo(4);\nassertApi('gtmOnSuccess').wasCalled();"
setup: ''
___NOTES___
Created on 21/01/2021, 11:32:35