-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.tpl
622 lines (572 loc) · 19.3 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
___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": [],
"categories": ["CHAT", "SOCIAL"],
"displayName": "Intercom",
"brand": {
"id": "brand_dummy",
"displayName": "Addingwell",
"thumbnail": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPUAAAD1CAYAAACIsbNlAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAmaSURBVHgB7d1NchvHGcbxh7GrsrSUC3iYA9h0DhCCziKpysLKNgtzkgPIvgGhXMDyCUhdIJGW2YjQLitH8gGE0c4ri156Q7rf6pkCTHwDPYOeF/9f1VuQiCliCMyD7pnp6ZEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFjmSIetCHUS6kH9b/TT+1DvQt2Eel0/HqxDC7WFdxDqvH58IHg0CvU81ItQleCShfdC8Rv9jjqouhS9MHcGocbq14ZIpa1bxS91OGAfZB82Oqqbeita7V67VL82OKqbItg99Y36taFR3RbB7pkL9WsDo/ZTFmyXZz8+kC+F4qkMYJWHoX4b6r9yxtt56rHoVmF91mJ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yoc5UqX5sNPfrWvFIr52P7XMr3qy77Wo0Xeu+BNllqJlNdH8GmkxuaKeVRnV9r8n5YnOnfDRfPM158VPFc+ZtjirDhgh1HiwQj+pqWLArxQEgzSCQebOypAz9vN5CoRjcj0N9Wv+be09njFDnqwnPo3s/rzQZ5fVOk3mx391bZh2FJgNWPqr/3zw2hZ4h1P1TiLBhCSYeBJwh1IAzHkK9yZS+wCKVnPAQ6krAbuwMwhs54SHUzdFfYBduenxe9qk3vbMDMK0K9UpOeAn1cwHbG8kRTxcVXGv+PaWBZWx/2uYSr+SEp1NaTwRsznp5lRzxdvmfXWlzJmA97lpp423wid1S9r2A1SzQ1rur5MwH8sVOb/0c6i8Clvt/qL/LIW+hNv9T3K0YCJhvHOqvcnrTeo+hNiPFYJ+Kif/wa3a3kT/J8YAlr6E2o1A/hfqzCDbiPrQd6bYW+geh12zurOZeVDnPkUW1U80N77u+jQ86UCp2vQj3YYX5Qgc2f9ohdkttiqAy1B/FXFse2cEv62bbWO4XcnowbJlD39dsZsXc9a6R2K/mSj2u2AMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIBO/AH09aFEvKovxAAAAAElFTkSuQmCC"
},
"description": "Non official tag to create/update user or company. You can also send data event attached to a user.",
"containerContexts": [
"SERVER"
]
}
___TEMPLATE_PARAMETERS___
[
{
"type": "TEXT",
"name": "accessToken",
"displayName": "Access Token",
"simpleValueType": true
},
{
"type": "RADIO",
"name": "actionType",
"displayName": "Action",
"radioItems": [
{
"value": "upsert_company",
"displayValue": "Create or update Company"
},
{
"value": "upsert_user",
"displayValue": "Create or update User"
},
{
"value": "submit_event",
"displayValue": "Submit data event"
}
],
"simpleValueType": true
},
{
"type": "GROUP",
"name": "upsertCompanyGroup",
"displayName": "Company Fields",
"groupStyle": "ZIPPY_OPEN",
"subParams": [
{
"type": "TEXT",
"name": "companyId",
"displayName": "Company Id",
"simpleValueType": true,
"help": "The company id you have defined for the company"
},
{
"type": "TEXT",
"name": "companyName",
"displayName": "Name",
"simpleValueType": true
},
{
"type": "TEXT",
"name": "companyRemoteCreatedAt",
"displayName": "Remote Created At",
"simpleValueType": true,
"help": "The time the company was created by you"
},
{
"type": "TEXT",
"name": "companyMonthlySpend",
"displayName": "Monthly Spend",
"simpleValueType": true,
"help": "How much revenue the company generates for your business. Note that this will truncate floats. i.e. it only allow for whole integers, 155.98 will be truncated to 155. Note that this has an upper limit of 2**31-1 or 2147483647."
},
{
"type": "TEXT",
"name": "companyPlan",
"displayName": "Plan",
"simpleValueType": true,
"help": "The name of the plan you have associated with the company"
},
{
"type": "TEXT",
"name": "companySize",
"displayName": "Size",
"simpleValueType": true,
"help": "The number of employees in this company"
},
{
"type": "TEXT",
"name": "companyWebsite",
"displayName": "Website",
"simpleValueType": true,
"help": "The URL for this company\u0027s website. Please note that the value specified here is not validated. Accepts any string."
},
{
"type": "TEXT",
"name": "companyIndustry",
"displayName": "Industry",
"simpleValueType": true,
"help": "The industry that this company operates in"
}
],
"enablingConditions": [
{
"paramName": "actionType",
"paramValue": "upsert_company",
"type": "EQUALS"
}
]
},
{
"type": "GROUP",
"name": "upsertUserGroup",
"displayName": "User Fields",
"groupStyle": "ZIPPY_OPEN",
"subParams": [
{
"type": "TEXT",
"name": "userId",
"displayName": "User Id",
"simpleValueType": true,
"help": "A unique string identifier for the user. It is required on creation if an email is not supplied."
},
{
"type": "TEXT",
"name": "userEmail",
"displayName": "Email",
"simpleValueType": true,
"help": "The user\u0027s email address. It is required on creation if a user_id is not supplied."
},
{
"type": "TEXT",
"name": "userName",
"displayName": "Name",
"simpleValueType": true
},
{
"type": "TEXT",
"name": "userPhone",
"displayName": "Phone",
"simpleValueType": true
},
{
"type": "TEXT",
"name": "userSignedUpAt",
"displayName": "Signed Up At",
"simpleValueType": true,
"help": "A UNIX Timestamp (in timestamp) representing the time the user signed up."
},
{
"type": "TEXT",
"name": "userLastRequestAt",
"displayName": "Last Request At",
"simpleValueType": true,
"help": "A UNIX timestamp (in seconds) representing the date the user last visited your application."
},
{
"type": "TEXT",
"name": "unsubscribedFromEmails",
"displayName": "Unsubscribed From Emails",
"simpleValueType": true,
"help": "\"True\" or \"false\" value"
},
{
"type": "TEXT",
"name": "updateLastRequestAt",
"displayName": "Update Last Request At",
"simpleValueType": true,
"help": "A \"true\" or \"false\" value, which if true, instructs Intercom to update the users\u0027 last_request_at value to the current API service time in UTC. default value if not sent is false."
},
{
"type": "TEXT",
"name": "newSession",
"displayName": "New Session",
"simpleValueType": true,
"help": "A \"true\" or \"false\" value, which if true, instructs Intercom to register the request as a session."
}
],
"enablingConditions": [
{
"paramName": "actionType",
"paramValue": "upsert_user",
"type": "EQUALS"
}
]
},
{
"type": "GROUP",
"name": "submitEventGroup",
"displayName": "Submit Event Fields",
"groupStyle": "ZIPPY_OPEN",
"subParams": [
{
"type": "TEXT",
"name": "seEventName",
"displayName": "Event Name",
"simpleValueType": true,
"help": "The name of the event that occurred. This is presented to your App\u0027s admins when filtering and creating segments - a good event name is typically a past tense \u0027verb-noun\u0027 combination, to improve readability, for example updated-plan."
},
{
"type": "TEXT",
"name": "seCreatedAt",
"displayName": "Created At",
"simpleValueType": true,
"help": "The time the event occurred as a UTC Unix timestamp (in seconds)"
},
{
"type": "TEXT",
"name": "seUserId",
"displayName": "User ID",
"simpleValueType": true,
"help": "Your identifier for the user."
},
{
"type": "TEXT",
"name": "seEmail",
"displayName": "Email",
"simpleValueType": true,
"help": "An email address for your user. An email should only be used where your application uses email to uniquely identify users."
}
],
"enablingConditions": [
{
"paramName": "actionType",
"paramValue": "submit_event",
"type": "EQUALS"
}
]
},
{
"type": "GROUP",
"name": "customAttributesGroup",
"displayName": "Custom attributes",
"groupStyle": "ZIPPY_CLOSED",
"subParams": [
{
"type": "LABEL",
"name": "label1",
"displayName": "This group allows you to send any information you wish as custom attributes."
},
{
"type": "LABEL",
"name": "label2",
"displayName": "You can send dates as custom attributes by sending a unix timestamp as a Number. If the name of your custom attribute ends with _at then it\u0027ll automatically treat it as a date, rather than a number."
},
{
"type": "SIMPLE_TABLE",
"name": "customAttributes",
"displayName": "",
"simpleTableColumns": [
{
"defaultValue": "",
"displayName": "Field",
"name": "field",
"type": "TEXT",
"isUnique": true,
"valueValidators": []
},
{
"defaultValue": "string",
"displayName": "Type",
"name": "type",
"type": "SELECT",
"selectItems": [
{
"value": "text",
"displayValue": "Text"
},
{
"value": "number",
"displayValue": "Number"
},
{
"value": "boolean",
"displayValue": "Boolean"
}
],
"macrosInSelect": false,
"valueValidators": []
},
{
"defaultValue": "",
"displayName": "Value",
"name": "value",
"type": "TEXT"
}
]
}
],
"enablingConditions": [
{
"paramName": "actionType",
"paramValue": "upsert_company",
"type": "EQUALS"
},
{
"paramName": "actionType",
"paramValue": "upsert_user",
"type": "EQUALS"
}
]
},
{
"type": "GROUP",
"name": "seMetaDataGroup",
"displayName": "Meta Data",
"groupStyle": "ZIPPY_CLOSED",
"subParams": [
{
"type": "LABEL",
"name": "seLabel1",
"displayName": "Metadata can be used to submit an event with extra key value data. Each event can contain up to ten metadata key values."
},
{
"type": "LABEL",
"name": "seLabel2",
"displayName": "You can send dates as metadata by sending a unix timestamp as a Number. The key musts ends with the String _date and the value is a Unix timestamp, assumed to be in the UTC timezone."
},
{
"type": "SIMPLE_TABLE",
"name": "seMetaData",
"displayName": "",
"simpleTableColumns": [
{
"defaultValue": "",
"displayName": "Field",
"name": "field",
"type": "TEXT",
"isUnique": true,
"valueValidators": []
},
{
"defaultValue": "string",
"displayName": "Type",
"name": "type",
"type": "SELECT",
"selectItems": [
{
"value": "text",
"displayValue": "Text"
},
{
"value": "number",
"displayValue": "Number"
},
{
"value": "boolean",
"displayValue": "Boolean"
}
],
"macrosInSelect": false,
"valueValidators": []
},
{
"defaultValue": "",
"displayName": "Value",
"name": "value",
"type": "TEXT"
}
]
}
],
"enablingConditions": [
{
"paramName": "actionType",
"paramValue": "submit_event",
"type": "EQUALS"
}
]
}
]
___SANDBOXED_JS_FOR_SERVER___
const sendHttpRequest = require('sendHttpRequest');
const makeNumber = require('makeNumber');
const makeString = require('makeString');
const JSON = require('JSON');
const logToConsole = require('logToConsole');
const getContainerVersion = require('getContainerVersion');
const containerVersion = getContainerVersion();
const isDebug = containerVersion.debugMode;
function parseType (type, value) {
switch (type) {
case 'text':
return makeString(value);
case 'number':
return makeNumber(value);
case 'boolean':
case 'bool':
const lowerCaseValue = value.toLowerCase();
return lowerCaseValue === "true" || lowerCaseValue === "yes" || lowerCaseValue === "1";
}
return value;
}
function addParamsToBody(body, existingFields, data) {
for (let i = 0; i < existingFields.length; i++) {
const dataFieldName = existingFields[i][0];
const intercomFieldName = existingFields[i][1];
const intercomFieldType = existingFields[i][2];
if (data[dataFieldName]) {
body[intercomFieldName] = parseType(intercomFieldType, data[dataFieldName]);
}
}
}
function formatCustomAttributes(customAttributes) {
const res = {};
if (!customAttributes) {
return res;
}
for (let i = 0; i < customAttributes.length; i++) {
const fieldName = customAttributes[i].field;
const fieldType = customAttributes[i].type;
const value = customAttributes[i].value;
res[fieldName] = parseType(fieldType, value);
}
return res;
}
let path;
const bodyData = {};
switch (data.actionType) {
case 'upsert_company':
path = '/companies';
if (!data.companyId) {
if (isDebug) {
logToConsole('Company Id is required');
}
data.gtmOnFailure();
return;
}
const companyFields = [
['companyId', 'company_id'],
['companyName', 'name'],
['companyRemoteCreatedAt', 'remote_created_at', 'number'],
['companyMonthlySpend', 'monthly_spend', 'number'],
['companyPlan', 'plan'],
['companySize', 'size', 'number'],
['companyWebsite', 'website'],
['companyIndustry', 'industry'],
];
addParamsToBody(bodyData, companyFields, data);
bodyData.custom_attributes = formatCustomAttributes(data.customAttributes);
break;
case 'upsert_user':
path = '/users';
const userFields = [
['userId', 'user_id'],
['userName', 'name'],
['userPhone', 'phone'],
['userSignedUpAt', 'signed_up_at', 'number'],
['userLastRequestAt', 'last_request_at', 'number'],
['unsubscribedFromEmails', 'unsubscribed_from_emails', 'boolean'],
['updateLastRequestAt', 'update_last_request_at', 'boolean'],
['newSession', 'new_session', 'boolean'],
];
addParamsToBody(bodyData, userFields, data);
bodyData.custom_attributes = formatCustomAttributes(data.customAttributes);
break;
case 'submit_event':
path = '/events';
const eventFields = [
['seEventName', 'event_name'],
['seCreatedAt', 'created_at', 'number'],
['seUserId', 'user_id'],
['seEmail', 'email'],
];
addParamsToBody(bodyData, eventFields, data);
bodyData.metadata = formatCustomAttributes(data.seMetaData);
break;
default:
if (isDebug) {
logToConsole('Invalid Type');
}
data.gtmOnFailure();
return;
}
if (isDebug) {
logToConsole(path, bodyData);
}
sendHttpRequest('https://api.intercom.io' + path, (statusCode, headers, body) => {
if (statusCode >= 200 && statusCode < 300) {
data.gtmOnSuccess();
} else {
if (isDebug) {
}
data.gtmOnFailure();
}
}, {
headers: { 'Authorization': 'Bearer ' + data.accessToken, 'Intercom-Version': '1.4', 'Accept': 'application/json', 'Content-Type': 'application/json' },
method: 'POST',
timeout: 3500
}, JSON.stringify(bodyData));
___SERVER_PERMISSIONS___
[
{
"instance": {
"key": {
"publicId": "logging",
"versionId": "1"
},
"param": [
{
"key": "environments",
"value": {
"type": 1,
"string": "debug"
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "read_container_data",
"versionId": "1"
},
"param": []
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "send_http",
"versionId": "1"
},
"param": [
{
"key": "allowedUrls",
"value": {
"type": 1,
"string": "specific"
}
},
{
"key": "urls",
"value": {
"type": 2,
"listItem": [
{
"type": 1,
"string": "https://api.intercom.io/*"
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
}
]
___TESTS___
scenarios: []
___NOTES___
Created on 12/3/2021, 10:58:49 AM