-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.tpl
365 lines (328 loc) · 13.2 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
___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": "Elevar Monitoring Facebook Tag",
"brand": {
"id": "brand_dummy",
"displayName": "",
"thumbnail": "data:image/png;base64,iVBORw0KGgoAAAANSUh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t4eq6do3rDqBAChjJRzrTcktJZLRwA0+yaLChJzAKxeUVbHQ0Il880Q1hwAST+eWgI18x6vaqUwBaA/vnDVwtcvpP17VAvjxfDKACxfUyDpXOtFMc3kWRmA1XuCVDdczBTKS3HUAVi7J0jKt99LAlrNqwkAFvr/JnUvtAJBCYDF7me+WAhFVFZCrRTMK3GVACTjOXEw7oCZwvl9f3XVpAFY/DaAv/RQo9ZKA0jGc+KCJjNnozaFh5uZXkHEkQJg5XYU8cVQ1c0Ys4XxYjxDAJWuR9R+9S/g+Ws+hnWiLoDKATrhIWBCfLnjpIY5bPIANQFUlhxEzVc+FegvN8vXmqoAxK2ITCw+Qah8JYw/3ZQXf8MgLLqcwlLwqMnPD+aZKOEPuIoABuK5fQCL739Z+Y77x8VCKOG/5aqJX24BFq8gnmeiQb/Wqwu/EsMsgLKXm/gmuvmk/ZhmWsAUgUd94RtXeQxbgPDdZ8ZoKFQcX/sh4sZlYXNbKgMoi7zszQawuOaFxO0ls6quhZtbSnOlN1yKMGfWjyWrgA9AVilN4f4Hksmi5Awd7h8AAAAASUVORK5CYII\u003d"
},
"description": "The Facebook Tag adds monitoring to your Facebook Tags. Attach FB tag information to your variable errors and notice critical errors immediately.\n\nThe tag is powered by Elevar Monitoring Variables.",
"categories": ["UTILITY", "ANALYTICS", "TAG_MANAGEMENT"],
"containerContexts": [
"WEB"
]
}
___TEMPLATE_PARAMETERS___
[
{
"type": "TEXT",
"name": "tagName",
"displayName": "Tag Name",
"simpleValueType": true,
"help": "This should equal the GTM Tag Name. This is used to report what tags were associated to the error to Elevar Monitoring dashboard."
},
{
"type": "TEXT",
"name": "type",
"displayName": "Type",
"simpleValueType": true,
"defaultValue": "track",
"alwaysInSummary": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
],
"help": "This will be used as the first parameter of the \"fbq\" function",
"valueHint": "track"
},
{
"type": "TEXT",
"name": "event",
"displayName": "Event",
"simpleValueType": true,
"alwaysInSummary": true,
"help": "This will be used as the second parameter of the \"fbq\" function",
"valueHint": "Purchase"
},
{
"type": "PARAM_TABLE",
"name": "content",
"displayName": "Data",
"paramTableColumns": [
{
"param": {
"type": "TEXT",
"name": "key",
"displayName": "Key",
"simpleValueType": true
},
"isUnique": true
},
{
"param": {
"type": "TEXT",
"name": "value",
"displayName": "Value",
"simpleValueType": true
},
"isUnique": false
},
{
"param": {
"type": "TEXT",
"name": "variableName",
"displayName": "Variable Name",
"simpleValueType": true,
"enablingConditions": [],
"help": "If you used a GTM variable as the value in the previous field input the name of that GTM variable here. The variable name is used to associate the variable errors to the tags that used those variables."
},
"isUnique": false
}
],
"help": "(Optional) This will be converted to a JSON object and will be sent as the third parameter of the \"fbq\" function."
}
]
___SANDBOXED_JS_FOR_WEB_TEMPLATE___
const log = require("logToConsole");
const createQueue = require("createQueue");
const callInWindow = require("callInWindow");
const TAG_INFO = "elevar_gtm_tag_info";
const addTagInformation = createQueue(TAG_INFO);
const variablesUsed = [];
/*
NOTE: This is almost identical to the snapchat template, so if a bug
is fixed here. It should also be fixed in the snapchat template.
*/
if (!data.content && !data.event) {
data.gtmOnFailure();
}
if (data.content) {
// Additional Data to send
const contentObj = {};
data.content.forEach(item => {
contentObj[item.key] = item.value;
if (item.variableName) variablesUsed.push(item.variableName);
});
callInWindow("fbq", data.type, data.event, contentObj);
} else {
callInWindow("fbq", data.type, data.event);
}
addTagInformation({
channel: 'facebook',
tagName: data.tagName,
eventId: data.gtmEventId,
variables: variablesUsed
});
data.gtmOnSuccess();
___WEB_PERMISSIONS___
[
{
"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": "elevar_gtm_tag_info"
},
{
"type": 8,
"boolean": true
},
{
"type": 8,
"boolean": true
},
{
"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": "fbq"
},
{
"type": 8,
"boolean": false
},
{
"type": 8,
"boolean": false
},
{
"type": 8,
"boolean": true
}
]
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "logging",
"versionId": "1"
},
"param": [
{
"key": "environments",
"value": {
"type": 1,
"string": "debug"
}
}
]
},
"isRequired": true
}
]
___TESTS___
scenarios:
- name: With Variable Name
code: |-
// Call runCode to run the template's code.
runCode(mockData);
// Verify that the tag finished successfully.
assertApi('gtmOnSuccess').wasCalled();
assertThat(calledInWindow).hasLength(1);
assertThat(calledInWindow[0][0]).isEqualTo('fbq');
assertThat(calledInWindow[0][1]).isEqualTo('track');
assertThat(calledInWindow[0][2]).isEqualTo('AddToCart');
assertThat(calledInWindow[0][3]).isEqualTo({content_ids: "Cool"});
assertThat(window[TAG_INFO]).hasLength(1);
assertThat(window[TAG_INFO][0].tagName).isEqualTo('Facebook - Add to Cart');
assertThat(window[TAG_INFO][0].eventId).isEqualTo(13);
assertThat(window[TAG_INFO][0].variables).isEqualTo(['dlv - Product View - SKU']);
- name: With No Variable Name
code: |-
mockData.content[0] = { key: "test", value:"10", variableName: "" };
// Call runCode to run the template's code.
runCode(mockData);
// Verify that the tag finished successfully.
assertApi('gtmOnSuccess').wasCalled();
assertApi('callInWindow').wasCalledWith('fbq', 'track', 'AddToCart', {test: "10"});
assertThat(window[TAG_INFO]).hasLength(1);
assertThat(window[TAG_INFO][0].variables).isEqualTo([]);
- name: With Multiple Mixed
code: |
mockData.content.push(
{ key: "currency", value:"USD", variableName: "" },
{ key: "value", value: 30.00, variableName: "dlv - Product Price" }
);
// Call runCode to run the template's code.
runCode(mockData);
// Verify that the tag finished successfully.
assertApi('gtmOnSuccess').wasCalled();
assertApi('callInWindow').wasCalledWith('fbq', 'track', 'AddToCart', {content_ids: "Cool", currency: 'USD', value: 30.00 });
assertThat(window[TAG_INFO]).hasLength(1);
assertThat(window[TAG_INFO][0].variables).isEqualTo(["dlv - Product View - SKU", "dlv - Product Price"]);
- name: With No Data
code: |-
mockData = {
tagName: "Facebook - Page View",
type: 'track',
event: "PageView",
gtmEventId: 13,
};
// Call runCode to run the template's code.
runCode(mockData);
// Verify that the tag finished successfully.
assertApi('gtmOnSuccess').wasCalled();
assertApi('callInWindow').wasCalledWith('fbq', 'track', 'PageView');
assertThat(window[TAG_INFO]).hasLength(1);
assertThat(window[TAG_INFO][0].variables).isEqualTo([]);
- name: Has Channel
code: |-
// Call runCode to run the template's code.
runCode(mockData);
// Verify that the tag finished successfully.
assertApi('gtmOnSuccess').wasCalled();
assertThat(window[TAG_INFO]).hasLength(1);
assertThat(window[TAG_INFO][0].channel).isEqualTo('facebook');
setup: "const log = require('logToConsole');\n\n// Custom window object used by mock\
\ functions\nlet window = {};\nconst TAG_INFO = 'elevar_gtm_tag_info';\n\n// Mock\
\ data used in template\nlet mockData = {\n tagName: \"Facebook - Add to Cart\"\
,\n type: \"track\",\n event: \"AddToCart\",\n content: [\n { key: \"content_ids\"\
, value: \"Cool\", variableName: \"dlv - Product View - SKU\" },\n ],\n gtmTagId:\
\ 2147483645,\n gtmEventId: 13\n};\n\n/*\nCreates an array in the window with the\
\ key provided and\nreturns a function that pushes items to that array.\n*/\nmock('createQueue',\
\ (key) => {\n const pushToArray = (arr) => (item) => {\n arr.push(item);\n\
\ };\n \n if (!window[key]) window[key] = [];\n return pushToArray(window[key]);\n\
});\n\n/*\ncallInWindow mock function\nsaves data on what function were called and\
\ with what params.\ncallInWindow('fbq', data.type, data.event, contentObj);\n*/\n\
let calledInWindow = [];\nmock('callInWindow', function () {\n const args = arguments;\n\
\ \n // Beware: This does not represent exactly what was called.\n if (args[3])\
\ {\n\tlog(args[0] + \"('\" + args[1] + \"', '\" + args[2] + \"',\", args[3], \"\
)\");\n } else {\n log(args[0] + \"('\" + args[1] + \"', '\" + args[2] + \"\
')\");\n }\n calledInWindow.push(args);\n});"
___NOTES___
Created on 18/02/2020, 18:41:48