-
Notifications
You must be signed in to change notification settings - Fork 2
/
template.tpl
783 lines (719 loc) · 27.1 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
___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": "Leanplum",
"description": "Leanplum Customer Engagement platform for collecting data, messaging and A/B testing across web and mobile.",
"categories": [
"MARKETING",
"EXPERIMENTATION",
"ANALYTICS"
],
"brand": {
"id": "brand_dummy",
"displayName": "Leanplum",
"thumbnail": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAMZGlDQ1BJQ0MgUHJvZmlsZQAASImVlwdYU8kWgOeWVBJaIAJSQm+iSA0gJYQWQUCqICohCSSUGBOCiB1dVsG1iyiW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AAD//9iEm60AAADYSURBVO1T7Q3EIAjFMdzKERzBFbqZK7iB/xzDw/tITpoqlUvaSyAxDa2P8t4DsNZWAJieSoKD+b5D4NPUez/t6Vn/bgRyztU5x2sehTeNQCkFyYwDJesuGGO6fJZQ/LZtO0iMEdo5FVc5gE2yVR7eVQJMJenWDlVl1mw1lndgNqspJQgh4D9eQXfg7A596uyeqyNEFaU5EuxmnH7HRrrvy7kSoNK+89s5sGzxr0blqA53hJTAkYLS9+qAVEEpXh2QKijFqwNSBaV4dUCqoBSvDkgVlOL/3YEHery+DXZnyFkAAAAASUVORK5CYII\u003d"
},
"containerContexts": [
"WEB"
]
}
___TEMPLATE_PARAMETERS___
[
{
"type": "GROUP",
"name": "configuration",
"displayName": "Configuration",
"groupStyle": "ZIPPY_OPEN",
"subParams": [
{
"type": "LABEL",
"name": "helpText",
"displayName": "Get the keys from the \u003cstrong\u003eKeys \u0026 Settings\u003c/strong\u003e popup in your \u003ca href\u003d\"https://www.leanplum.com/dashboard#/account/apps\"\u003eApp Settings page\u003c/a\u003e."
},
{
"type": "TEXT",
"name": "applicationKey",
"displayName": "App ID",
"simpleValueType": true,
"valueValidators": [
{
"type": "REGEX",
"args": [
"^app_..*"
]
},
{
"type": "NON_EMPTY"
}
]
},
{
"type": "TEXT",
"name": "productionKey",
"displayName": "Client secret",
"simpleValueType": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
],
"valueHint": "prod_abcdefgh...",
"help": "Never use a non-production key on live websites."
},
{
"type": "CHECKBOX",
"name": "enableRichInAppMessages",
"checkboxText": "Enable Rich In-App Messages",
"simpleValueType": true,
"help": "If enabled, rich in-app messages will be delivered to web users that match the trigger conditions of your campaigns."
},
{
"type": "GROUP",
"name": "webPush",
"displayName": "Web Push options",
"groupStyle": "NO_ZIPPY",
"subParams": [
{
"type": "TEXT",
"name": "webPushServiceWorkerUrl",
"displayName": "Service Worker URL",
"simpleValueType": true,
"help": "Specify the location of the service worker file on the web server. This allows you to send messages that use the \u0027Register for Push\u0027 app function."
}
]
}
]
},
{
"type": "GROUP",
"name": "fireOptions",
"displayName": "Firing options",
"groupStyle": "ZIPPY_OPEN",
"subParams": [
{
"type": "SELECT",
"name": "method",
"displayName": "Tag Options",
"macrosInSelect": false,
"selectItems": [
{
"value": "load",
"displayValue": "Only load SDK"
},
{
"value": "loadAndStart",
"displayValue": "Load and start session"
},
{
"value": "track",
"displayValue": "Track Event"
},
{
"value": "trackPurchase",
"displayValue": "Track Purchase"
},
{
"value": "setUserAttributes",
"displayValue": "Set User Attributes"
}
],
"simpleValueType": true,
"subParams": []
},
{
"type": "TEXT",
"name": "userId",
"displayName": "User ID",
"simpleValueType": true,
"help": "Leave blank to use previously-stored ID.\nFor new users, a new ID is generated at the start of their first session.",
"enablingConditions": [
{
"paramName": "method",
"paramValue": "load",
"type": "NOT_EQUALS"
}
]
},
{
"type": "GROUP",
"name": "trackOptions",
"displayName": "",
"groupStyle": "NO_ZIPPY",
"subParams": [
{
"type": "TEXT",
"name": "trackEvent",
"displayName": "Event Name",
"simpleValueType": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
}
],
"enablingConditions": [
{
"paramName": "method",
"paramValue": "track",
"type": "EQUALS"
}
]
},
{
"type": "GROUP",
"name": "trackPurchaseOptions",
"displayName": "",
"subParams": [
{
"type": "TEXT",
"name": "trackPurchaseValue",
"displayName": "Value",
"simpleValueType": true,
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
},
{
"type": "TEXT",
"name": "trackPurchaseCurrency",
"displayName": "Currency (optional)",
"simpleValueType": true,
"valueValidators": [
{
"type": "STRING_LENGTH",
"args": [
3,
3
]
}
]
}
],
"enablingConditions": [
{
"paramName": "method",
"paramValue": "trackPurchase",
"type": "EQUALS"
}
],
"groupStyle": "NO_ZIPPY"
},
{
"type": "GROUP",
"name": "setUserAttributesOptions",
"displayName": "",
"groupStyle": "NO_ZIPPY",
"subParams": [],
"enablingConditions": [
{
"paramName": "method",
"paramValue": "setUserAttributes",
"type": "EQUALS"
}
]
},
{
"type": "PARAM_TABLE",
"name": "trackParameters",
"displayName": "Parameters (optional)",
"paramTableColumns": [
{
"param": {
"type": "TEXT",
"name": "parameterName",
"displayName": "Name",
"simpleValueType": true
},
"isUnique": true
},
{
"param": {
"type": "TEXT",
"name": "parameterValue",
"displayName": "Value",
"simpleValueType": true
},
"isUnique": false
}
],
"newRowButtonText": "Add parameter",
"newRowTitle": "Add parameter",
"editRowTitle": "Edit parameter",
"enablingConditions": [
{
"paramName": "method",
"paramValue": "track",
"type": "EQUALS"
},
{
"paramName": "method",
"paramValue": "trackPurchase",
"type": "EQUALS"
}
]
},
{
"type": "PARAM_TABLE",
"name": "userAttributes",
"displayName": "Attributes",
"paramTableColumns": [
{
"param": {
"type": "TEXT",
"name": "parameterName",
"displayName": "Name",
"simpleValueType": true
},
"isUnique": true
},
{
"param": {
"type": "TEXT",
"name": "parameterValue",
"displayName": "Value",
"simpleValueType": true
},
"isUnique": false
}
],
"newRowButtonText": "Add attribute",
"newRowTitle": "Add attribute",
"editRowTitle": "Edit attribute",
"enablingConditions": [
{
"paramName": "method",
"paramValue": "setUserAttributes",
"type": "EQUALS"
}
]
}
]
}
]
___SANDBOXED_JS_FOR_WEB_TEMPLATE___
const injectScript = require('injectScript');
const setInWindow = require('setInWindow');
const callInWindow = require('callInWindow');
const makeNumber = require('makeNumber');
const LP_URL = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/leanplum.min.js';
// command queue
var setKey = data.productionKey.indexOf("dev_") === 0 ?
"setAppIdForDevelopmentMode" : "setAppIdForProductionMode";
var queue = [
{ "name": setKey, "args": [data.applicationKey, data.productionKey] },
{ "name": "useSessionLength", "args": [2*60*60] }
];
if (data.enableRichInAppMessages) {
queue.push(
{ "name": "enableRichInAppMessages", "args": [true] }
);
}
if (data.webPushServiceWorkerUrl) {
queue.push(
{ "name": "setWebPushOptions", "args": [{
serviceWorkerUrl: data.webPushServiceWorkerUrl
}] }
);
}
if (data.method !== "load") {
// start a session
var args = data.userId ? [data.userId] : [];
queue.push(
{ "name": "start", "args": args }
);
}
const parameters = {};
const parametersTable = data.trackParameters || data.userAttributes;
if (parametersTable) {
parametersTable.forEach(parameter => {
parameters[parameter.parameterName] = parameter.parameterValue;
});
}
switch (data.method) {
case "track":
const trackArgs = [data.trackEvent];
if (data.trackParameters) {
trackArgs.push(parameters);
}
queue.push({ "name": "track", "args": trackArgs });
break;
case "trackPurchase":
const trackPurchaseArgs = [makeNumber(data.trackPurchaseValue)];
if (data.trackPurchaseCurrency || data.trackParameters) {
trackPurchaseArgs.push(data.trackPurchaseCurrency || '');
}
if (data.trackParameters) {
trackPurchaseArgs.push(parameters);
}
queue.push({ "name": "trackPurchase", "args": trackPurchaseArgs });
break;
case "setUserAttributes":
queue.push({ "name": "setUserAttributes", "args": [parameters] });
break;
}
// global object stubs
var lp = {};
["setApiPath","setEmail","setNetworkTimeout","setAppIdForDevelopmentMode","setAppIdForProductionMode","setSocketHost","setDeviceId","setLocale","setAppVersion","setDeviceName","setDeviceModel","setRequestBatching","setSystemName","setSystemVersion","setVariables","setVariantDebugInfoEnabled","enableRichInAppMessages","processMessageEvent","getVariantDebugInfo","getVariables","getVariable","getVariants","inbox","addStartResponseHandler","removeStartResponseHandler","addVariablesChangedHandler","removeVariablesChangedHandler","forceContentUpdate","useSessionLength","start","startFromCache","stop","pauseSession","resumeSession","pauseState","resumeState","getUserId","setUserId","setUserAttributes","track","trackPurchase","advanceTo","isWebPushSupported","isWebPushSubscribed","setWebPushOptions","registerForWebPush","unregisterFromWebPush","clearUserContent","defineAction","applyQueue","on","off","getFileUrl"].forEach(function(name) {
lp[name] = function() {
queue.push({ name: name, args: arguments });
};
});
setInWindow("Leanplum", lp, false);
// load script
injectScript(LP_URL, function() {
callInWindow("Leanplum.applyQueue", queue);
data.gtmOnSuccess();
}, data.gtmOnError, LP_URL);
___WEB_PERMISSIONS___
[
{
"instance": {
"key": {
"publicId": "inject_script",
"versionId": "1"
},
"param": [
{
"key": "urls",
"value": {
"type": 2,
"listItem": [
{
"type": 1,
"string": "https://cdn.jsdelivr.net/npm/leanplum-sdk*"
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"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": "Leanplum"
},
{
"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": "Leanplum.applyQueue"
},
{
"type": 8,
"boolean": false
},
{
"type": 8,
"boolean": false
},
{
"type": 8,
"boolean": true
}
]
}
]
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
}
]
___TESTS___
scenarios:
- name: Injects script
code: |-
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "load"
});
assertApi('injectScript').wasCalled();
- name: Can track events
code: |-
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "track",
trackEvent: "Track Test"
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "start", "args": [] },
{ "name": "track", "args": ["Track Test"] }
]);
- name: Can track purchase events
code: |-
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "trackPurchase",
trackPurchaseValue: "42"
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "start", "args": [] },
{ "name": "trackPurchase", "args": [42] }
]);
- name: Can track events with parameters
code: |-
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "track",
trackEvent: "Track Test",
trackParameters: [{"parameterName":"param","parameterValue":"123"}]
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "start", "args": [] },
{ "name": "track", "args": ["Track Test", { "param": "123" }] }
]);
- name: Can track purchase events in different currency
code: |+
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "trackPurchase",
trackPurchaseValue: "42.42",
trackPurchaseCurrency: "BGN"
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "start", "args": [] },
{ "name": "trackPurchase", "args": [42.42, "BGN"] }
]);
- name: Can track purchase events with parameters
code: |+
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "trackPurchase",
trackPurchaseValue: "42.42",
trackPurchaseCurrency: undefined,
trackParameters: [{"parameterName":"param","parameterValue":"123"}]
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "start", "args": [] },
{ "name": "trackPurchase", "args": [42.42, "", { "param": "123" } ] }
]);
- name: Can set user attributes
code: |+
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "setUserAttributes",
trackPurchaseValue: "42.42",
trackPurchaseCurrency: undefined,
userAttributes: [{"parameterName":"param","parameterValue":"123"}]
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "start", "args": [] },
{ "name": "setUserAttributes", "args": [{ "param": "123" } ] }
]);
- name: Can inject SDK without sending events
code: |-
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "load"
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] }
]);
- name: Can enable rich in-app message rendering
code: |-
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "load",
enableRichInAppMessages: true
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "enableRichInAppMessages", "args": [ true ] }
]);
- name: Can use development key
code: |-
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "dev_bar",
method: "load"
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForDevelopmentMode", "args": ["app_foo", "dev_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] }
]);
- name: Can track sessions
code: |-
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "loadAndStart"
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "start", "args": [] }
]);
- name: Can use custom user ID
code: |-
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "loadAndStart",
userId: "from-data-layer"
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "start", "args": ["from-data-layer"] }
]);
- name: Can set Web Push options
code: |-
mock('injectScript', function(url, onSuccess, onFailure) {
onSuccess();
});
runCode({
applicationKey: "app_foo",
productionKey: "prod_bar",
method: "loadAndStart",
webPushServiceWorkerUrl: "/foo/sw.min.js",
userId: "from-data-layer"
});
assertApi('callInWindow').wasCalledWith("Leanplum.applyQueue", [
{ "name": "setAppIdForProductionMode", "args": ["app_foo", "prod_bar"] },
{ "name": "useSessionLength", "args": [2*60*60] },
{ "name": "setWebPushOptions", "args": [{ serviceWorkerUrl: "/foo/sw.min.js" }] },
{ "name": "start", "args": ["from-data-layer"] }
]);
___NOTES___
Created on 5/19/2020, 5:00:41 PM