countly-sdk-web 22.2.2 → 22.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/.eslintignore +17 -17
  2. package/.eslintrc.js +215 -215
  3. package/.github/dependabot.yml +20 -20
  4. package/.github/workflows/codeql-analysis.yml +71 -71
  5. package/.github/workflows/documentation.yml +24 -0
  6. package/.github/workflows/node.js.yml +25 -41
  7. package/CHANGELOG.md +241 -237
  8. package/LICENSE +19 -19
  9. package/README.md +86 -122
  10. package/SECURITY.md +3 -3
  11. package/bower.json +29 -29
  12. package/cypress/.eslintrc.js +22 -22
  13. package/cypress/fixtures/base.html +8 -0
  14. package/cypress/fixtures/scroll_test.html +60 -0
  15. package/cypress/fixtures/scroll_test_2.html +48 -0
  16. package/cypress/fixtures/scroll_test_3.html +72 -0
  17. package/cypress/fixtures/session_test_auto.html +51 -0
  18. package/cypress/fixtures/session_test_manual_1.html +58 -0
  19. package/cypress/fixtures/session_test_manual_2.html +54 -0
  20. package/cypress/fixtures/user_agent.html +20 -0
  21. package/cypress/integration/consents.js +165 -165
  22. package/cypress/integration/device_id.js +1085 -830
  23. package/cypress/integration/events.js +65 -65
  24. package/cypress/integration/heatmaps.js +52 -0
  25. package/cypress/integration/internal_limits.js +153 -153
  26. package/cypress/integration/reponse_validation.js +170 -170
  27. package/cypress/integration/sessions.js +196 -60
  28. package/cypress/integration/user_agent.js +63 -0
  29. package/cypress/integration/user_details.js +40 -40
  30. package/cypress/integration/utm.js +236 -236
  31. package/cypress/integration/views.js +62 -62
  32. package/cypress/plugins/index.js +22 -22
  33. package/cypress/support/commands.js +322 -298
  34. package/cypress/support/helper.js +59 -59
  35. package/cypress/support/index.js +2 -2
  36. package/cypress/support/integration_helper.js +17 -0
  37. package/cypress.json +3 -1
  38. package/examples/example_apm.html +51 -51
  39. package/examples/example_fb.html +50 -50
  40. package/examples/example_formdata.html +47 -47
  41. package/examples/example_ga_adapter.html +173 -173
  42. package/examples/example_gdpr.html +82 -82
  43. package/examples/example_internal_limits.html +184 -184
  44. package/examples/example_multiple_instances.html +52 -52
  45. package/examples/example_rating_widgets.html +80 -80
  46. package/examples/example_remote_config.html +38 -38
  47. package/examples/example_sync.html +36 -36
  48. package/examples/examples_feedback_widgets.html +81 -81
  49. package/examples/mpa/boomerang/boomerang-1.0.0.js +22871 -22871
  50. package/examples/mpa/boomerang/countly_boomerang.js +138 -138
  51. package/examples/mpa/index.html +816 -816
  52. package/examples/react/README.md +35 -35
  53. package/examples/react/package.json +37 -37
  54. package/examples/react/public/index.html +19 -19
  55. package/examples/react/public/manifest.json +25 -25
  56. package/examples/react/public/robots.txt +3 -3
  57. package/examples/react/src/App-WithEffect.js +33 -33
  58. package/examples/react/src/App-WithRouter.js +46 -46
  59. package/examples/react/src/App.test.js +9 -9
  60. package/examples/react/src/Components/Contact.js +28 -28
  61. package/examples/react/src/Components/Header.js +88 -88
  62. package/examples/react/src/Components/Home.js +23 -23
  63. package/examples/react/src/Components/Users.js +43 -43
  64. package/examples/react/src/Components/styles.css +25 -25
  65. package/examples/react/src/ErrorBoundary.js +28 -28
  66. package/examples/react/src/Location-WithEffect.js +27 -27
  67. package/examples/react/src/Location-WithRouter.js +23 -23
  68. package/examples/react/src/index.css +5 -5
  69. package/examples/react/src/index.js +68 -68
  70. package/examples/react/src/serviceWorker.js +141 -141
  71. package/examples/react/src/setupTests.js +5 -5
  72. package/examples/symbolication/.babelrc +11 -11
  73. package/examples/symbolication/.editorconfig +8 -8
  74. package/examples/symbolication/.yo-rc.json +53 -53
  75. package/examples/symbolication/README.md +33 -33
  76. package/examples/symbolication/package.json +22 -22
  77. package/examples/symbolication/src/index.js +47 -47
  78. package/examples/symbolication/static/index.html +21 -21
  79. package/examples/symbolication/webpack.config.js +27 -27
  80. package/generateDocs.sh +80 -79
  81. package/inch.json +6 -6
  82. package/jsdoc_conf.json +4 -2
  83. package/lib/countly.js +4625 -4416
  84. package/lib/countly.min.js +126 -117
  85. package/package.json +57 -57
  86. package/plugin/boomerang/boomerang.min.js +10 -10
  87. package/plugin/boomerang/countly_boomerang.js +150 -150
  88. package/plugin/ga_adapter/doc.md +73 -73
  89. package/plugin/ga_adapter/ga_adapter.js +451 -451
  90. package/webpack.config.js +12 -12
  91. package/countly-sdk-web-22.2.2.tgz +0 -0
