-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
441 lines (387 loc) · 23.5 KB
/
index.js
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
function log(param){
if(arguments.length>1){
for (let i = 0; i < arguments.length; i++) {
log(arguments[i])
}
}
else{
if (typeof param === 'object') {
console.log("object:",JSON.stringify(param))
} else if (typeof param === 'function') {
console.log('function:', param)
} else {
console.log(String(param))
}
}
}
function setupButtons() {
let variables = {
'cordova_var_string': 'cordova_var_string_value',
'cordova_var_map': {
cordova_var_map_string: 'cordova_var_map_value',
cordova_var_map_float: 10.11,
cordova_var_map_nested:{
cordova_var_map_nested_float:3.14
}
},
'cordova_var_int': 6,
'cordova_var_float': 6.9,
'cordova_var_boolean': true
};
let eventsMap = [
["title","ClientSide InApps"],
["Fetch InApps", () => CleverTap.fetchInApps(success => log("fetchInApps success = " + success))],
["Clear InApp Resources", () => CleverTap.clearInAppResources(false)],
["Clear Expired Only InApp Resources", () => CleverTap.clearInAppResources(true)],
["title","Android 13 Push Primer"],
["promptPushPrimer",()=> CleverTap.promptPushPrimer({
inAppType: 'alert',
titleText: 'Get Notified',
messageText:
'Please enable notifications on your device to use Push Notifications.',
followDeviceOrientation: true,
positiveBtnText: 'Allow',
negativeBtnText: 'Cancel',
backgroundColor: '#FFFFFF',
btnBorderColor: '#FF0000',
titleTextColor: '#0000FF',
messageTextColor: '#000000',
btnTextColor: '#FFFFFF',
btnBackgroundColor: '#0000FF',
btnBorderRadius: '5',
imageUrl:"https://icons.iconarchive.com/icons/treetog/junior/64/camera-icon.png",
fallbackToSettings: true
})
],
["promptForPushPermission",()=> CleverTap.promptForPushPermission(true)],
["isPushPermissionGranted",()=> CleverTap.isPushPermissionGranted(val => log("isPushPermissionGranted value is " + val))],
["title","Product Experiences"],
["defineVariables", () => CleverTap.defineVariables(variables)],
["syncVariables", () => CleverTap.syncVariables()],
["syncVariablesinProd", () => CleverTap.syncVariablesinProd()],
["fetchVariables", () => CleverTap.fetchVariables(success => log("fetchVariables success = " + success))],
["getVariable", () => {
let key = prompt("Please enter key", "cordova_var_string");
CleverTap.getVariable(key,val => log(key+" value is "+JSON.stringify(val)));
}
],
["getVariables", () => {
CleverTap.getVariables(val => log("getVariables value is "+val.cordova_var_map.cordova_var_map_nested.cordova_var_map_nested_float));
}
],
["onVariablesChanged", () => {
CleverTap.onVariablesChanged(val => log("onVariablesChanged value is "+JSON.stringify(val)));
}
],
["onValueChanged", () => {
let key = prompt("Please enter key", "cordova_var_string");
CleverTap.onValueChanged(key,val => log("onValueChanged value is "+JSON.stringify(val)));
}
],
["title","Events"],
["record Event With Name", () => CleverTap.recordEventWithName("foo")],
["set Locale", () => CleverTap.setLocale("en_IN")],
["record Event With NameAndProps", () => CleverTap.recordEventWithNameAndProps("boo", {"bar": "zoo"})],
["record Charged Event With Details And Items", () => CleverTap.recordChargedEventWithDetailsAndItems({
"amount": 300,
"Charged ID": 1234
}, [{"Category": "Books", "Quantity": 1, "Title": "Book Title"}])],
["recordScreenView", () => CleverTap.recordScreenView("HomeView")],
["title","User Profile"],
["profile Set", () => CleverTap.profileSet({"Identity": 20701, "DOB": "1951-10-15", "custom": 1.3})],
["profile SetMultiValues", () => CleverTap.profileSetMultiValues("multiValue", ["one", "two", "three", "four"])],
["profile getLocation/setLocation", () => CleverTap.getLocation(loc => {
log("CleverTapLocation is " + loc.lat + loc.lon)
CleverTap.setLocation(loc.lat, loc.lon)
}, error => log("CleverTapLocation error is " + error))],
["profile GetProperty - DOB", () => CleverTap.profileGetProperty("DOB", val => log("DOB profile value is " + val))],
["profile GetProperty - Identity", () => CleverTap.profileGetProperty("Identity", val => log("Identity profile value is " + val))],
["profile GetProperty - custom", () => CleverTap.profileGetProperty("custom", val => log("custom profile value is " + val))],
["profile onUserLogin", () => CleverTap.onUserLogin({"Identity": 20700, "custom": 1.3})],
["profile Add MultiValue", () => CleverTap.profileAddMultiValue("multiValue", "five")],
["profile Remove MultiValues", () => CleverTap.profileRemoveMultiValues("multiValue", ["one", "two"])],
["profile Remove MultiValuE", () => CleverTap.profileRemoveMultiValue("multiValue", "three")],
["profile Remove Value For Key", () => CleverTap.profileRemoveValueForKey("custom")],
["profile GetProperty (multivalue)", () => CleverTap.profileGetProperty("multiValue", val => log("multiValue profile value is " + val))],
["profile Increment ValueBy", () => CleverTap.profileIncrementValueBy("Score", 1)],
["profile Increment ValueBy(2)", () => CleverTap.profileIncrementValueBy("Score", 2)],
["profile Decrement ValueBy", () => CleverTap.profileDecrementValueBy("pageview", 1)],
["profile getString", () => CleverTap.getString("test", val => log("Value is " + val))],
["profile getBoolean", () => CleverTap.getBoolean("test", val => log("Value is " + val))],
["profile getLong", () => CleverTap.getLong("test", val => log("Value is " + val))],
["profile getDouble", () => CleverTap.getDouble("test", val => log("Value is " + val))],
["title","In App"],
["suspend InApp Notifications", () => CleverTap.suspendInAppNotifications()],
["resume InApp Notifications", () => CleverTap.resumeInAppNotifications()],
["discard InApp Notifications", () => CleverTap.discardInAppNotifications()],
["create notification channel GSTTesting", ()=> CleverTap.createNotificationChannel("GSTTesting", "GSTTesting", "", 5, true)],
["create notification channel BRTesting", ()=> CleverTap.createNotificationChannel("BRTesting", "Core", "", 5, true)],
["create notification channel PTTesting", ()=> CleverTap.createNotificationChannel("PTTesting", "Push templates", "", 5, true)],
["Send Basic Push", () => CleverTap.recordEventWithName("Send Basic Push")],
["Send Carousel Push", () => CleverTap.recordEventWithName("Send Carousel Push")],
["Send Manual Carousel Pus", () => CleverTap.recordEventWithName("Send Manual Carousel Pus")],
["Send Filmstrip Carousel Push", () => CleverTap.recordEventWithName("Send Filmstrip Carousel Push")],
["Send Rating Push", () => CleverTap.recordEventWithName("Send Rating Push")],
["Send Product Display Notification", () => CleverTap.recordEventWithName("Send Product Display Notification")],
["Send Linear Product Display Push", () => CleverTap.recordEventWithName("Send Linear Product Display Push")],
["Send CTA Notification", () => CleverTap.recordEventWithName("Send CTA Notification")],
["Send Zero Bezel Notification", () => CleverTap.recordEventWithName("Send Zero Bezel Notification")],
["Send Zero Bezel Text Only Notification", () => CleverTap.recordEventWithName("Send Zero Bezel Text Only Notification")],
["Send Timer Notification", () => CleverTap.recordEventWithName("Send Timer Notification")],
["Send Input Box Notification", () => CleverTap.recordEventWithName("Send Input Box Notification")],
["Send Input Box Reply with Event Notification", () => CleverTap.recordEventWithName("Send Input Box Reply with Event Notification")],
["Send Input Box Reply with Auto Open Notification", () => CleverTap.recordEventWithName("Send Input Box Reply with Auto Open Notification")],
["Send Input Box Remind Notification DOC FALSE", () => CleverTap.recordEventWithName("Send Input Box Remind Notification DOC FALSE")],
["Send Input Box CTA DOC true", () => CleverTap.recordEventWithName("Send Input Box CTA DOC true")],
["Send Input Box CTA DOC false", () => CleverTap.recordEventWithName("Send Input Box CTA DOC false")],
["Send Input Box Reminder DOC true", () => CleverTap.recordEventWithName("Send Input Box Reminder DOC true")],
["Send Input Box Reminder DOC false", () => CleverTap.recordEventWithName("Send Input Box Reminder DOC false")],
["Send Input Box Reminder DOC false", () => CleverTap.recordEventWithName("Send Input Box Reminder DOC false")],
["title","productConfig"],
["productConfig fetch", () => CleverTap.fetch()],
["productConfig fetchWithMinimumInterval", () => CleverTap.fetchWithMinimumFetchIntervalInSeconds(100)],
["productConfig activate", () => CleverTap.activate()],
["productConfig fetchAndActivate", () => CleverTap.fetchAndActivate()],
["productConfig reset", () => CleverTap.reset()],
["productConfig setMinimumFetchInterval", () => CleverTap.setMinimumFetchIntervalInSeconds(100)],
["productConfig getLastFetchTimeStamp", () => CleverTap.getLastFetchTimeStampInMillis(val => log("Value is " + val))],
["title","inbox"],
["initialize Inbox", () => CleverTap.initializeInbox()],
["title","Feature flag"],
["get Feature Flag", () => CleverTap.getFeatureFlag("test", true, val => log("Value is " + val))],
["title","Device Identifiers"],
["get CleverTap ID", () => CleverTap.getCleverTapID(val => log("getCleverTapID is " + val))],
["title","special functions for cordova sdk"],
["Push tokens manually", () => {
CleverTap.setPushToken("foo")
CleverTap.setPushXiaomiToken("foo","in")
CleverTap.setPushBaiduToken("foo")
CleverTap.setPushHuaweiToken("foo")
}],
["set Debug Level", () => CleverTap.setDebugLevel(3)],
["notify Device Ready", () => CleverTap.notifyDeviceReady()],
["register Push", () => CleverTap.registerPush()],
["pushInstallReferrer", () => CleverTap.pushInstallReferrer("source", "medium", "campaign")],
["event GetFirstTime - foo", () => CleverTap.eventGetFirstTime("foo", time => log("foo event first time is " + time))],
["event GetFirstTime - noevent", () => CleverTap.eventGetFirstTime("noevent", time => log("noevent event first time is " + time))],
["event GetLastTime - App Launched", () => CleverTap.eventGetLastTime("App Launched", time => log("app launched last time is " + time))],
["event GetLastTime - noevent", () => CleverTap.eventGetLastTime("noevent", time => log("noevent last time is " + time))],
["event GetOccurrences foo", () => CleverTap.eventGetOccurrences("foo", num => log("foo event occurrences " + num))],
["event GetDetails - Charged", () => CleverTap.eventGetDetails("Charged", res => log(res))],
["getEventHistory", () => CleverTap.getEventHistory(history => log(history))],
["event GetOccurrences noevent", () => CleverTap.eventGetOccurrences("noevent", num => log("noevent occurrences " + num))],
["event GetDetails - noevent", () => CleverTap.eventGetDetails("noevent", res => log(res))],
["session GetTimeElapsed", () => CleverTap.sessionGetTimeElapsed(val => log("session elapsed time is " + val))],
["session GetTotalVisits", () => CleverTap.sessionGetTotalVisits(val => log("session total visits is " + val))],
["session GetScreenCount", () => CleverTap.sessionGetScreenCount(val => log("session screen count is " + val))],
["session GetPreviousVisitTime", () => CleverTap.sessionGetPreviousVisitTime(val => log("session previous visit time is " + val))],
["session GetUTMDetails", () => CleverTap.sessionGetUTMDetails(val => log(val))],
["enable Personalization", () => CleverTap.enablePersonalization()],
["disable Personalization", () => CleverTap.disablePersonalization()],
["set Defaults Map", () => CleverTap.setDefaultsMap({"test": "val1", "test1": "val2"})],
["Run All Actions", () => {
CleverTap.setDebugLevel(3)
CleverTap.notifyDeviceReady()
CleverTap.registerPush()
CleverTap.enablePersonalization()
CleverTap.disablePersonalization()
CleverTap.recordScreenView("HomeView")
CleverTap.pushInstallReferrer("source", "medium", "campaign")
CleverTap.onUserLogin({"Identity": 20500, "custom": 1.3})
CleverTap.profileSet({"Identity": 20501, "DOB": "1950-10-15", "custom": 1.3})
CleverTap.profileSetMultiValues("multiValue", ["one", "two", "three", "four"])
CleverTap.getLocation(
loc => {
log("CleverTapLocation is " + loc.lat + loc.lon)
CleverTap.setLocation(loc.lat, loc.lon)
},
error => log("CleverTapLocation error is " + error)
)
CleverTap.recordEventWithName("foo")
CleverTap.recordEventWithNameAndProps("boo", {"bar": "zoo"})
CleverTap.recordChargedEventWithDetailsAndItems({"amount": 300, "Charged ID": 1234}, [{
"Category": "Books",
"Quantity": 1,
"Title": "Book Title"
}])
CleverTap.eventGetFirstTime("foo", time => log("foo event first time is " + time))
CleverTap.eventGetLastTime("App Launched", time => log("app launched last time is " + time))
CleverTap.eventGetOccurrences("foo", num => log("foo event occurrences " + num))
CleverTap.eventGetDetails("Charged", res => log(res))
CleverTap.getEventHistory(history => log(history))
CleverTap.eventGetFirstTime("noevent", time => log("noevent event first time is " + time))
CleverTap.eventGetLastTime("noevent", time => log("noevent last time is " + time))
CleverTap.eventGetOccurrences("noevent", num => log("noevent occurrences " + num))
CleverTap.eventGetDetails("noevent", res => log(res))
CleverTap.profileGetProperty("DOB", val => log("DOB profile value is " + val))
CleverTap.profileGetProperty("Identity", val => log("Identity profile value is " + val))
CleverTap.profileGetProperty("custom", val => log("custom profile value is " + val))
CleverTap.sessionGetTimeElapsed(val => log("session elapsed time is " + val))
CleverTap.sessionGetTotalVisits(val => log("session total visits is " + val))
CleverTap.sessionGetScreenCount(val => log("session screen count is " + val))
CleverTap.sessionGetPreviousVisitTime(val => log("session previous visit time is " + val))
CleverTap.sessionGetUTMDetails(val => log(val))
//CleverTap.profileGetCleverTapID(function(val) {log("CleverTapID is "+val)})
//CleverTap.profileGetCleverTapAttributionIdentifier(function(val) {log("CleverTapAttributionIdentifier is "+val)})
CleverTap.getCleverTapID(val => log("getCleverTapID is " + val))
CleverTap.profileAddMultiValue("multiValue", "five")
CleverTap.profileRemoveMultiValues("multiValue", ["one", "two"])
CleverTap.profileRemoveMultiValue("multiValue", "three")
CleverTap.profileRemoveValueForKey("custom")
CleverTap.profileGetProperty("multiValue", val => log("multiValue profile value is " + val))
CleverTap.profileIncrementValueBy("Score", 1)
CleverTap.getFeatureFlag("test", true, val => log("Value is " + val))
CleverTap.setDefaultsMap({"test": "val1", "test1": "val2"})
CleverTap.fetch()
CleverTap.fetchWithMinimumFetchIntervalInSeconds(100)
CleverTap.activate()
CleverTap.fetchAndActivate()
CleverTap.setMinimumFetchIntervalInSeconds(100)
CleverTap.getLastFetchTimeStampInMillis(val => log("Value is " + val))
CleverTap.getString("test", val => log("Value is " + val))
CleverTap.getBoolean("test", val => log("Value is " + val))
CleverTap.getLong("test", val => log("Value is " + val))
CleverTap.getDouble("test", val => log("Value is " + val))
CleverTap.profileIncrementValueBy("Score", 1)
CleverTap.profileDecrementValueBy("pageview", 1)
CleverTap.suspendInAppNotifications()
CleverTap.resumeInAppNotifications()
CleverTap.discardInAppNotifications()
CleverTap.reset()
/* CleverTap.recordDisplayUnitViewedEventForID("unitID")
CleverTap.recordDisplayUnitClickedEventForID("unitID")*/
//FOR NOTIFICATION INBOX
CleverTap.initializeInbox()
}],
]
for (let element of eventsMap) {
const buttonElement = element[0]==="title"? document.createElement("p") : document.createElement("button")
buttonElement.innerText = element[0]==="title" ? element[1]:element[0]
const buttonOnClick = element[0]==="title" ? ()=>{} : element[1]
buttonElement.addEventListener('click',buttonOnClick)
document.querySelector('.ct_button').appendChild(buttonElement)
}
// onCleverTapProfileSync Event Handler
// CleverTap provides a mechanism for notifying your application about synchronization-related changes to the User Profile/Event History.
// You can subscribe to these notifications by listening for the onCleverTapProfile Sync event,
// i.e. document.addEventListener('onCleverTapProfileSync', this.onCleverTapProfileSync, false)
// the updates property of the onCleverTapProfileSync event represents the changed data and is of the form:
// {
// "profile":{"<property1>":{"oldValue":<value>, "newValue":<value>}, ...},
// "events:{"<eventName>":
// {"count":
// {"oldValue":(int)<old count>, "newValue":<new count>},
// "firstTime":
// {"oldValue":(double)<old first time event occurred>, "newValue":<new first time event occurred>},
// "lastTime":
// {"oldValue":(double)<old last time event occurred>, "newValue":<new last time event occurred>},
// }, ...
// }
// }
//
//
}
function initLogging() {
log('Running cordova-' + cordova.platformId + '@' + cordova.version)
CleverTap.setDebugLevel(3)
}
function initListeners() {
log("setting listeners")
document.addEventListener('onCleverTapProfileSync', e => log(e.updates))
document.addEventListener('onCleverTapProfileDidInitialize', e => log(e.CleverTapID))
document.addEventListener('onCleverTapInAppNotificationDismissed', e => {
log("onCleverTapInAppNotificationDismissed")
log(e.extras)
log(e.actionExtras)
}
)
// deeplink handler
document.addEventListener('onDeepLink', e => log(e.deeplink))
//push notification handler
document.addEventListener('onPushNotification', e => log(e.notification))
document.addEventListener('onCleverTapInboxDidInitialize', () => {
CleverTap.getInboxMessageForId("1642753141_1642755745", val => log("Inbox message is " + JSON.stringify(val)))
CleverTap.showInbox({"navBarTitle": "My App Inbox", "tabs": ["tag1", "tag2"], "navBarColor": "#FF0000"})
CleverTap.getAllInboxMessages(val => log("Inbox messages are " + val))
CleverTap.getUnreadInboxMessages(val => log("Unread Inbox messages are " + val))
CleverTap.deleteInboxMessageForId("messageId")
CleverTap.deleteInboxMessagesForIds(["id1", "id2"])
CleverTap.markReadInboxMessageForId("messageId")
CleverTap.markReadInboxMessagesForIds(["id1", "id2"])
CleverTap.pushInboxNotificationViewedEventForId("messageId")
CleverTap.pushInboxNotificationClickedEventForId("messageId")
CleverTap.dismissInbox()
}
)
document.addEventListener('onCleverTapInboxMessagesDidUpdate', () => {
CleverTap.getInboxMessageUnreadCount(val => log("Inbox unread message count" + val))
CleverTap.getInboxMessageCount(val => log("Inbox read message count" + val))
}
)
document.addEventListener('onCleverTapInboxButtonClick', e => {
log("onCleverTapInboxButtonClick")
log(e.customExtras)
}
)
document.addEventListener('onCleverTapInboxItemClick', e => {
log("onCleverTapInboxItemClick")
log(JSON.stringify(e))
}
)
document.addEventListener('onCleverTapInAppButtonClick', e => {
log("onCleverTapInAppButtonClick")
log(e.customExtras)
}
)
document.addEventListener('onCleverTapFeatureFlagsDidUpdate', () => log("onCleverTapFeatureFlagsDidUpdate"))
document.addEventListener('onCleverTapProductConfigDidInitialize', () => log("onCleverTapProductConfigDidInitialize"))
document.addEventListener('onCleverTapProductConfigDidFetch', () => log("onCleverTapProductConfigDidFetch"))
document.addEventListener('onCleverTapProductConfigDidActivate', () => log("onCleverTapProductConfigDidActivate"))
document.addEventListener('onCleverTapExperimentsUpdated', () => log("onCleverTapExperimentsUpdated"))
document.addEventListener('onCleverTapDisplayUnitsLoaded', e => {
log("onCleverTapDisplayUnitsLoaded")
log(e.units)
CleverTap.getDisplayUnitForId("1642753742_20220131", val => log("Native Display unit is " + JSON.stringify(val)))
CleverTap.getAllDisplayUnits(val => log("Native Display units are " + JSON.stringify(val)))
}
)
document.addEventListener('onCleverTapPushNotificationTappedWithCustomExtras', e => {
log("onCleverTapPushNotificationTappedWithCustomExtras")
log(e.customExtras)
}
)
document.addEventListener('onCleverTapPushAmpPayloadDidReceived', e => {
log("onCleverTapPushAmpPayloadDidReceived")
log(e.customExtras)
}
)
document.addEventListener('onCleverTapPushPermissionResponseReceived', e => {
log("onCleverTapPushPermissionResponseReceived")
log(e.accepted)
})
document.addEventListener('onCleverTapInAppNotificationShow', e => {
log("onCleverTapInAppNotificationShow")
log(e.customExtras)
})
}
function updateUi() {
document.getElementById('deviceready').classList.add('ready')
let parentElement = document.getElementById("deviceready")
let listeningElement = parentElement.querySelector('.listening')
let receivedElement = parentElement.querySelector('.received')
listeningElement.setAttribute('style', 'display:none')
receivedElement.setAttribute('style', 'display:block')
}
initListeners()
document.addEventListener(
'deviceready',
param => {
log("on device ready, received param:", param)
initLogging()
setupButtons()
updateUi()
},
false
)
//TEST-R78-ZZK-955Z TEST-311-ba2
// following tag combination gives a very clean log stream under logcat(make sure to check regex) : chromium|CleverTap