-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.tpl
1170 lines (1127 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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
___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": "GA4 Advanced",
"brand": {
"id": "brand_dummy",
"displayName": "",
"thumbnail": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMAAAADACAYAAABS3GwHAAAABmJLR0QA/wD/AP+gvaeTAAAJfElEQVR42u3d34tc5R3H8Y+KiRGhCfRCiAZikOCFscbEmlI1Vir0D+iF4JUXRVoW3J3nbMRIOgkiSIsiFWK8iF7ENJxn1jVGI4JeifiDYozZRDE0mz3P7Aaym92wluw8s0lOLzKLrYghs/Oc85z4fsOBvX3mfF9znjM/diQiIiIiIiIiIiIiIiKiHymv69p2Qxu81aC3Sr3VYW91xlt5b9X2VtPe6mtvtd83tH3O6uH8oJbyyFGlOzekW3xDz/qGMm+VX+Ex4612txvawCNJleo/qW5uNbSr8wyfL/ZoW33YHtJ6HlmKvnZDT3irs70Y/B8cF9pWL+eplvEoU3z7/GEt96mGAwz+D4+RVqq1POIUz14/1Uqf6kgBw79wTM2n2sQjT3EMv9WJAod/4ZhtD2kjZ4DK2/a8oRW+oWMlDH/urfKW1eRcqtWcCSp++HNdU9Ce/6ePVJ/nqZZwRqjQWlZ9pQ//90edM0LF7fv/qVu91WxEAOZa+7SGM0OF5K12RzT8C8frnBkKv/UZ0m3eaj5CAO25VKs4QxT62f/5CId/4YZ4G2eIwr3yk+o6b3UqWgBW33CWKFjtId0X8fBfem+Am2EKtv1JtTV2AO2GHudMUaj9v43+CmC1kzNFoQCMRH8FsPqAM0VBallNxg7AW53gTFGoK4CvAIApzhSFApBX4PCcKfo5A8g5UwQAIgAQAYAIAEQAIAIAEQCIAEAEACIAEAGACABEACACABEAiABABAAiABAAAEAAAAABAAAEAAAQAABAAA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upoOuH7dGcPaOluid3q0ttwZfTxW029jWFtnS/SOt7rYo+H/eD6NY22lND6guzOjVzq/A3zF+/ws0c7Qvw65iJdJ13XW1s0PhMy6RHt6/TNPPXyvYF3L6hVvNdXNPt9b7Zm3ca6tlI7WtSSr6QFnVHdGb7qaRjqD4zvHlDM64oyGnFE9S3T/Yj7VWfTWyCV60NW0zSUa7qxjurOu9sKPgGdGb3fW9kjRPwK+mK3RfKoHfaptPtWwT3XEW017K9/ZLk17q6M+1dveqt6yeqTyr+0TEREREREREREREVEl+i+UeTUxohjOewAAAABJRU5ErkJggg\u003d\u003d"
},
"description": "GA4 Tag powered by stape.",
"containerContexts": [
"SERVER"
]
}
___TEMPLATE_PARAMETERS___
[
{
"type": "TEXT",
"name": "measurementId",
"displayName": "Measurement ID",
"simpleValueType": true,
"help": "If the event came from a GA4 web tag, you can leave this field blank to inherit the measurement ID of the event",
"valueHint": "G-1234567890"
},
{
"type": "SELECT",
"name": "redactVisitorIP",
"displayName": "Redact visitor IP address",
"macrosInSelect": true,
"selectItems": [
{
"value": false,
"displayValue": "false"
},
{
"value": true,
"displayValue": "true"
}
],
"simpleValueType": true,
"help": "Remove visitor IP address from the event. Reports based on the event will not include geographic information."
},
{
"type": "TEXT",
"name": "eventName",
"displayName": "Event Name",
"simpleValueType": true,
"help": "The event name to send to Google. See the \u003ca href\u003d\"https://developers.google.com/analytics/devguides/collection/ga4/events?client_type\u003dgtag\" target\u003d\"_blank\"\u003erecommended events\u003c/a\u003e for more information. If this field is blank, the value of the event_name parameter will be sent.",
"valueHint": "Defaults to event.event_name"
},
{
"type": "GROUP",
"name": "eventParametersGroup",
"displayName": "Event Parameters",
"groupStyle": "ZIPPY_CLOSED",
"subParams": [
{
"type": "SELECT",
"name": "defaultParametersToInclude",
"displayName": "Default Parameters to Include",
"macrosInSelect": false,
"selectItems": [
{
"value": "all",
"displayValue": "All"
},
{
"value": "none",
"displayValue": "None"
}
],
"simpleValueType": true,
"help": "Specify which event parameters to send to Google by default. Do not send personally identifiable information (PII) to Google Analytics. See the \u003ca href\u003d\"https://developers.google.com/analytics/devguides/collection/app-web/policy\" target\u003d\"_blank\"\u003edocumentation\u003c/a\u003e for more details. The following parameters are excluded regardless of the selected option: first_name, last_name, email_address, phone_number, address"
},
{
"type": "SIMPLE_TABLE",
"name": "parametersToExclude",
"displayName": "Parameters to Exclude",
"simpleTableColumns": [
{
"defaultValue": "",
"displayName": "Name",
"name": "name",
"type": "TEXT",
"isUnique": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
}
],
"help": "Event parameters listed here will not be sent to Google.",
"newRowButtonText": "+ Add param"
},
{
"type": "PARAM_TABLE",
"name": "parametersToOverride",
"displayName": "Parameters to Add / Edit",
"paramTableColumns": [
{
"param": {
"type": "TEXT",
"name": "name",
"displayName": "Name",
"simpleValueType": true
},
"isUnique": true
},
{
"param": {
"type": "TEXT",
"name": "value",
"displayName": "Value",
"simpleValueType": true
},
"isUnique": false
},
{
"param": {
"type": "CHECKBOX",
"name": "addParam",
"checkboxText": "Add if not exists",
"simpleValueType": true
},
"isUnique": false
}
],
"help": "Event parameters listed here will be added to the event sent to Google. If the event parameter is already included, then the value will be replaced with the specified value.",
"newRowButtonText": "+ Add param"
}
]
},
{
"type": "GROUP",
"name": "userPropertiesGroup",
"displayName": "User Properties",
"groupStyle": "ZIPPY_CLOSED",
"subParams": [
{
"type": "SELECT",
"name": "defaultUserPropertiesToInclude",
"displayName": "Default Properties to Include",
"macrosInSelect": false,
"selectItems": [
{
"value": "all",
"displayValue": "All"
},
{
"value": "none",
"displayValue": "None"
}
],
"simpleValueType": true,
"help": "Specify which user properties to send to Google by default."
},
{
"type": "SIMPLE_TABLE",
"name": "userPropertiesToExclude",
"displayName": "Properties to Exclude",
"simpleTableColumns": [
{
"defaultValue": "",
"displayName": "Name",
"name": "name",
"type": "TEXT",
"isUnique": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
}
],
"help": "User properties listed here will not be sent to Google"
},
{
"type": "SIMPLE_TABLE",
"name": "userPropertiesToAdd",
"displayName": "Properties to Add / Edit",
"simpleTableColumns": [
{
"defaultValue": "",
"displayName": "Name",
"name": "name",
"type": "TEXT",
"isUnique": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
},
{
"defaultValue": "",
"displayName": "Value",
"name": "value",
"type": "TEXT",
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
}
],
"help": "User properties listed here will be added to the event sent to Google. If the user property is already included, then the value will be replaced with the specified value."
}
]
},
{
"type": "GROUP",
"name": "requestHeadersGroup",
"displayName": "Request Headers",
"groupStyle": "ZIPPY_CLOSED",
"subParams": [
{
"type": "PARAM_TABLE",
"name": "requestHeaders",
"displayName": "",
"paramTableColumns": [
{
"param": {
"type": "TEXT",
"name": "name",
"displayName": "Name",
"simpleValueType": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
},
"isUnique": true
},
{
"param": {
"type": "TEXT",
"name": "value",
"displayName": "Value",
"simpleValueType": true
},
"isUnique": false
}
],
"newRowButtonText": "+ Add header"
}
]
},
{
"type": "GROUP",
"name": "dataSourceGroup",
"displayName": "Data Source Settings",
"groupStyle": "ZIPPY_CLOSED",
"subParams": [
{
"type": "RADIO",
"name": "dataSource",
"displayName": "",
"radioItems": [
{
"value": "request",
"displayValue": "Incoming Request"
},
{
"value": "eventData",
"displayValue": "Event Data (Beta)",
"help": ""
}
],
"simpleValueType": true,
"defaultValue": "request"
}
]
},
{
"type": "GROUP",
"name": "logSettingsGroup",
"displayName": "Logs Settings",
"groupStyle": "ZIPPY_CLOSED",
"subParams": [
{
"type": "RADIO",
"name": "logType",
"displayName": "",
"radioItems": [
{
"value": "no",
"displayValue": "Do not log"
},
{
"value": "debug",
"displayValue": "Log to console during debug and preview"
},
{
"value": "always",
"displayValue": "Always log to console"
}
],
"simpleValueType": true,
"defaultValue": "debug"
}
]
}
]
___SANDBOXED_JS_FOR_SERVER___
const logToConsole = require('logToConsole');
const getContainerVersion = require('getContainerVersion');
const getRequestHeader = require('getRequestHeader');
const getAllEventData = require('getAllEventData');
const getRequestBody = require('getRequestBody');
const getRequestQueryParameters = require('getRequestQueryParameters');
const encodeUriComponent = require('encodeUriComponent');
const JSON = require('JSON');
const parseUrl = require('parseUrl');
const Object = require('Object');
const sendHttpRequest = require('sendHttpRequest');
const getType = require('getType');
const containerVersion = getContainerVersion();
const isDebug = containerVersion.debugMode;
const isLoggingEnabled = determinateIsLoggingEnabled();
const traceId = getRequestHeader('trace-id');
const userAgent = getRequestHeader('User-Agent');
const eventData = getAllEventData();
const eventName = data.eventName ? data.eventName : eventData.event_name;
let postUrl = 'https://www.google-analytics.com/g/collect';
const queryParams = getQueryParams();
const events = getEvents();
if (data.measurementId) {
queryParams.tid = data.measurementId;
}
if (data.redactVisitorIP !== 'false') {
queryParams._uip = encodeUriComponent('::');
Object.delete(queryParams, 'ep.ip_override');
}
if (data.parametersToExclude && data.parametersToExclude.length) {
data.parametersToExclude.forEach((param) => {
Object.delete(queryParams, param.name);
events.forEach((event) => {
Object.delete(event, param.name);
});
});
}
if (data.parametersToOverride && data.parametersToOverride.length) {
data.parametersToOverride.forEach((param) => {
if (isValidParam(queryParams[param.name]) || param.addParam) {
queryParams[param.name] = param.value;
}
events.forEach((event) => {
if (isValidParam(event[param.name])) {
event[param.name] = param.value;
}
});
});
}
if (data.userPropertiesToExclude && data.userPropertiesToExclude.length) {
data.userPropertiesToExclude.forEach((property) => {
deleteUserProperty(queryParams, property.name);
events.forEach((event) => {
deleteUserProperty(event, property.name);
});
});
}
if (data.userPropertiesToAdd && data.userPropertiesToAdd.length) {
const target = events.length ? events[0] : queryParams;
data.userPropertiesToAdd.forEach((property) => {
target['up.' + property.name] = property.value;
});
}
const queryParamsString = objectToQueryString(queryParams);
if (queryParamsString) {
postUrl = postUrl + '?' + queryParamsString;
}
const body = events.length
? events.map(objectToQueryString).join('\n')
: undefined;
const headers = {
'Content-Type': 'text/plain;charset=UTF-8',
'User-Agent': userAgent,
};
if (data.requestHeaders && data.requestHeaders.length) {
data.requestHeaders.forEach((header) => {
headers[header.name] = header.value;
});
}
if (isLoggingEnabled) {
logToConsole(
JSON.stringify({
Name: 'GA4Advanced',
Type: 'Request',
TraceId: traceId,
EventName: eventName,
})
);
}
sendHttpRequest(
postUrl,
{
headers: headers,
method: 'POST',
},
body
)
.then((response) => {
if (isLoggingEnabled) {
logToConsole(
JSON.stringify({
Name: 'GA4Advanced',
Type: 'Response',
TraceId: traceId,
EventName: eventName,
ResponseStatusCode: response.statusCode,
ResponseHeaders: response.headers,
ResponseBody: response.body,
})
);
}
data.gtmOnSuccess();
})
.catch(() => {
data.gtmOnFailure();
});
function getQueryParams() {
if (data.defaultParametersToInclude === 'none') return {};
if (data.dataSource === 'request') return getQueryParamsFromRequest();
return getQueryParamsFromEventData();
}
function getEvents() {
if (data.dataSource === 'eventData') return [];
const requestBody = getRequestBody();
const requestBodyLines = requestBody ? requestBody.split('\n') : [];
return requestBodyLines.map((requestBodyLine) => {
return parseUrl('https://parse.com?' + requestBodyLine).searchParams;
});
}
function getQueryParamsFromRequest() {
const params = getRequestQueryParameters();
if (data.defaultUserPropertiesToInclude === 'none') {
Object.keys(params).forEach((key) => {
if (key.indexOf('upn.') === 0 || key.indexOf('up.') === 0) {
Object.delete(params, key);
}
});
}
return params;
}
function getQueryParamsFromEventData() {
const params = {};
const clientHints = eventData.client_hints || {};
const settings = [
/**
* Request parameters:
*/
{
param: 'v', // (Protocol Version)
value: eventData['x-ga-protocol_version'],
},
{
param: 'tid', // (Tracking ID)
value: eventData['x-ga-measurement_id'],
},
{
param: 'gtm', // (GTM Hash Info),
value: eventData['x-ga-gtm_version'],
},
{
param: '_p', // (Random Page Load Hash)
value: eventData['x-ga-page_id'],
},
{
param: 'sr', // (Screen Resolution),
value: eventData['screen_resolution'],
},
{
param: 'ul', // (User Language),
value: eventData['language'],
},
{
param: 'dh', // (Document Hostname)
value: undefined,
},
{
param: 'cid', // (client Id),
value: eventData['client_id'],
},
{
param: '_s', // (Hit Counter)
value: undefined,
},
{
param: 'richsstsse', // (richsstsse)
value: undefined, // param without value in query params, how to handle ???
},
/**
* Shared:
*/
{
param: 'dl', // (Document location),
value: eventData['page_location'],
},
{
param: 'dt', // (Document title)
value: eventData['page_title'],
},
{
param: 'dr', // (Document referrer)
value: undefined,
},
{
param: '_z', // (_z) - some hash
value: undefined,
},
{
param: '_eu', // (Event usage)
value: undefined,
},
{
param: 'edid', // (Event Debug ID?)
value: undefined,
},
{
param: '_dbg', // (is Debug)
value: eventData.debug_mode === 'true' ? 1 : undefined,
},
{
param: 'ir', // (Ignore Referrer)
value: undefined,
},
{
param: 'tt', // (Traffic Type)
value: undefined,
},
{
param: 'gcs', // (Google Consent Status)
value: undefined,
},
{
param: 'gcu', // (Google Consent Update)
value: undefined,
},
{
param: 'gcut', // (Google Consent Update Type)
value: undefined,
},
{
param: 'gcd', // (Google Consent Default)
value: undefined,
},
{
param: '_glv', // (is Google Linker Valid)
value: undefined,
},
/**
* Event Parameters:
*/
{
param: 'en', // (Event Name)
value: eventName,
},
{
param: '_et', // (Engagement Time)
value: eventData.engagement_time_msec,
},
{
param: '_c', // is Conversion
value: eventData['x-ga-system_properties']
? eventData['x-ga-system_properties'].c
: undefined,
},
{
param: '_ee', // external event
value: undefined,
},
{
param: 'ep.debug_mode',
value: eventData.debug_mode,
},
{
param: 'ep.event_id',
value: eventData.event_id,
},
{
param: 'ep.value',
value: eventData.value,
},
{
param: 'ep.transaction_id',
value: eventData.transaction_id,
},
{
param: 'ep.tax',
value: eventData.tax,
},
{
param: 'ep.shipping',
value: eventData.shipping,
},
{
param: 'ep.payment_type',
value: eventData.payment_type,
},
{
param: 'ep.city',
value: eventData.city,
},
{
param: 'ep.phone',
value: eventData.phone,
},
{
param: 'ep.object',
value: eventData.object,
},
{
param: 'ep.long',
value: eventData.long,
},
{
param: 'ep.cyr',
value: eventData.cyr,
},
{
param: 'ep.cyrl',
value: eventData.cyrl,
},
{
param: 'ep.percent_scrolled',
value: eventData.percent_scrolled,
},
{
param: 'ep.plays_count',
value: eventData.plays_count,
},
/**
* E-Commerce Main:
*/
{
param: 'cu', // Currency Code
value: eventData.currency,
},
{
param: 'ep.affiliation', // Affiliation
value: undefined,
},
{
param: 'epn.value', // Transaction Revenue
value: eventData.value, // ???
},
{
param: 'epn.tax', // Transaction Tax
value: eventData.tax, // ???
},
{
param: 'epn.shipping', // Transaction Shipping
value: eventData.shipping, // ???
},
{
param: 'pi', // Promotion ID
value: undefined,
},
{
param: 'pn', // Promotion Name
value: undefined,
},
{
param: 'cn', // Creative Name
value: undefined,
},
{
param: 'cs', // Creative Slot
value: undefined,
},
{
param: 'lo', // Location id
value: undefined,
},
/**
* Campaign Attribution:
*/
{
param: 'cm', // Campaign Medium
value: undefined,
},
{
param: 'cs', // Campaign Source
value: undefined,
},
{
param: 'cn', // Campaign Name
value: undefined,
},
{
param: 'cc', // Campaign Content
value: undefined,
},
{
param: 'ck', // Campaign Term
value: undefined,
},
{
param: 'ccf', // Campaign Creative Format
value: undefined,
},
{
param: '_rnd', // Gclid Deduper
value: undefined,
},
// Session / User Related:
{
param: 'uid', // User Id
value: eventData.user_id,
},
{
param: '_fid', // Firebase Id
value: eventData.firebase_id, // ???
},
{
param: 'sid', // Session Id
value: eventData.ga_session_id,
},
{
param: 'sct', // Session count
value: eventData.ga_session_number,
},
{
param: 'seg', // Session Engagement
value: eventData['x-ga-mp2-seg'], // ???
},
{
param: '_fv', // First Visit
value: undefined, // If the "_ga_THYNGSTER" cookie is not set, the first event will have this value present. This will internally create a new "first_visit" event on GA4. If this event is also a conversion the value will be "2" if not, will be "1"
},
{
param: '_ss', // Session start
value: undefined, // If the "_ga_THYNGSTER" cookie last session time value is older than 1800 seconds, the current event will have this value present. This will internally create a new "session_start" event on GA4. If this event is also a conversion the value will be "2" if not, will be "1"
},
{
param: '_fplc', // First Party Linker Cookie
value: undefined,
},
{
param: '_nsi', // New Session Id
value: undefined,
},
{
param: 'gdid', // Google Developer ID
value: undefined,
},
{
param: '_uc', // User Country
value: undefined,
},
// Client Hints:
{
param: 'uaa', // User Agent Architecture
value: clientHints.architecture,
},
{
param: 'uab', // User Agent Bitness
value: clientHints.bitness,
},
{
param: 'uafvl', // User Agent Full Version List
value: clientHints.full_version_list
? clientHints.full_version_list
.map((item) => {
return (
encodeUriComponent(item.brand) +
';' +
encodeUriComponent(item.version)
);
})
.join('|')
: undefined,
},
{
param: 'uamb', // User Agent Mobile
value: clientHints.mobile ? 1 : 0,
},
{
param: 'uam', // User Agent Model
value: clientHints.model,
},
{
param: 'uap', // User Agent Platform
value: clientHints.platform,
},
{
param: 'uapv', // User Agent Platform Version
value: clientHints.platform_version,
},
{
param: 'uaw', // User Agent WOW64
value: clientHints.wow64 ? 1 : 0,
},
/**
* Uncategorized / Missing Info:
*/
{
param: 'gtm_up', //
value: undefined,
},
{
param: '_ecid', // European Consent Mode Enabled ID
value: undefined,
},
{
param: '_uei', //
value: undefined,
},
{
param: '_gaz', // Create Google Join
value: undefined,
},
{
param: '_rdi', // Redact Device Info
value: undefined, // Maybe data.redactVisitorIP ???
},
{
param: '_geo', // Geo Granularity
value: undefined,
},
{
param: 'us_privacy', // US Privacy Signal
value: undefined,
},
{
param: 'gdpr', // GDPR applies or not (IAB TCFv2)
value: undefined,
},
{
param: 'gdpr_consent', // GDPR Vendors Lists IDs (GVL ID)(IAB TCFv2)
value: undefined,
},
];
/**
* Items Parameters
*/
if (eventData.items && eventData.items.length) {
eventData.items.forEach((item) => {
const value = [
{
param: 'id',
value: item.item_id,
},
{
param: 'nm',
value: item.item_name,
},
{
param: 'ln',
value: item.item_list_name,
},
{
param: 'ln',
value: item.item_list_id,
},
{
param: 'br',
value: item.item_brand,
},
{
param: 'ca',
value: item.item_category,
},
{
param: 'ca2', // c2 or ca2 ??? ga4 base - c2 but https://www.thyngster.com/ga4-measurement-protocol-cheatsheet/ - ca2
value: item.item_category2,
},
{
param: 'ca3',
value: item.item_category3,
},
{
param: 'ca4',
value: item.item_category4,
},
{
param: 'ca5',
value: item.item_category5,
},
{
param: 'va',
value: item.item_variant,
},
{
param: 'lp',
value: item.index,
},
{
param: 'qt',
value: item.quantity,
},
{
param: 'pr',
value: item.price,
},
{
param: 'cp',
value: item.coupon, // ??
},
{
param: 'ds',
value: item.discount, // ??
},
{
param: 'af',
value: item.affiliation, // ??
},
];
settings.push({
param: 'pr' + item.index,
value: value
.filter((setting) => isValidParam(setting.value))
.map((setting) => setting.param + setting.value)
.join('~'),
});
});
}
/**
* User properties
*/
if (data.defaultUserPropertiesToInclude === 'all') {
const userProperties = eventData['x-ga-mp2-user_properties'] || {};
Object.keys(userProperties).forEach((key) => {
settings.push({
param: 'up.' + key,
value: userProperties[key],
});
});
}
settings.forEach((setting) => {
if (isValidParam(setting.value)) {
params[setting.param] = setting.value;
}
});
return params;
}
function deleteUserProperty(obj, propertyName) {
if (obj['up.' + propertyName]) {
Object.delete(obj, 'up.' + propertyName);
}
if (obj['upn.' + propertyName]) {
Object.delete(obj, 'upn.' + propertyName);
}
}
function objectToQueryString(obj) {
return Object.keys(obj)
.map((key) =>
isValidParam(obj[key]) ? key + '=' + encodeUriComponent(obj[key]) : key
)
.join('&');
}
function determinateIsLoggingEnabled() {
if (!data.logType) {
return isDebug;
}
if (data.logType === 'no') {
return false;
}
if (data.logType === 'debug') {
return isDebug;