@@ -1,452 +1,452 @@
1
- "use strict";
2
- /*global Countly */
3
- /*
4
- Countly Adapter Library for Google Analytics
5
- */
6
- (function() {
7
- // logs array for tests
8
- window.cly_ga_test_logs = [];
9
- Countly.onload = Countly.onload || [];
10
- // adapter function
11
- window.CountlyGAAdapter = function() {
12
- // hold ga instance
13
- var old_ga = window.ga;
14
- // array for ga calls which called before ga initialized
15
- var gaCalls = [];
16
- // hold calls in array
17
- window.ga = function() {
18
- gaCalls.push(arguments);
19
- return old_ga.apply(this, arguments);
20
- };
21
- // ga overrided signature
22
- window.ga._signature = 1;
23
-
24
- // hold ga_countly calls in array before countly initialized
25
- var gaCountlyArray = [];
26
- var ga_countly = function() {
27
- gaCountlyArray.push(arguments);
28
- };
29
-
30
- Countly.onload.push(function(cly) {
31
- // cart for ga:ecommerce plugin
32
- var cart = cly._internals.store('cly_ecommerce:cart') || [];
33
- // override ga_countly and map request to countly
34
- ga_countly = function(c, o, u, n, t, l/*, y*/) {
35
- if (typeof c === "string") {
36
- var customSegments, i, count;
37
- switch (c) {
38
- case 'send':
39
- if (typeof o === 'string') {
40
- // ga('send', 'event', ..)
41
- if (o === 'event') {
42
-
43
- customSegments = {};
44
- count = 1;
45
- // ga('send', 'event', 'category', 'action')
46
- if (arguments.length === 4) {
47
- customSegments.category = u;
48
- }
49
- // ga('send', 'event', 'category', 'action', 'label')
50
- else if (arguments.length === 5 && typeof arguments[4] === "string") {
51
- customSegments.category = u;
52
- customSegments.label = t;
53
- }
54
- // ga('send', 'event', 'category', 'action', {metric:value})
55
- else if (arguments.length === 5 && typeof arguments[4] === "object") {
56
- customSegments.category = u;
57
- for (i = 0; i < Object.keys(arguments[4]).length; i++) {
58
- customSegments[Object.keys(arguments[4])[i]] = Object.values(arguments[4])[i];
59
- }
60
- }
61
- // ga('send', 'event', 'category', 'action', 'label', 1)
62
- else if (arguments.length >= 6) {
63
- customSegments.category = u;
64
- customSegments.label = t;
65
- count = l;
66
- }
67
-
68
- // add event by configured values
69
- Countly.q.push(['add_event', {
70
- key: n,
71
- count: count,
72
- segmentation: customSegments
73
- }]);
74
-
75
- if (window.cly_ga_test_mode) {
76
- window.cly_ga_test_logs.push(['add_event', {
77
- key: n,
78
- count: count,
79
- segmentation: customSegments
80
- }]);
81
- }
82
- }
83
- // ga('send', 'pageview')
84
- else if (o === 'pageview' && arguments.length === 2) {
85
- if (cly._internals.store('cly_ga:page')) {
86
- Countly.q.push(['track_pageview', cly._internals.store('cly_ga:page')]);
87
- if (window.cly_ga_test_mode) {
88
- window.cly_ga_test_logs.push(['track_pageview', cly._internals.store('cly_ga:page')]);
89
- }
90
- }
91
- else {
92
- Countly.q.push(['track_pageview']);
93
- if (window.cly_ga_test_mode) {
94
- window.cly_ga_test_logs.push(['track_pageview']);
95
- }
96
- }
97
- }
98
- // ga('send', 'pageview', 'page')
99
- else if (o === 'pageview' && arguments.length >= 3 && typeof arguments[2] === "string") {
100
- Countly.q.push(['track_pageview', arguments[2]]);
101
- if (window.cly_ga_test_mode) {
102
- window.cly_ga_test_logs.push(['track_pageview', arguments[2]]);
103
- }
104
- }
105
- // ga('send', 'pageview', {'customDimension':'customValue'})
106
- else if (o === 'pageview' && arguments.length >= 3 && typeof arguments[2] === "object") {
107
- // we are not supported tracking pageview with custom objects for now
108
- Countly.q.push(['track_pageview']);
109
- if (window.cly_ga_test_mode) {
110
- window.cly_ga_test_logs.push(['track_pageview']);
111
- }
112
- }
113
- // ga('send', 'social', 'network', 'action', 'target')
114
- else if (o === 'social') {
115
- Countly.q.push(['add_event', {
116
- "key": n,
117
- "count": 1,
118
- "segmentation": {
119
- "category": o,
120
- "platform": u,
121
- "target": t
122
- }
123
- }]);
124
- if (window.cly_ga_test_mode) {
125
- window.cly_ga_test_logs.push(['add_event', {
126
- "key": n,
127
- "count": 1,
128
- "segmentation": {"category": o, "platform": u, "target": t}
129
- }]);
130
- }
131
- }
132
- // ga('send', 'screenview', {..})
133
- else if (o === 'screenview') {
134
- customSegments = {appName: u.appName};
135
-
136
- if (u.screenName) {
137
- customSegments.screenName = u.screenName;
138
- }
139
- if (u.appVersion) {
140
- customSegments.appVersion = u.appVersion;
141
- }
142
- if (u.appInstallerId) {
143
- customSegments.appInstallerId = u.appInstallerId;
144
- }
145
- if (cly._internals.store('cly_ga:screenname')) {
146
- customSegments.screenName = cly._internals.store('cly_ga:screenname');
147
- }
148
-
149
- Countly.q.push(['add_event', {
150
- "key": "Screen View",
151
- "count": 1,
152
- "segmentation": customSegments
153
- }]);
154
-
155
- if (window.cly_ga_test_mode) {
156
- window.cly_ga_test_logs.push(['add_event', {
157
- "key": "Screen View",
158
- "count": 1,
159
- "segmentation": customSegments
160
- }]);
161
- }
162
- }
163
- // ga('send', 'exception', {..})
164
- else if (o === 'exception') {
165
- cly.log_error(u.exDescription);
166
- if (window.cly_ga_test_mode) {
167
- window.cly_ga_test_logs.push(u.exDescription);
168
- }
169
- }
170
- // ga('send', 'timing', 'timingCategory', 'timingVar', 'timingValue', 'timingLabel')
171
- else if (o === 'timing') {
172
- customSegments = {category: u};
173
- if (l) {
174
- customSegments.label = l;
175
- }
176
- Countly.q.push(['add_event', {
177
- "key": n,
178
- "count": 1,
179
- "dur": t,
180
- "segmentation": customSegments
181
- }]);
182
- if (window.cly_ga_test_mode) {
183
- window.cly_ga_test_logs.push(['add_event', {
184
- "key": n,
185
- "count": 1,
186
- "dur": t,
187
- "segmentation": customSegments
188
- }]);
189
- }
190
- }
191
- }
192
- // ga('send', {hitType:.., ...})
193
- else if (typeof o === 'object') {
194
- switch (o.hitType) {
195
- // ga('send', {'hitType':'event', ..})
196
- case 'event':
197
- customSegments = {
198
- 'category': o.eventCategory
199
- };
200
- count = 1;
201
-
202
- if (o.eventLabel) {
203
- customSegments.label = o.eventLabel;
204
- }
205
- if (o.eventValue) {
206
- count = o.eventValue;
207
- }
208
-
209
- Countly.q.push(['add_event', {
210
- key: o.eventAction,
211
- count: count,
212
- segmentation: customSegments
213
- }]);
214
-
215
- if (window.cly_ga_test_mode) {
216
- window.cly_ga_test_logs.push(['add_event', {
217
- key: o.eventAction,
218
- count: count,
219
- segmentation: customSegments
220
- }]);
221
- }
222
-
223
- break;
224
- // ga('send', {'hitType':'social', ..})
225
- case 'social':
226
- Countly.q.push(['add_event', {
227
- "key": o.socialAction,
228
- "count": 1,
229
- "segmentation": {
230
- "category": o.hitType,
231
- "platform": o.socialNetwork,
232
- "target": o.socialTarget
233
- }
234
- }]);
235
-
236
- if (window.cly_ga_test_mode) {
237
- window.cly_ga_test_logs.push(['add_event', {
238
- "key": o.socialAction,
239
- "count": 1,
240
- "segmentation": {
241
- "category": o.hitType,
242
- "platform": o.socialNetwork,
243
- "target": o.socialTarget
244
- }
245
- }]);
246
- }
247
-
248
- break;
249
- // ga('send', {'hitType':'timing', ..})
250
- case 'timing':
251
- Countly.q.push(['add_event', {
252
- "key": o.timingVar,
253
- "count": 1,
254
- "dur": o.timingValue,
255
- "segmentation": {
256
- "category": o.timingCategory
257
- }
258
- }]);
259
-
260
- if (window.cly_ga_test_mode) {
261
- window.cly_ga_test_logs.push(['add_event', {
262
- "key": o.timingVar,
263
- "count": 1,
264
- "dur": o.timingValue,
265
- "segmentation": {"category": o.timingCategory}
266
- }]);
267
- }
268
- break;
269
- // ga('send', {'hitType':'pageview', 'page':'page'})
270
- case 'pageview':
271
- Countly.q.push(['track_pageview', o.page]);
272
- if (window.cly_ga_test_mode) {
273
- window.cly_ga_test_logs.push(['track_pageview', o.page]);
274
- }
275
- break;
276
- }
277
- }
278
- break;
279
- // ga('create', '..')
280
- case 'create':
281
- // ga('create', .., 'auto', '..')
282
- if (arguments.length === 4 && arguments[2] === 'auto') {
283
- cly._internals.store('cly_ga:id', o);
284
- if (window.cly_ga_test_mode) {
285
- window.cly_ga_test_logs.push({
286
- 'stored': cly._internals.store('cly_ga:id'),
287
- 'value': o
288
- });
289
- }
290
- window.ga_adapter_integrated = true;
291
- // ga('create', .., callback)
292
- }
293
- else if (arguments.length === 3) {
294
- cly._internals.store('cly_ga:id', o);
295
- if (window.cly_ga_test_mode) {
296
- window.cly_ga_test_logs.push({
297
- 'stored': cly._internals.store('cly_ga:id'),
298
- 'value': o
299
- });
300
- }
301
- window.ga_adapter_integrated = true;
302
- }
303
- break;
304
- // ga('set', '..')
305
- case 'set':
306
- // ga('set', 'page', '/login.html')
307
- if (o === 'page') {
308
- cly._internals.store('cly_ga:page', u);
309
- }
310
- // ga('set', 'screenname', 'High scores')
311
- else if (o === 'screenname') {
312
- cly._internals.store('cly_ga:screenname', u);
313
- if (window.cly_ga_test_mode) {
314
- window.cly_ga_test_logs.push({
315
- 'stored': cly._internals.store('cly_ga:screenname'),
316
- 'value': u
317
- });
318
- }
319
- }
320
- // ga('set', 'dimension', 'custom data')
321
- else if (arguments.length === 3) {
322
- Countly.q.push(['userData.set', o, u]);
323
- if (window.cly_ga_test_mode) {
324
- window.cly_ga_test_logs.push(['userData.set', o, u]);
325
- }
326
- }
327
- // ga('set', {key:val, anotherKey: anotherVal})
328
- else if (arguments.length === 2 && typeof o === 'object') {
329
- Countly.q.push(['user_details', {custom: o}]);
330
- if (window.cly_ga_test_mode) {
331
- window.cly_ga_test_logs.push(['user_details', {custom: o}]);
332
- }
333
- }
334
- break;
335
- // ga('ecommerce:addTransaction', {..})
336
- case 'ecommerce:addTransaction':
337
- customSegments = {
338
- "id": o.id,
339
- "affiliation": o.affiliation,
340
- "shipping": o.shipping,
341
- "tax": o.tax
342
- };
343
-
344
- if (o.currency) {
345
- customSegments.currency = o.currency;
346
- }
347
-
348
- Countly.q.push(['add_event', {
349
- "key": c,
350
- "count": 1,
351
- "sum": o.revenue,
352
- "segmentation": customSegments
353
- }]);
354
-
355
- if (window.cly_ga_test_mode) {
356
- window.cly_ga_test_logs.push(['add_event', {
357
- "key": c,
358
- "count": 1,
359
- "sum": o.revenue,
360
- "segmentation": customSegments
361
- }]);
362
- }
363
-
364
- break;
365
- // ga('ecommerce:addItem', {..})
366
- case 'ecommerce:addItem':
367
- customSegments = {
368
- "id": o.id,
369
- "name": o.name,
370
- "sku": o.sku,
371
- "category": o.category
372
- };
373
-
374
- if (o.currency) {
375
- customSegments.currency = o.currency;
376
- }
377
-
378
- cart.push(['add_event', {
379
- "key": c,
380
- "count": o.quantity,
381
- "sum": o.price,
382
- "segmentation": customSegments
383
- }]);
384
-
385
- cly._internals.store('cly_ecommerce:cart', cart);
386
-
387
- if (window.cly_ga_test_mode) {
388
- window.cly_ga_test_logs.push(['add_event', {
389
- "key": c,
390
- "count": o.quantity,
391
- "sum": o.price,
392
- "segmentation": customSegments
393
- }]);
394
- }
395
-
396
- break;
397
- // ga('ecommerce:send')
398
- case 'ecommerce:send':
399
- var firstLength;
400
- if (window.cly_ga_test_mode) {
401
- firstLength = cart.length;
402
- }
403
- for (i = 0; i < cart.length; i++) {
404
- Countly.q.push(cart[i]);
405
- }
406
- cart = [];
407
- cly._internals.store('cly_ecommerce:cart', cart);
408
-
409
- if (window.cly_ga_test_mode) {
410
- window.cly_ga_test_logs.push({first: firstLength, last: cart.length});
411
- }
412
- break;
413
- // ga('ecommerce:clear')
414
- case 'ecommerce:clear':
415
- cart = [];
416
- cly._internals.store('cly_ecommerce:cart', cart);
417
-
418
- if (window.cly_ga_test_mode) {
419
- window.cly_ga_test_logs.push(cly._internals.store('cly_ecommerce:cart'));
420
- }
421
- break;
422
- default:
423
- break;
424
- }
425
- }
426
- };
427
- // apply old countly calls to overrided function
428
- while (gaCountlyArray.length) {
429
- var args = gaCountlyArray.shift();
430
- ga_countly.apply(window, args);
431
- }
432
- });
433
-
434
- // check variable for gaAdapter is loaded?
435
- setTimeout(function check() {
436
- if (window.ga._signature) {
437
- return setTimeout(check, 125);
438
- }
439
- old_ga = window.ga;
440
-
441
- while (gaCalls.length) {
442
- var args = gaCalls.shift();
443
- ga_countly.apply(window, args);
444
- }
445
-
446
- window.ga = function() {
447
- ga_countly.apply(window, arguments);
448
- return old_ga.apply(this, arguments);
449
- };
450
- }, 125);
451
- };
1
+ "use strict";
2
+ /*global Countly */
3
+ /*
4
+ Countly Adapter Library for Google Analytics
5
+ */
6
+ (function() {
7
+ // logs array for tests
8
+ window.cly_ga_test_logs = [];
9
+ Countly.onload = Countly.onload || [];
10
+ // adapter function
11
+ window.CountlyGAAdapter = function() {
12
+ // hold ga instance
13
+ var old_ga = window.ga;
14
+ // array for ga calls which called before ga initialized
15
+ var gaCalls = [];
16
+ // hold calls in array
17
+ window.ga = function() {
18
+ gaCalls.push(arguments);
19
+ return old_ga.apply(this, arguments);
20
+ };
21
+ // ga overrided signature
22
+ window.ga._signature = 1;
23
+
24
+ // hold ga_countly calls in array before countly initialized
25
+ var gaCountlyArray = [];
26
+ var ga_countly = function() {
27
+ gaCountlyArray.push(arguments);
28
+ };
29
+
30
+ Countly.onload.push(function(cly) {
31
+ // cart for ga:ecommerce plugin
32
+ var cart = cly._internals.store('cly_ecommerce:cart') || [];
33
+ // override ga_countly and map request to countly
34
+ ga_countly = function(c, o, u, n, t, l/*, y*/) {
35
+ if (typeof c === "string") {
36
+ var customSegments, i, count;
37
+ switch (c) {
38
+ case 'send':
39
+ if (typeof o === 'string') {
40
+ // ga('send', 'event', ..)
41
+ if (o === 'event') {
42
+
43
+ customSegments = {};
44
+ count = 1;
45
+ // ga('send', 'event', 'category', 'action')
46
+ if (arguments.length === 4) {
47
+ customSegments.category = u;
48
+ }
49
+ // ga('send', 'event', 'category', 'action', 'label')
50
+ else if (arguments.length === 5 && typeof arguments[4] === "string") {
51
+ customSegments.category = u;
52
+ customSegments.label = t;
53
+ }
54
+ // ga('send', 'event', 'category', 'action', {metric:value})
55
+ else if (arguments.length === 5 && typeof arguments[4] === "object") {
56
+ customSegments.category = u;
57
+ for (i = 0; i < Object.keys(arguments[4]).length; i++) {
58
+ customSegments[Object.keys(arguments[4])[i]] = Object.values(arguments[4])[i];
59
+ }
60
+ }
61
+ // ga('send', 'event', 'category', 'action', 'label', 1)
62
+ else if (arguments.length >= 6) {
63
+ customSegments.category = u;
64
+ customSegments.label = t;
65
+ count = l;
66
+ }
67
+
68
+ // add event by configured values
69
+ Countly.q.push(['add_event', {
70
+ key: n,
71
+ count: count,
72
+ segmentation: customSegments
73
+ }]);
74
+
75
+ if (window.cly_ga_test_mode) {
76
+ window.cly_ga_test_logs.push(['add_event', {
77
+ key: n,
78
+ count: count,
79
+ segmentation: customSegments
80
+ }]);
81
+ }
82
+ }
83
+ // ga('send', 'pageview')
84
+ else if (o === 'pageview' && arguments.length === 2) {
85
+ if (cly._internals.store('cly_ga:page')) {
86
+ Countly.q.push(['track_pageview', cly._internals.store('cly_ga:page')]);
87
+ if (window.cly_ga_test_mode) {
88
+ window.cly_ga_test_logs.push(['track_pageview', cly._internals.store('cly_ga:page')]);
89
+ }
90
+ }
91
+ else {
92
+ Countly.q.push(['track_pageview']);
93
+ if (window.cly_ga_test_mode) {
94
+ window.cly_ga_test_logs.push(['track_pageview']);
95
+ }
96
+ }
97
+ }
98
+ // ga('send', 'pageview', 'page')
99
+ else if (o === 'pageview' && arguments.length >= 3 && typeof arguments[2] === "string") {
100
+ Countly.q.push(['track_pageview', arguments[2]]);
101
+ if (window.cly_ga_test_mode) {
102
+ window.cly_ga_test_logs.push(['track_pageview', arguments[2]]);
103
+ }
104
+ }
105
+ // ga('send', 'pageview', {'customDimension':'customValue'})
106
+ else if (o === 'pageview' && arguments.length >= 3 && typeof arguments[2] === "object") {
107
+ // we are not supported tracking pageview with custom objects for now
108
+ Countly.q.push(['track_pageview']);
109
+ if (window.cly_ga_test_mode) {
110
+ window.cly_ga_test_logs.push(['track_pageview']);
111
+ }
112
+ }
113
+ // ga('send', 'social', 'network', 'action', 'target')
114
+ else if (o === 'social') {
115
+ Countly.q.push(['add_event', {
116
+ "key": n,
117
+ "count": 1,
118
+ "segmentation": {
119
+ "category": o,
120
+ "platform": u,
121
+ "target": t
122
+ }
123
+ }]);
124
+ if (window.cly_ga_test_mode) {
125
+ window.cly_ga_test_logs.push(['add_event', {
126
+ "key": n,
127
+ "count": 1,
128
+ "segmentation": {"category": o, "platform": u, "target": t}
129
+ }]);
130
+ }
131
+ }
132
+ // ga('send', 'screenview', {..})
133
+ else if (o === 'screenview') {
134
+ customSegments = {appName: u.appName};
135
+
136
+ if (u.screenName) {
137
+ customSegments.screenName = u.screenName;
138
+ }
139
+ if (u.appVersion) {
140
+ customSegments.appVersion = u.appVersion;
141
+ }
142
+ if (u.appInstallerId) {
143
+ customSegments.appInstallerId = u.appInstallerId;
144
+ }
145
+ if (cly._internals.store('cly_ga:screenname')) {
146
+ customSegments.screenName = cly._internals.store('cly_ga:screenname');
147
+ }
148
+
149
+ Countly.q.push(['add_event', {
150
+ "key": "Screen View",
151
+ "count": 1,
152
+ "segmentation": customSegments
153
+ }]);
154
+
155
+ if (window.cly_ga_test_mode) {
156
+ window.cly_ga_test_logs.push(['add_event', {
157
+ "key": "Screen View",
158
+ "count": 1,
159
+ "segmentation": customSegments
160
+ }]);
161
+ }
162
+ }
163
+ // ga('send', 'exception', {..})
164
+ else if (o === 'exception') {
165
+ cly.log_error(u.exDescription);
166
+ if (window.cly_ga_test_mode) {
167
+ window.cly_ga_test_logs.push(u.exDescription);
168
+ }
169
+ }
170
+ // ga('send', 'timing', 'timingCategory', 'timingVar', 'timingValue', 'timingLabel')
171
+ else if (o === 'timing') {
172
+ customSegments = {category: u};
173
+ if (l) {
174
+ customSegments.label = l;
175
+ }
176
+ Countly.q.push(['add_event', {
177
+ "key": n,
178
+ "count": 1,
179
+ "dur": t,
180
+ "segmentation": customSegments
181
+ }]);
182
+ if (window.cly_ga_test_mode) {
183
+ window.cly_ga_test_logs.push(['add_event', {
184
+ "key": n,
185
+ "count": 1,
186
+ "dur": t,
187
+ "segmentation": customSegments
188
+ }]);
189
+ }
190
+ }
191
+ }
192
+ // ga('send', {hitType:.., ...})
193
+ else if (typeof o === 'object') {
194
+ switch (o.hitType) {
195
+ // ga('send', {'hitType':'event', ..})
196
+ case 'event':
197
+ customSegments = {
198
+ 'category': o.eventCategory
199
+ };
200
+ count = 1;
201
+
202
+ if (o.eventLabel) {
203
+ customSegments.label = o.eventLabel;
204
+ }
205
+ if (o.eventValue) {
206
+ count = o.eventValue;
207
+ }
208
+
209
+ Countly.q.push(['add_event', {
210
+ key: o.eventAction,
211
+ count: count,
212
+ segmentation: customSegments
213
+ }]);
214
+
215
+ if (window.cly_ga_test_mode) {
216
+ window.cly_ga_test_logs.push(['add_event', {
217
+ key: o.eventAction,
218
+ count: count,
219
+ segmentation: customSegments
220
+ }]);
221
+ }
222
+
223
+ break;
224
+ // ga('send', {'hitType':'social', ..})
225
+ case 'social':
226
+ Countly.q.push(['add_event', {
227
+ "key": o.socialAction,
228
+ "count": 1,
229
+ "segmentation": {
230
+ "category": o.hitType,
231
+ "platform": o.socialNetwork,
232
+ "target": o.socialTarget
233
+ }
234
+ }]);
235
+
236
+ if (window.cly_ga_test_mode) {
237
+ window.cly_ga_test_logs.push(['add_event', {
238
+ "key": o.socialAction,
239
+ "count": 1,
240
+ "segmentation": {
241
+ "category": o.hitType,
242
+ "platform": o.socialNetwork,
243
+ "target": o.socialTarget
244
+ }
245
+ }]);
246
+ }
247
+
248
+ break;
249
+ // ga('send', {'hitType':'timing', ..})
250
+ case 'timing':
251
+ Countly.q.push(['add_event', {
252
+ "key": o.timingVar,
253
+ "count": 1,
254
+ "dur": o.timingValue,
255
+ "segmentation": {
256
+ "category": o.timingCategory
257
+ }
258
+ }]);
259
+
260
+ if (window.cly_ga_test_mode) {
261
+ window.cly_ga_test_logs.push(['add_event', {
262
+ "key": o.timingVar,
263
+ "count": 1,
264
+ "dur": o.timingValue,
265
+ "segmentation": {"category": o.timingCategory}
266
+ }]);
267
+ }
268
+ break;
269
+ // ga('send', {'hitType':'pageview', 'page':'page'})
270
+ case 'pageview':
271
+ Countly.q.push(['track_pageview', o.page]);
272
+ if (window.cly_ga_test_mode) {
273
+ window.cly_ga_test_logs.push(['track_pageview', o.page]);
274
+ }
275
+ break;
276
+ }
277
+ }
278
+ break;
279
+ // ga('create', '..')
280
+ case 'create':
281
+ // ga('create', .., 'auto', '..')
282
+ if (arguments.length === 4 && arguments[2] === 'auto') {
283
+ cly._internals.store('cly_ga:id', o);
284
+ if (window.cly_ga_test_mode) {
285
+ window.cly_ga_test_logs.push({
286
+ 'stored': cly._internals.store('cly_ga:id'),
287
+ 'value': o
288
+ });
289
+ }
290
+ window.ga_adapter_integrated = true;
291
+ // ga('create', .., callback)
292
+ }
293
+ else if (arguments.length === 3) {
294
+ cly._internals.store('cly_ga:id', o);
295
+ if (window.cly_ga_test_mode) {
296
+ window.cly_ga_test_logs.push({
297
+ 'stored': cly._internals.store('cly_ga:id'),
298
+ 'value': o
299
+ });
300
+ }
301
+ window.ga_adapter_integrated = true;
302
+ }
303
+ break;
304
+ // ga('set', '..')
305
+ case 'set':
306
+ // ga('set', 'page', '/login.html')
307
+ if (o === 'page') {
308
+ cly._internals.store('cly_ga:page', u);
309
+ }
310
+ // ga('set', 'screenname', 'High scores')
311
+ else if (o === 'screenname') {
312
+ cly._internals.store('cly_ga:screenname', u);
313
+ if (window.cly_ga_test_mode) {
314
+ window.cly_ga_test_logs.push({
315
+ 'stored': cly._internals.store('cly_ga:screenname'),
316
+ 'value': u
317
+ });
318
+ }
319
+ }
320
+ // ga('set', 'dimension', 'custom data')
321
+ else if (arguments.length === 3) {
322
+ Countly.q.push(['userData.set', o, u]);
323
+ if (window.cly_ga_test_mode) {
324
+ window.cly_ga_test_logs.push(['userData.set', o, u]);
325
+ }
326
+ }
327
+ // ga('set', {key:val, anotherKey: anotherVal})
328
+ else if (arguments.length === 2 && typeof o === 'object') {
329
+ Countly.q.push(['user_details', {custom: o}]);
330
+ if (window.cly_ga_test_mode) {
331
+ window.cly_ga_test_logs.push(['user_details', {custom: o}]);
332
+ }
333
+ }
334
+ break;
335
+ // ga('ecommerce:addTransaction', {..})
336
+ case 'ecommerce:addTransaction':
337
+ customSegments = {
338
+ "id": o.id,
339
+ "affiliation": o.affiliation,
340
+ "shipping": o.shipping,
341
+ "tax": o.tax
342
+ };
343
+
344
+ if (o.currency) {
345
+ customSegments.currency = o.currency;
346
+ }
347
+
348
+ Countly.q.push(['add_event', {
349
+ "key": c,
350
+ "count": 1,
351
+ "sum": o.revenue,
352
+ "segmentation": customSegments
353
+ }]);
354
+
355
+ if (window.cly_ga_test_mode) {
356
+ window.cly_ga_test_logs.push(['add_event', {
357
+ "key": c,
358
+ "count": 1,
359
+ "sum": o.revenue,
360
+ "segmentation": customSegments
361
+ }]);
362
+ }
363
+
364
+ break;
365
+ // ga('ecommerce:addItem', {..})
366
+ case 'ecommerce:addItem':
367
+ customSegments = {
368
+ "id": o.id,
369
+ "name": o.name,
370
+ "sku": o.sku,
371
+ "category": o.category
372
+ };
373
+
374
+ if (o.currency) {
375
+ customSegments.currency = o.currency;
376
+ }
377
+
378
+ cart.push(['add_event', {
379
+ "key": c,
380
+ "count": o.quantity,
381
+ "sum": o.price,
382
+ "segmentation": customSegments
383
+ }]);
384
+
385
+ cly._internals.store('cly_ecommerce:cart', cart);
386
+
387
+ if (window.cly_ga_test_mode) {
388
+ window.cly_ga_test_logs.push(['add_event', {
389
+ "key": c,
390
+ "count": o.quantity,
391
+ "sum": o.price,
392
+ "segmentation": customSegments
393
+ }]);
394
+ }
395
+
396
+ break;
397
+ // ga('ecommerce:send')
398
+ case 'ecommerce:send':
399
+ var firstLength;
400
+ if (window.cly_ga_test_mode) {
401
+ firstLength = cart.length;
402
+ }
403
+ for (i = 0; i < cart.length; i++) {
404
+ Countly.q.push(cart[i]);
405
+ }
406
+ cart = [];
407
+ cly._internals.store('cly_ecommerce:cart', cart);
408
+
409
+ if (window.cly_ga_test_mode) {
410
+ window.cly_ga_test_logs.push({first: firstLength, last: cart.length});
411
+ }
412
+ break;
413
+ // ga('ecommerce:clear')
414
+ case 'ecommerce:clear':
415
+ cart = [];
416
+ cly._internals.store('cly_ecommerce:cart', cart);
417
+
418
+ if (window.cly_ga_test_mode) {
419
+ window.cly_ga_test_logs.push(cly._internals.store('cly_ecommerce:cart'));
420
+ }
421
+ break;
422
+ default:
423
+ break;
424
+ }
425
+ }
426
+ };
427
+ // apply old countly calls to overrided function
428
+ while (gaCountlyArray.length) {
429
+ var args = gaCountlyArray.shift();
430
+ ga_countly.apply(window, args);
431
+ }
432
+ });
433
+
434
+ // check variable for gaAdapter is loaded?
435
+ setTimeout(function check() {
436
+ if (window.ga._signature) {
437
+ return setTimeout(check, 125);
438
+ }
439
+ old_ga = window.ga;
440
+
441
+ while (gaCalls.length) {
442
+ var args = gaCalls.shift();
443
+ ga_countly.apply(window, args);
444
+ }
445
+
446
+ window.ga = function() {
447
+ ga_countly.apply(window, arguments);
448
+ return old_ga.apply(this, arguments);
449
+ };
450
+ }, 125);
451
+ };
452
452
  }());