This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathindex.html
879 lines (803 loc) · 40.1 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/1.11.8/semantic.min.css" />
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/stacktrace.js/2.0.0/stacktrace.min.js"></script>
<style type="text/css">
button {
margin-top: 20px !important;
margin-bottom: 20px !important;
}
</style>
<title>Countly Cordova Demo App</title>
</head>
<body onload="onBodyLoad()">
<div class="app">
<h1 class="ui center aligned header">Countly Cordova Demo App</h1>
<img class="ui centered medium image" src="http://try.count.ly/images/dashboard/countly_logo.svg">
<button onclick="app.start()" class="fluid ui green button">Start</button>
<button onclick="app.stop()" class="fluid ui red button">Stop</button>
<button onclick="app.halt()" class="fluid ui red button">Halt</button>
<!-- <button onclick="app.manualSessionHandling()" class="fluid ui CornflowerBlue button">Manual Session Handling</button>
<button onclick="app.updateSessionPeriod()" class="fluid ui CornflowerBlue button">Update Session Period</button>
<button onclick="app.eventSendThreshold()" class="fluid ui CornflowerBlue button">Event Send Threshold</button>
<button onclick="app.storedRequestsLimit()" class="fluid ui CornflowerBlue button">Stored Requests Limit</button> -->
<div class="ui horizontal divider">Events Start</div>
<button onclick="app.basicEvent()" class="fluid ui button">Basic Events</button>
<button onclick="app.eventWithSum()" class="fluid ui button">Event with Sum</button>
<button onclick="app.eventWithSegment()" class="fluid ui button">Event with Segment</button>
<button onclick="app.eventWithSumSegment()" class="fluid ui button">Even with Sum and Segment</button>
<button onclick="app.event()" class="fluid ui black button">All Events</button>
<button onclick="app.endEventBasic()" class="fluid ui button">Timed event: Start / Stop</button>
<button onclick="app.endEventWithSum()" class="fluid ui button">Timed event Sum: Start / Stop</button>
<button onclick="app.endEventWithSegment()" class="fluid ui button">Timed event Segment: Start / Stop</button>
<button onclick="app.endEventWithSumSegment()" class="fluid ui button">Timed event Sum Segment: Start /
Stop</button>
<button onclick="app.startEventX()" class="fluid ui button">Start Event X</button>
<button onclick="app.cancelEventX()" class="fluid ui button">Cancel Event X</button>
<div class="ui horizontal divider">Events End</div>
<button onclick="app.recordView('HomePage')" class="fluid ui button">Record View: "HomePage"</button>
<button onclick="app.recordView('Dashboard')" class="fluid ui button">Record View: "Dashboard"</button>
<div class="ui horizontal divider">2017</div>
<div class="ui horizontal divider">User Methods Start</div>
<button onclick="app.setCaptianAmericaData()" class="fluid ui button teal">Send Captian America Data</button>
<button onclick="app.setIronManData()" class="fluid ui button teal">Send Iron Man Data</button>
<button onclick="app.setSpiderManData()" class="fluid ui button teal">Send Spider-Man Data</button>
<button onclick="app.setUserData()" class="fluid ui button teal">Send Users Data</button>
<button onclick="app.userData.setProperty()" class="fluid ui button teal">UserData.setProperty</button>
<button onclick="app.userData.increment()" class="fluid ui button teal">UserData.increment</button>
<button onclick="app.userData.incrementBy()" class="fluid ui button teal">UserData.incrementBy</button>
<button onclick="app.userData.multiply()" class="fluid ui button teal">UserData.multiply</button>
<button onclick="app.userData.saveMax()" class="fluid ui button teal">UserData.saveMax</button>
<button onclick="app.userData.saveMin()" class="fluid ui button teal">UserData.saveMin</button>
<button onclick="app.userData.setOnce()" class="fluid ui button teal">UserData.setOnce</button>
<button onclick="app.userData.pushUniqueValue()" class="fluid ui button teal">UserData.pushUniqueValue</button>
<button onclick="app.userData.pushValue()" class="fluid ui button teal">UserData.pushValue</button>
<button onclick="app.userData.pullValue()" class="fluid ui button teal">UserData.pullValue</button>
<!-- Consent Button -->
<button onclick="app.setRequiresConsent()" class="fluid ui button blue">Init Consent</button>
<button onclick="app.giveMultipleConsent()" class="fluid ui button blue">Give multiple consent</button>
<button onclick="app.removeMultipleConsent()" class="fluid ui button blue">Remove multiple consent</button>
<button onclick="app.giveAllConsent()" class="fluid ui button blue">Give all Consent</button>
<button onclick="app.removeAllConsent()" class="fluid ui button blue">Remove all Consent</button>
<button onclick="app.giveConsentSessions()" class="fluid ui button blue">Give Consent Sessions</button>
<button onclick="app.giveConsentEvents()" class="fluid ui button blue">Give Consent Events</button>
<button onclick="app.giveConsentViews()" class="fluid ui button blue">Give Consent Views</button>
<button onclick="app.giveConsentLocation()" class="fluid ui button blue">Give Consent Location</button>
<button onclick="app.giveConsentCrashes()" class="fluid ui button blue">Give Consent Crashes</button>
<button onclick="app.giveConsentAttribution()" class="fluid ui button blue">Give Consent Attribution</button>
<button onclick="app.giveConsentUsers()" class="fluid ui button blue">Give Consent Users</button>
<button onclick="app.giveConsentPush()" class="fluid ui button blue">Give Consent Push</button>
<button onclick="app.giveConsentStarRating()" class="fluid ui button blue">Give Consent starRating</button>
<button onclick="app.giveConsentAppleWatch()" class="fluid ui button blue">Give Consent AppleWatch</button>
<button onclick="app.giveConsentAPM()" class="fluid ui button blue">Give Consent Performance</button>
<button onclick="app.removeConsentSessions()" class="fluid ui button blue">Remove Consent Sessions</button>
<button onclick="app.removeConsentEvents()" class="fluid ui button blue">Remove Consent Events</button>
<button onclick="app.removeConsentViews()" class="fluid ui button blue">Remove Consent Views</button>
<button onclick="app.removeConsentLocation()" class="fluid ui button blue">Remove Consent Location</button>
<button onclick="app.removeConsentCrashes()" class="fluid ui button blue">Remove Consent Crashes</button>
<button onclick="app.removeConsentAttribution()" class="fluid ui button blue">Remove Consent
Attribution</button>
<button onclick="app.removeConsentUsers()" class="fluid ui button blue">Remove Consent Users</button>
<button onclick="app.removeConsentPush()" class="fluid ui button blue">Remove Consent Push</button>
<button onclick="app.removeConsentStarRating()" class="fluid ui button blue">Remove Consent starRating</button>
<button onclick="app.removeConsentAppleWatch()" class="fluid ui button blue">Remove Consent AppleWatch</button>
<button onclick="app.removeConsentAPM()" class="fluid ui button blue">Remove Consent Performance</button>
<!-- Consent Button -->
<div class="ui horizontal divider">User Methods End</div>
<div class="ui horizontal divider">Remote Config Methods Start</div>
<button onclick="app.setRemoteConfigAutomaticDownload()"
class="fluid ui button blue">Countly.setRemoteConfigAutomaticDownload</button>
<button onclick="app.remoteConfigUpdate()" class="fluid ui button blue">Countly.remoteConfigUpdate</button>
<button onclick="app.updateRemoteConfigForKeysOnly()"
class="fluid ui button blue">Countly.updateRemoteConfigForKeysOnly</button>
<button onclick="app.updateRemoteConfigExceptKeys()"
class="fluid ui button blue">Countly.updateRemoteConfigExceptKeys</button>
<button onclick="app.remoteConfigClearValues()"
class="fluid ui button blue">Countly.remoteConfigClearValues</button>
<button onclick="app.updateRemoteConfigForbooleanValueOnly()" class="fluid ui button blue">Boolean Test</button>
<button onclick="app.updateRemoteConfigForfloatValueOnly()" class="fluid ui button blue">Float Test</button>
<button onclick="app.updateRemoteConfigForintegerValueOnly()" class="fluid ui button blue">Integer Test</button>
<button onclick="app.updateRemoteConfigForstringValueOnly()" class="fluid ui button blue">String Test</button>
<button onclick="app.updateRemoteConfigForjsonValueOnly()" class="fluid ui button blue">JSON Test</button>
<button onclick="app.updateRemoteConfigForjsonStringValueOnly()" class="fluid ui button blue">Array String
Test</button>
<button onclick="app.updateRemoteConfigForjsonNumberValueOnly()" class="fluid ui button blue">Array Number
Test</button>
<div class="ui horizontal divider">Remote Config Methods End</div>
<div class="ui horizontal divider">Other Methods Start</div>
<button onclick="app.setloggingenabled()" class="fluid ui button teal">Enable Debug Mode</button>
<button onclick="app.setloggingdisabled()" class="fluid ui button teal">Disable Debug Mode</button>
<button onclick="app.askForNotificationPermission()"
class="fluid ui button yellow">askForNotificationPermission</button>
<button onclick="app.sendPushToken()" class="fluid ui button teal">Send Push Token</button>
<button onclick="app.setHttpPostForced()" class="fluid ui button teal">SetHttpPostForced</button>
<!-- <button onclick="app.testAndroidPush()" class="fluid ui button teal">Push Test Android</button> -->
<!-- <button onclick="app.testiOSPush()" class="fluid ui button teal">Push Test iOS</button> -->
<button onclick="app.changeDeviceId()" class="fluid ui button yellow">Change Device ID</button>
<button onclick="app.enableParameterTamperingProtection('123456')" class="fluid ui button yellow">Enable
Parameter Tapmering Protection</button>
<button onclick="app.setOptionalParametersForInitialization()" class="fluid ui button yellow">City, State, and
Location</button>
<button onclick="app.setLocation()" class="fluid ui button yellow">SetLocation</button>
<button onclick="app.addCrashLog()" class="fluid ui button yellow">Send Crash Report</button>
<div class="ui horizontal divider">Other Methods End</div>
<div class="ui horizontal divider">Rating Methods Start</div>
<!-- <button onclick="app.sendRating()" class="fluid ui button">Send 5 star rating!!</button> -->
<button onclick="app.askForStarRating()" class="fluid ui button orange">Open rating modal</button>
<button onclick="app.askForFeedback()" class="fluid ui button orange">Open feedback modal</button>
<button onclick="app.showSurvey()" class="fluid ui button orange">Show Survey</button>
<button onclick="app.showNPS()" class="fluid ui button orange">Show NPS</button>
<div class="ui horizontal divider">Rating Methods End</div>
<div class="ui horizontal divider">Performance Methods Start</div>
<button onclick="app.startTrace()" class="fluid ui black button">Start Trace</button>
<button onclick="app.endTrace()" class="fluid ui black button">End Trace</button>
<button onclick="app.recordNetworkTraceSuccess()" class="fluid ui black button">Record Network Trace
Success</button>
<button onclick="app.recordNetworkTraceFailure()" class="fluid ui black button">Record Network Trace
Failure</button>
<button onclick="app.enableApm()" class="fluid ui black button">Enable APM</button>
<div class="ui horizontal divider">Performance Methods End</div>
</div>
<script type="text/javascript">
function onBodyLoad() {
console.log("[CountlyCordova] onBodyLoad");
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
console.log("[CountlyCordova] deviceready");
Countly.onNotification(function (theNotification) {
console.log("[CountlyCordova] onNotification : " + JSON.stringify(theNotification));
});
app.init();
}
app = {};
function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
app.init = function () {
Countly.isInitialized().then((result) => {
if (result != "true") {
/** Recommended settings for Countly initialisation */
Countly.setLoggingEnabled(true); // Enable countly internal debugging logs
Countly.enableCrashReporting(); // Enable crash reporting to report unhandled crashes to Countly
Countly.setRequiresConsent(true); // Set that consent should be required for features to work.
Countly.giveConsentInit(["location", "sessions", "attribution", "push", "events", "views", "crashes", "users", "push", "star-rating", "apm", "feedback", "remote-config"]); // give conset for specific features before init.
Countly.setLocationInit("TR", "Istanbul", "41.0082,28.9784", "10.2.33.12"); // Set user initial location.
/** Optional settings for Countly initialisation */
Countly.enableParameterTamperingProtection("salt"); // Set the optional salt to be used for calculating the checksum of requested data which will be sent with each request
// Countly.pinnedCertificates("count.ly.cer"); // It will ensure that connection is made with one of the public keys specified
Countly.setHttpPostForced(false); // Set to "true" if you want HTTP POST to be used for all requests
Countly.enableApm(); // Enable APM features, which includes the recording of app start time.
Countly.enableAttribution(); // Enable to measure your marketing campaign performance by attributing installs from specific campaigns.
Countly.setRemoteConfigAutomaticDownload(function (r) {
console.log("[CountlyCordova] onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] onError : " + r);
}); // Set Automatic value download happens when the SDK is initiated or when the device ID is changed.
Countly.pushTokenType(Countly.messagingMode.TEST); // Set messaging mode for push notifications
Countly.setStarRatingDialogTexts("Title", "Message", "Dismiss");
Countly.init("https://try.count.ly", "YOUR_API_KEY").then((result) => {
Countly.appLoadingFinished();
/**
* Push notifications settings
* Should be call after init
*/
Countly.onNotification(function (theNotification) {
console.log("[CountlyCordova] onNotification : " + JSON.stringify(theNotification));
}); // Set callback to receive push notifications
Countly.askForNotificationPermission(); // This method will ask for permission, enables push notification and send push token to countly server.
Countly.giveAllConsent(); // give consent for all features, should be call after init
// Countly.giveConsent(["events", "views"]); // give conset for some specific features, should be call after init.
}, (err) => {
console.error(err);
});
}
}, (err) => {
console.error(err);
});
// Countly.eventSendThreshold(1);
};
// app.test = function() {
// app.sendPushToken();
// app.sendSampleEvent();
// }
app.setOptionalParametersForInitialization = function () {
Countly.setOptionalParametersForInitialization({
"city": "Tampa",
"country": "US",
"latitude": "28.006324",
"longitude": "-82.7166183",
"ipAddress": "255.255.255.255"
});
};
app.setLocation = function () {
Countly.setLocation("TR", "Istanbul", "41.0082,28.9784", "10.2.33.12");
};
app.event = function () {
setInterval(function () {
app.sendSampleEvent();
}, 1000);
}
app.start = function () {
Countly.start();
}
// app.manualSessionHandling = function() {
// Countly.manualSessionHandling();
// }
// app.updateSessionPeriod = function() {
// Countly.updateSessionPeriod(15);
// }
// app.eventSendThreshold = function() {
// Countly.eventSendThreshold(1);
// }
// app.storedRequestsLimit = function() {
// Countly.storedRequestsLimit(1);
// }
app.stop = function () {
Countly.stop();
}
app.halt = function () {
Countly.halt();
}
app.sendSampleEvent = function () {
app.basicEvent();
app.eventWithSum();
app.eventWithSegment();
app.eventWithSumSegment();
}
app.basicEvent = function () {
// example for basic event
var event = {
"key": "Basic Event",
"count": 1
};
Countly.recordEvent(event);
}
app.eventWithSum = function () {
// example for event with sum
var event = {
"key": "Event With Sum",
"count": 1,
"sum": "0.99",
};
Countly.recordEvent(event);
}
app.eventWithSegment = function () {
// example for event with segment
var event = {
"key": "Event With Segment",
"count": 1
};
event.segments = {
"Country": "Turkey",
"Age": "28"
};
Countly.recordEvent(event);
}
app.eventWithSumSegment = function () {
// example for event with segment and sum
var event = {
"key": "Event With Sum And Segment",
"count": 1,
"sum": "0.99"
};
event.segments = {
"Country": "Turkey",
"Age": "28"
};
Countly.recordEvent(event);
}
app.eventWithSumSegment_duration = function () {
// example for event with segment and sum
var event = {
"key": "Event With Sum And Segment duration",
"count": 1,
"sum": "0.99",
"duration": "1000"
};
event.segments = {
"Country": "Turkey",
"Age": "28"
};
Countly.recordEvent(event);
}
app.setUserData = function () {
// example for setUserData
var options = {};
options.name = "Name of User";
options.username = "Username";
options.email = "User Email";
options.org = "User Organization";
options.phone = "User Contact number";
options.picture = "https://count.ly/images/logos/countly-logo.png";
options.picturePath = "";
options.gender = "User Gender";
options.byear = 1989;
Countly.setUserData(options);
};
app.setCaptianAmericaData = function () {
// example for setCaptianAmericaData
var deviceId = makeid();
Countly.changeDeviceId(deviceId, false);
var options = {};
options.name = "Captian America";
options.username = "captianamerica";
options.email = "[email protected]";
options.organization = "Avengers";
options.phone = "+91 555 555 5555";
options.picture = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Captain-America-icon.png";
options.picturePath = "";
options.gender = "M"; // "F"
options.byear = 1989;
Countly.setUserData(options);
};
app.setIronManData = function () {
// example for setIronManData
var deviceId = makeid();
Countly.changeDeviceId(deviceId, false);
var options = {};
options.name = "Iron Man";
options.username = "ironman";
options.email = "[email protected]";
options.organization = "Avengers";
options.phone = "+91 555 555 5555";
options.picture = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Iron-Man-icon.png";
options.picturePath = "";
options.gender = "M"; // "F"
options.byear = 1989;
Countly.setUserData(options);
Countly.start();
};
app.setSpiderManData = function () {
var deviceId = makeid();
Countly.changeDeviceId(deviceId, false);
var options = {};
options.name = "Spider-Man";
options.username = "spiderman";
options.email = "[email protected]";
options.organization = "Avengers";
options.phone = "+91 555 555 5555";
options.picture = "http://icons.iconarchive.com/icons/mattahan/ultrabuuf/512/Comics-Spiderman-Morales-icon.png";
options.picturePath = "";
options.gender = "M"; // "F"
options.byear = 1989;
Countly.setUserData(options);
Countly.start();
};
app.setloggingenabled = function () {
// example for setLoggingEnabled
Countly.setLoggingEnabled(true);
}
app.setloggingdisabled = function () {
// example for setLoggingEnabled
Countly.setLoggingEnabled(false);
}
app.sendPushToken = function () {
var push = PushNotification.init({
android: { sound: true },
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
push.on('registration', function (data) {
console.log("[CountlyCordova] registration : " + 'Token received: ' + data.registrationId);
Countly.sendPushToken({
"token": data.registrationId,
"messagingMode": Countly.messagingMode.DEVELOPMENT
});
});
push.on('notification', function (data) {
console.log("[CountlyCordova] notification : " + JSON.stringify(data));
});
push.on('error', function (e) {
// e.message
});
// Countly.messagingMode.DEVELOPMENT
// Countly.messagingMode.PRODUCTION
// Countly.messagingMode.ADHOC
}
app.setHttpPostForced = function () {
Countly.setHttpPostForced(true);
}
app.askForNotificationPermission = function () {
Countly.askForNotificationPermission();
}
app.recordView = function (viewName) {
Countly.recordView(viewName);
}
/** 2017 **/
app.changeDeviceId = function () {
Countly.changeDeviceId("123456", true);
}
app.enableParameterTamperingProtection = function () {
Countly.enableParameterTamperingProtection("salt");
}
app.endEventBasic = function () {
Countly.startEvent("Timed Event");
setTimeout(function () {
Countly.endEvent({ "key": "Timed Event" });
}, 1000);
}
app.endEventWithSum = function () {
Countly.startEvent("Timed Event With Sum");
setTimeout(function () {
Countly.endEvent({ "key": "Timed Event With Sum", "sum": "0.99" });
}, 1000);
}
app.endEventWithSegment = function () {
Countly.startEvent("Timed Event With Segment");
setTimeout(function () {
var events = {
"key": "Timed Event With Segment"
};
events.segments = {
"Country": "Turkey",
"Age": "28"
};
Countly.endEvent(events);
}, 1000);
}
app.endEventWithSumSegment = function () {
Countly.startEvent("Timed Event With Segment, Sum and Count");
setTimeout(function () {
var events = {
"key": "Timed Event With Segment, Sum and Count",
"count": 1,
"sum": "0.99"
};
events.segments = {
"Country": "Turkey",
"Age": "28"
};
Countly.endEvent(events);
}, 1000);
}
app.startEventX = function () {
Countly.startEvent("Event X");
}
app.cancelEventX = function () {
Countly.cancelEvent("Event X");
}
// app.sendRating = function(){
// // Ratings can be from 1 - 5;
// Countly.sendRating(5);
// }
app.askForFeedback = function () {
Countly.askForFeedback("5e4254507975d006a22535fc", "Close");
}
app.askForStarRating = function () {
Countly.askForStarRating(function (ratingResult) {
console.log("[CountlyCordova] askForStarRating : " + ratingResult);
});
}
app.showSurvey = function () {
Countly.getFeedbackWidgets().then((retrivedWidgets) => {
var surveyWidget = retrivedWidgets.find(x => x.type === 'survey')
if (surveyWidget) {
Countly.presentFeedbackWidget(surveyWidget, "Close")
}
}, (err) => {
console.error("showSurvey getFeedbackWidgets error : " + err);
});
}
app.showNPS = function () {
Countly.getFeedbackWidgets().then((retrivedWidgets) => {
var npsWidget = retrivedWidgets.find(x => x.type === 'nps')
if (npsWidget) {
Countly.presentFeedbackWidget(npsWidget, "Cancel")
}
}, (err) => {
console.error("showNPS getFeedbackWidgets error : " + err);
});
}
app.addCrashLog = function () {
Countly.enableCrashReporting();
Countly.addCrashLog("User Performed Step A");
setTimeout(function () {
Countly.addCrashLog("User Performed Step B");
}, 1000);
setTimeout(function () {
Countly.addCrashLog("User Performed Step C");
// console.log("Opps found and error");
a();
}, 1000);
}
function a() {
b();
}
function b() {
c();
}
function c() {
d();
throw new Error("My Custom Error");
}
function d() {
try {
throw new Error("My Second Error");
} catch (err) {
StackTrace.fromError(err).then(function (stackframes) {
Countly.logException(stackframes, true, { "_facebook_version": "0.0.1" });
});
}
}
/** user details **/
app.userData = {};
app.userData.setProperty = function () {
Countly.userData.setProperty("setProperty", "My Property");
}
app.userData.increment = function () {
Countly.userData.setProperty("increment", 4);
Countly.userData.increment("increment");
}
app.userData.incrementBy = function () {
Countly.userData.setProperty("incrementBy", 5);
Countly.userData.incrementBy("incrementBy", 10);
}
app.userData.multiply = function () {
Countly.userData.setProperty("multiply", 5);
Countly.userData.multiply("multiply", 20);
}
app.userData.saveMax = function () {
Countly.userData.saveMax("saveMax", 100);
}
app.userData.saveMin = function () {
Countly.userData.saveMin("saveMin", 50);
}
app.userData.setOnce = function () {
Countly.userData.setOnce("setOnce", 200);
}
app.userData.pushUniqueValue = function () {
Countly.userData.pushUniqueValue("pushUniqueValue", "morning");
}
app.userData.pushValue = function () {
Countly.userData.pushValue("pushValue", "morning");
}
app.userData.pullValue = function () {
Countly.userData.pullValue("pullValue", "morning");
}
//setRequiresConsent
app.setRequiresConsent = function () {
Countly.setRequiresConsent(true);
}
app.giveMultipleConsent = function () {
Countly.giveConsent(["events", "views", "star-rating", "crashes"]);
}
app.removeMultipleConsent = function () {
Countly.removeConsent(["events", "views", "star-rating", "crashes"]);
}
app.giveAllConsent = function () {
Countly.giveAllConsent();
}
app.removeAllConsent = function () {
Countly.removeAllConsent();
}
app.giveConsentSessions = function () {
Countly.giveConsent(["sessions"]);
}
app.giveConsentEvents = function () {
Countly.giveConsent(["events"]);
}
app.giveConsentViews = function () {
Countly.giveConsent(["views"]);
}
app.giveConsentLocation = function () {
Countly.giveConsent(["location"]);
}
app.giveConsentCrashes = function () {
Countly.giveConsent(["crashes"]);
}
app.giveConsentAttribution = function () {
Countly.giveConsent(["attribution"]);
}
app.giveConsentUsers = function () {
Countly.giveConsent(["users"]);
}
app.giveConsentPush = function () {
Countly.giveConsent(["push"]);
}
app.giveConsentStarRating = function () {
Countly.giveConsent(["star-rating"]);
}
app.giveConsentAppleWatch = function () {
Countly.giveConsent(["AppleWatch"]);
}
app.giveConsentAPM = function () {
Countly.giveConsent(["apm"]);
}
app.removeConsentSessions = function () {
Countly.removeConsent(["sessions"]);
}
app.removeConsentEvents = function () {
Countly.removeConsent(["events"]);
}
app.removeConsentViews = function () {
Countly.removeConsent(["views"]);
}
app.removeConsentLocation = function () {
Countly.removeConsent(["location"]);
}
app.removeConsentCrashes = function () {
Countly.removeConsent(["crashes"]);
}
app.removeConsentAttribution = function () {
Countly.removeConsent(["attribution"]);
}
app.removeConsentUsers = function () {
Countly.removeConsent(["users"]);
}
app.removeConsentPush = function () {
Countly.removeConsent(["push"]);
}
app.removeConsentStarRating = function () {
Countly.removeConsent(["star-rating"]);
}
app.removeConsentAppleWatch = function () {
Countly.giveConsent(["AppleWatch"]);
}
app.removeConsentAPM = function () {
Countly.removeConsent(["apm"]);
}
// Remote config usage
app.setRemoteConfigAutomaticDownload = function () {
Countly.setRemoteConfigAutomaticDownload(function (r) {
console.log("[CountlyCordova] setRemoteConfigAutomaticDownload onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] setRemoteConfigAutomaticDownload onError : " + r);
});
}
app.remoteConfigUpdate = function () {
Countly.remoteConfigUpdate(function (r) {
console.log("[CountlyCordova] remoteConfigUpdate onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] remoteConfigUpdate onError : " + r);
});
}
app.updateRemoteConfigForKeysOnly = function () {
Countly.updateRemoteConfigForKeysOnly(["name"], function (r) {
console.log("[CountlyCordova] updateRemoteConfigForKeysOnly onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] updateRemoteConfigForKeysOnly onError : " + r);
});
}
app.updateRemoteConfigExceptKeys = function () {
Countly.updateRemoteConfigExceptKeys(["url"], function (r) {
console.log("[CountlyCordova] updateRemoteConfigExceptKeys onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] updateRemoteConfigExceptKeys onError : " + r);
});
}
app.remoteConfigClearValues = function () {
Countly.remoteConfigClearValues(function (r) {
console.log("[CountlyCordova] remoteConfigClearValues onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] remoteConfigClearValues onError : " + r);
});
}
app.getRemoteConfigValueForKey = function () {
Countly.getRemoteConfigValueForKey("name", function (r) {
console.log("[CountlyCordova] getRemoteConfigValueForKey onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] getRemoteConfigValueForKey onError : " + r);
});
}
app.updateRemoteConfigForbooleanValueOnly = function () {
Countly.getRemoteConfigValueForKey("booleanValue", function (r) {
console.log("[CountlyCordova] updateRemoteConfigForbooleanValueOnly onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] updateRemoteConfigForbooleanValueOnly onError : " + r);
});
}
app.updateRemoteConfigForfloatValueOnly = function () {
Countly.getRemoteConfigValueForKey("floatValue", function (r) {
console.log("[CountlyCordova] updateRemoteConfigForfloatValueOnly onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] updateRemoteConfigForfloatValueOnly onError : " + r);
});
}
app.updateRemoteConfigForintegerValueOnly = function () {
Countly.getRemoteConfigValueForKey("integerValue", function (r) {
console.log("[CountlyCordova] updateRemoteConfigForintegerValueOnly onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] updateRemoteConfigForintegerValueOnly onError : " + r);
});
}
app.updateRemoteConfigForstringValueOnly = function () {
Countly.getRemoteConfigValueForKey("stringValue", function (r) {
console.log("[CountlyCordova] updateRemoteConfigForstringValueOnly onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] updateRemoteConfigForstringValueOnly onError : " + r);
});
}
app.updateRemoteConfigForjsonValueOnly = function () {
Countly.getRemoteConfigValueForKey("jsonValue", function (r) {
console.log("[CountlyCordova] updateRemoteConfigForjsonValueOnly onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] updateRemoteConfigForjsonValueOnly onError : " + r);
});
}
app.updateRemoteConfigForjsonStringValueOnly = function () {
Countly.getRemoteConfigValueForKey("arrayStringValue", function (r) {
console.log("[CountlyCordova] updateRemoteConfigForjsonStringValueOnly onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] updateRemoteConfigForjsonStringValueOnly onError : " + r);
});
}
app.updateRemoteConfigForjsonNumberValueOnly = function () {
Countly.getRemoteConfigValueForKey("arrayNumberValue", function (r) {
console.log("[CountlyCordova] updateRemoteConfigForjsonNumberValueOnly onSuccess : " + r)
}, function (r) {
console.log("[CountlyCordova] updateRemoteConfigForjsonNumberValueOnly onError : " + r);
});
}
var successCodes = [100, 101, 200, 201, 202, 205, 300, 301, 303, 305];
var failureCodes = [400, 402, 405, 408, 500, 501, 502, 505];
app.startTrace = function () {
var traceKey = "Trace Key";
Countly.startTrace(traceKey);
}
app.endTrace = function () {
var traceKey = "Trace Key";
var customMetric = {
"ABC": 1233,
"C44C": 1337
};
Countly.endTrace(traceKey, customMetric);
}
function random(number) {
return Math.floor(Math.random() * number);
}
app.recordNetworkTraceSuccess = function () {
var networkTraceKey = "api/endpoint.1";
var responseCode = successCodes[random(successCodes.length)];
var requestPayloadSize = random(700) + 200;
var responsePayloadSize = random(700) + 200;
var startTime = new Date().getTime();
var endTime = startTime + 500;
Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime);
}
app.recordNetworkTraceFailure = function () {
var networkTraceKey = "api/endpoint.1";
var responseCode = failureCodes[random(failureCodes.length)];
var requestPayloadSize = random(700) + 250;
var responsePayloadSize = random(700) + 250;
var startTime = new Date().getTime();
var endTime = startTime + 500;
Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime);
}
app.enableApm = function () {
Countly.enableApm();
}
app.setCustomCrashSegment = function () {
var segment = { "Key": "Value" };
Countly.setCustomCrashSegment(segment);
}
// Remote config usage
// /** Use StackTrace to log all exceptions **/
// (function(){
// if (window.StackTrace) {
// StackTrace.get().then(function(stackframes) {
// if (Countly.isCrashReportingEnabled) {
// Countly.logException(stackframes, true, {"_facebook_version": "0.0.1"});
// }
// }).catch(function(err) {});
// }
// })();
</script>
</body>
</html>