countly-sdk-web 23.2.0 → 23.2.2

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.
package/.eslintignore CHANGED
@@ -1,5 +1,4 @@
1
1
  lib/countly.min.js
2
- lib/countly.pack.js
3
2
  plugin/boomerang/boomerang.min.js
4
3
  examples/react
5
4
  examples/symbolication
@@ -10,7 +9,5 @@ node_modules
10
9
  CHANGELOG.md
11
10
  cypress.json
12
11
  generateDocs.sh
13
- inch.json
14
12
  jsdoc_conf.json
15
- LICENSE
16
- webpack.config.js
13
+ LICENSE
package/.eslintrc.js CHANGED
@@ -18,6 +18,7 @@ module.exports = {
18
18
  "comma-dangle": "off",
19
19
  "no-restricted-globals": "off",
20
20
  "no-restricted-properties": "off",
21
+ strict: "off",
21
22
  //
22
23
  "no-unused-vars": "warn",
23
24
  "no-var": "off",
@@ -28,8 +28,5 @@ jobs:
28
28
  - name: Install dependencies
29
29
  run: npm install --legacy-peer-deps
30
30
 
31
- - name: Build project (if present)
32
- run: npm run build --if-present
33
-
34
31
  - name: Run tests
35
32
  run: npm test
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 23.2.2
2
+ - Default max segmentation value count changed from 30 to 100
3
+
4
+ ## 23.02.1
5
+ - Mitigated an issue that could have caused view IDs to be terminated prematurely when using manual sessions and end_session was called abruptly
6
+
1
7
  ## 23.02.0
2
8
  - Events are now recorded with an internal ID.
3
9
  - Mitigated an issue where users could have truncate an internal event key
package/README.md CHANGED
@@ -12,8 +12,7 @@ and [desktop](https://countly.com/desktop-analytics) applications. [Ensuring pri
12
12
 
13
13
  Track, measure, and take action - all without leaving Countly.
14
14
 
15
- * **Slack user?** [Join our Slack Community](https://slack.count.ly)
16
- * **Questions or feature requests?** [Post in our Community Forum](https://support.count.ly/hc/en-us/community/topics)
15
+ * **Questions or feature requests?** [Join the Countly Community on Discord](https://discord.gg/countly)
17
16
  * **Looking for the Countly Server?** [Countly Community Edition repository](https://github.com/Countly/countly-server)
18
17
  * **Looking for other Countly SDKs?** [An overview of all Countly SDKs for mobile, web and desktop](https://support.count.ly/hc/en-us/articles/360037236571-Downloading-and-Installing-SDKs#officially-supported-sdks)
19
18
 
@@ -56,6 +55,6 @@ If you like Countly, [why not use one of our badges](https://countly.com/brand-g
56
55
  ```
57
56
 
58
57
  ## How can I help you with your efforts?
59
- Glad you asked! We need ideas, feedback and constructive comments. All your suggestions will be taken care of with utmost importance. For feature requests and engaging with the community, join [our Slack Community](https://slack.count.ly) or [Community Forum](https://support.count.ly/hc/en-us/community/topics).
58
+ Glad you asked! For community support, feature requests, and engaging with the Countly Community, please join us at [our Discord Server](https://discord.gg/countly). We're excited to have you there!
60
59
 
61
- We are on [Twitter](https://twitter.com/gocountly), [Facebook](https://www.facebook.com/Countly) and [LinkedIn](https://www.linkedin.com/company/countly) if you would like to keep up with Countly related updates.
60
+ Also, we are on [Twitter](https://twitter.com/gocountly) and [LinkedIn](https://www.linkedin.com/company/countly) if you would like to keep up with Countly related updates.
Binary file
@@ -9,6 +9,7 @@ module.exports = {
9
9
  "cypress/no-assigning-return-values": "error",
10
10
  "cypress/no-unnecessary-waiting": "off",
11
11
  "cypress/assertion-before-screenshot": "warn",
12
+ "cypress/unsafe-to-chain-command": "warn",
12
13
  "cypress/no-force": "warn",
13
14
  "cypress/no-async-tests": "error",
14
15
  "cypress/no-pause": "error",
@@ -0,0 +1,161 @@
1
+ <html>
2
+ <head>
3
+ <script type='text/javascript' src='../../lib/countly.js'></script>
4
+ <script type='text/javascript' src='../support/integration_helper.js'></script>
5
+ <script type='text/javascript'>
6
+ // here we implement a cookie and localStorage clearing logic
7
+ const deleteAllCookies = () => {
8
+ const cookies = document.cookie.split(";");
9
+ for (const cookie of cookies) {
10
+ const eqPos = cookie.indexOf("=");
11
+ const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
12
+ document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
13
+ }
14
+ }
15
+ window.localStorage.clear();
16
+ deleteAllCookies();
17
+ console.error("cleared the storage");
18
+
19
+ // ==================================================
20
+ // synchronously
21
+ // ==================================================
22
+ //initializing first instance, which will be global Countly
23
+ Countly.init({
24
+ app_key: "YOUR_APP_KEY1",
25
+ url: "https://try.count.ly",
26
+ test_mode: true
27
+ })
28
+ Countly.remove_consent();
29
+ Countly.disable_offline_mode();
30
+ Countly.add_event({ key: "test", count: 1, sum: 1, dur: 1, segmentation: { test: "test" } });
31
+ Countly.start_event("test");
32
+ Countly.cancel_event("gobbledygook");
33
+ Countly.end_event("test");
34
+ Countly.report_conversion("camp_id", "camp_user_id");
35
+ Countly.recordDirectAttribution("camp_id", "camp_user_id");
36
+ Countly.user_details({ name: "name" });
37
+ Countly.userData.set("set", "set");
38
+ Countly.userData.save();
39
+ Countly.report_trace({ name: "name", stz: 1, type: "type" });
40
+ Countly.log_error({ error: "error", stack: "stack" });
41
+ Countly.add_log("error");
42
+ Countly.fetch_remote_config();
43
+ Countly.enrollUserToAb();
44
+ Countly.track_sessions();
45
+ Countly.track_pageview();
46
+ Countly.track_errors();
47
+ Countly.track_clicks();
48
+ Countly.track_scrolls();
49
+ Countly.track_links();
50
+ Countly.track_forms();
51
+ Countly.collect_from_forms();
52
+ Countly.collect_from_facebook();
53
+ Countly.opt_in();
54
+
55
+ //initialize second instance for another app synchronously
56
+ var Countly2 = Countly.init({
57
+ app_key: "YOUR_APP_KEY2", //must have different APP key
58
+ url: "https://try.count.ly",
59
+ test_mode: true
60
+
61
+ });
62
+ Countly2.remove_consent();
63
+ Countly2.disable_offline_mode();
64
+ Countly2.add_event({ key: "test", count: 1, sum: 1, dur: 1, segmentation: { test: "test" } });
65
+ Countly2.start_event("test");
66
+ Countly2.cancel_event("gobbledygook");
67
+ Countly2.end_event("test");
68
+ Countly2.report_conversion("camp_id", "camp_user_id");
69
+ Countly2.recordDirectAttribution("camp_id", "camp_user_id");
70
+ Countly2.user_details({ name: "name" });
71
+ Countly2.userData.set("set", "set");
72
+ Countly2.userData.save();
73
+ Countly2.report_trace({ name: "name", stz: 1, type: "type" });
74
+ Countly2.log_error({ error: "error", stack: "stack" });
75
+ Countly2.add_log("error");
76
+ Countly2.fetch_remote_config();
77
+ Countly2.enrollUserToAb();
78
+ Countly2.track_sessions();
79
+ Countly2.track_pageview();
80
+ Countly2.track_errors();
81
+ Countly2.track_clicks();
82
+ Countly2.track_scrolls();
83
+ Countly2.track_links();
84
+ Countly2.track_forms();
85
+ Countly2.collect_from_forms();
86
+ Countly2.collect_from_facebook();
87
+ Countly2.opt_in();
88
+
89
+ // ==================================================
90
+ // asynchronously
91
+ // ==================================================
92
+ //initialize third instance for another app asynchronously
93
+ Countly.q.push(["init", {
94
+ app_key: "YOUR_APP_KEY3", //must have different APP key
95
+ url: "https://try.count.ly",
96
+ test_mode: true
97
+
98
+ }])
99
+ Countly.q.push(["YOUR_APP_KEY3", "remove_consent"]);
100
+ Countly.q.push(["YOUR_APP_KEY3", "disable_offline_mode"]);
101
+ Countly.q.push(["YOUR_APP_KEY3", "add_event", { key: "test", count: 1, sum: 1, dur: 1, segmentation: { test: "test" } }]);
102
+ Countly.q.push(["YOUR_APP_KEY3", "start_event", "test"]);
103
+ Countly.q.push(["YOUR_APP_KEY3", "cancel_event", "gobbledygook"]);
104
+ Countly.q.push(["YOUR_APP_KEY3", "end_event", "test"]);
105
+ Countly.q.push(["YOUR_APP_KEY3", "report_conversion", "camp_id", "camp_user_id"]);
106
+ Countly.q.push(["YOUR_APP_KEY3", "recordDirectAttribution", "camp_id", "camp_user_id"]);
107
+ Countly.q.push(["YOUR_APP_KEY3", "user_details", { name: "name" }]);
108
+ Countly.q.push(["YOUR_APP_KEY3", "userData.set", "set", "set"]);
109
+ Countly.q.push(["YOUR_APP_KEY3", "userData.save"]);
110
+ Countly.q.push(["YOUR_APP_KEY3", "report_trace", { name: "name", stz: 1, type: "type" }]);
111
+ Countly.q.push(["YOUR_APP_KEY3", "log_error", { error: "error", stack: "stack" }]);
112
+ Countly.q.push(["YOUR_APP_KEY3", "add_log", "error"]);
113
+ Countly.q.push(["YOUR_APP_KEY3", "fetch_remote_config"]);
114
+ Countly.q.push(["YOUR_APP_KEY3", "enrollUserToAb"]);
115
+ Countly.q.push(["YOUR_APP_KEY3", "track_sessions"]);
116
+ Countly.q.push(["YOUR_APP_KEY3", "track_pageview"]);
117
+ Countly.q.push(["YOUR_APP_KEY3", "track_errors"]);
118
+ Countly.q.push(["YOUR_APP_KEY3", "track_clicks"]);
119
+ Countly.q.push(["YOUR_APP_KEY3", "track_scrolls"]);
120
+ Countly.q.push(["YOUR_APP_KEY3", "track_links"]);
121
+ Countly.q.push(["YOUR_APP_KEY3", "track_forms"]);
122
+ Countly.q.push(["YOUR_APP_KEY3", "collect_from_forms"]);
123
+ Countly.q.push(["YOUR_APP_KEY3", "collect_from_facebook"]);
124
+ Countly.q.push(["YOUR_APP_KEY3", "opt_in"]);
125
+
126
+ //initialize fourth instance for another app asynchronously
127
+ Countly.q.push(["init", {
128
+ app_key: "YOUR_APP_KEY4", //must have different APP key
129
+ url: "https://try.count.ly",
130
+ test_mode: true
131
+
132
+ }])
133
+ Countly.q.push(["YOUR_APP_KEY4", "remove_consent"]);
134
+ Countly.q.push(["YOUR_APP_KEY4", "disable_offline_mode"]);
135
+ Countly.q.push(["YOUR_APP_KEY4", "add_event", { key: "test", count: 1, sum: 1, dur: 1, segmentation: { test: "test" } }]);
136
+ Countly.q.push(["YOUR_APP_KEY4", "start_event", "test"]);
137
+ Countly.q.push(["YOUR_APP_KEY4", "cancel_event", "gobbledygook"]);
138
+ Countly.q.push(["YOUR_APP_KEY4", "end_event", "test"]);
139
+ Countly.q.push(["YOUR_APP_KEY4", "report_conversion", "camp_id", "camp_user_id"]);
140
+ Countly.q.push(["YOUR_APP_KEY4", "recordDirectAttribution", "camp_id", "camp_user_id"]);
141
+ Countly.q.push(["YOUR_APP_KEY4", "user_details", { name: "name" }]);
142
+ Countly.q.push(["YOUR_APP_KEY4", "userData.set", "set", "set"]);
143
+ Countly.q.push(["YOUR_APP_KEY4", "userData.save"]);
144
+ Countly.q.push(["YOUR_APP_KEY4", "report_trace", { name: "name", stz: 1, type: "type" }]);
145
+ Countly.q.push(["YOUR_APP_KEY4", "log_error", { error: "error", stack: "stack" }]);
146
+ Countly.q.push(["YOUR_APP_KEY4", "add_log", "error"]);
147
+ Countly.q.push(["YOUR_APP_KEY4", "fetch_remote_config"]);
148
+ Countly.q.push(["YOUR_APP_KEY4", "enrollUserToAb"]);
149
+ Countly.q.push(["YOUR_APP_KEY4", "track_sessions"]);
150
+ Countly.q.push(["YOUR_APP_KEY4", "track_pageview"]);
151
+ Countly.q.push(["YOUR_APP_KEY4", "track_errors"]);
152
+ Countly.q.push(["YOUR_APP_KEY4", "track_clicks"]);
153
+ Countly.q.push(["YOUR_APP_KEY4", "track_scrolls"]);
154
+ Countly.q.push(["YOUR_APP_KEY4", "track_links"]);
155
+ Countly.q.push(["YOUR_APP_KEY4", "track_forms"]);
156
+ Countly.q.push(["YOUR_APP_KEY4", "collect_from_forms"]);
157
+ Countly.q.push(["YOUR_APP_KEY4", "collect_from_facebook"]);
158
+ Countly.q.push(["YOUR_APP_KEY4", "opt_in"]);
159
+ </script>
160
+ </head>
161
+ </html>
@@ -14,59 +14,6 @@ function initMain(consent) {
14
14
  debug: true
15
15
  });
16
16
  }
17
- // gathered events. count and segmentation key/values must be consistent
18
- const eventArray = [
19
- // first event must be custom event
20
- {
21
- key: "a",
22
- count: 1,
23
- segmentation: {
24
- 1: "1"
25
- }
26
- },
27
- // rest can be internal events
28
- {
29
- key: "[CLY]_view",
30
- count: 2,
31
- segmentation: {
32
- 2: "2"
33
- }
34
- },
35
- {
36
- key: "[CLY]_nps",
37
- count: 3,
38
- segmentation: {
39
- 3: "3"
40
- }
41
- },
42
- {
43
- key: "[CLY]_survey",
44
- count: 4,
45
- segmentation: {
46
- 4: "4"
47
- }
48
- },
49
- {
50
- key: "[CLY]_star_rating",
51
- count: 5,
52
- segmentation: {
53
- 5: "5"
54
- }
55
- },
56
- {
57
- key: "[CLY]_orientation",
58
- count: 6,
59
- segmentation: {
60
- 6: "6"
61
- }
62
- }
63
- ];
64
- // event adding loop
65
- function events() {
66
- for (var i = 0, len = eventArray.length; i < len; i++) {
67
- Countly.add_event(eventArray[i]);
68
- }
69
- }
70
17
 
71
18
  /**
72
19
  * Checks a queue object for valid/correct values/limits during consent tests
@@ -101,51 +48,51 @@ describe("Consent tests", () => {
101
48
  hp.haltAndClearStorage(() => {
102
49
  initMain(true);
103
50
  Countly.add_consent(["events"]);
104
- events();
51
+ hp.events();
105
52
  cy.fetch_local_event_queue().then((eq) => {
106
53
  expect(eq.length).to.equal(1);
107
- consent_check(eq, eventArray, true);
54
+ consent_check(eq, hp.eventArray, true);
108
55
  });
109
56
  });
110
57
  });
111
58
  it("All but custom event should be sent to the queue", () => {
112
59
  hp.haltAndClearStorage(() => {
113
60
  initMain(true);
114
- Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback"]);
115
- events();
61
+ Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "push", "clicks"]);
62
+ hp.events();
116
63
  cy.fetch_local_event_queue().then((eq) => {
117
- expect(eq.length).to.equal(5);
118
- consent_check(eq, eventArray, false, true);
64
+ expect(eq.length).to.equal(6);
65
+ consent_check(eq, hp.eventArray, false, true);
119
66
  });
120
67
  });
121
68
  });
122
69
  it("All consents given and all events should be recorded", () => {
123
70
  hp.haltAndClearStorage(() => {
124
71
  initMain(true);
125
- Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "events"]);
126
- events();
72
+ Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "events", "push", "clicks"]);
73
+ hp.events();
127
74
  cy.fetch_local_event_queue().then((eq) => {
128
- expect(eq.length).to.equal(6);
129
- consent_check(eq, eventArray, false, false);
75
+ expect(eq.length).to.equal(7);
76
+ consent_check(eq, hp.eventArray, false, false);
130
77
  });
131
78
  });
132
79
  });
133
80
  it("No consent required and all events should be recorded", () => {
134
81
  hp.haltAndClearStorage(() => {
135
82
  initMain(false);
136
- events();
83
+ hp.events();
137
84
  cy.fetch_local_event_queue().then((eq) => {
138
- expect(eq.length).to.equal(6);
139
- consent_check(eq, eventArray, false, false);
85
+ expect(eq.length).to.equal(7);
86
+ consent_check(eq, hp.eventArray, false, false);
140
87
  });
141
88
  });
142
89
  });
143
90
  it("Non-merge ID change should reset all consents", () => {
144
91
  hp.haltAndClearStorage(() => {
145
92
  initMain(true);
146
- Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback"]);
93
+ Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "push", "clicks"]);
147
94
  Countly.change_id("Richard Wagner II", false);
148
- events();
95
+ hp.events();
149
96
  cy.fetch_local_event_queue().then((eq) => {
150
97
  expect(eq.length).to.equal(0);
151
98
  });
@@ -154,12 +101,12 @@ describe("Consent tests", () => {
154
101
  it("Merge ID change should not reset consents", () => {
155
102
  hp.haltAndClearStorage(() => {
156
103
  initMain(true);
157
- Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback"]);
104
+ Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "push", "clicks"]);
158
105
  Countly.change_id("Richard Wagner the second", true);
159
- events();
106
+ hp.events();
160
107
  cy.fetch_local_event_queue().then((eq) => {
161
- expect(eq.length).to.equal(5);
162
- consent_check(eq, eventArray, false, true);
108
+ expect(eq.length).to.equal(6);
109
+ consent_check(eq, hp.eventArray, false, true);
163
110
  });
164
111
  });
165
112
  });
@@ -16,24 +16,40 @@ function click_check(segmentation, offX, offY) {
16
16
  }
17
17
 
18
18
  describe("Browser heatmap tests, scrolls", () => {
19
- it("Check if scrolls are sent if page url changes", () => {
19
+ it("Check if scrolls are sent if page url changes, multi page", () => {
20
20
  cy.visit("./cypress/fixtures/scroll_test.html");
21
21
  cy.scrollTo("bottom");
22
22
  cy.visit("./cypress/fixtures/scroll_test_2.html");
23
- cy.fetch_local_request_queue(hp.appKey).then((rq) => {
24
- cy.log(rq);
25
- // 2 session and 1 orientation 1 event
26
- expect(rq.length).to.equal(4);
27
- // first object of the queue should be about begin session, second is orientation
28
- cy.check_session(rq[0], undefined, undefined, hp.appKey);
29
- cy.check_view_event(JSON.parse(rq[1].events)[1], "/cypress/fixtures/scroll_test.html", undefined, false);
30
- // third object of the queue should be about session extension, also input the expected duration range, we expect 0 here so we enter a value lower than that but not deviated more than 1
31
- cy.check_session(rq[2], -0.5, undefined);
32
- // fourth object of the queue should be events in the queue, there must be 4 of them
33
- cy.check_view_event(JSON.parse(rq[3].events)[0], "/cypress/fixtures/scroll_test.html", 0, false);
34
- cy.check_scroll_event(JSON.parse(rq[3].events)[1]);
35
- // number 3 is orientation
36
- cy.check_view_event(JSON.parse(rq[3].events)[3], "/cypress/fixtures/scroll_test_2.html", undefined, false); // new page not new view
23
+ hp.waitFunction(hp.getTimestampMs(), 1000, 100, () => {
24
+ cy.fetch_local_request_queue(hp.appKey).then((rq) => {
25
+ cy.log(rq);
26
+ // There should be 4 requests: session -> event batch 1 -> session_duration -> event batch 2
27
+ expect(rq.length).to.equal(4);
28
+ const beginSessionReq = rq[0];
29
+ const eventBatch1 = JSON.parse(rq[1].events);
30
+ const sessionDurationReq = rq[2];
31
+ const eventBatch2 = JSON.parse(rq[3].events);
32
+
33
+ // 1st req
34
+ cy.check_session(beginSessionReq, undefined, undefined, hp.appKey);
35
+
36
+ // 2nd req
37
+ expect(eventBatch1.length).to.equal(2);
38
+ expect(eventBatch1[0].key).to.equal("[CLY]_orientation");
39
+ expect(eventBatch1[0].segmentation.mode).to.be.ok;
40
+ cy.check_view_event(eventBatch1[1], "/cypress/fixtures/scroll_test.html", undefined, false); // start view
41
+
42
+ // 3rd object of the req queue should be about session extension, also input the expected duration range, we expect 0 here so we enter a value lower than that but not deviated more than 1
43
+ cy.check_session(sessionDurationReq, -0.5, undefined);
44
+
45
+ // 4th object of the queue should be events in the queue, there must be 4 of them
46
+ expect(eventBatch2.length).to.equal(4);
47
+ cy.check_view_event(eventBatch2[0], "/cypress/fixtures/scroll_test.html", 0, false); // end view
48
+ cy.check_scroll_event(eventBatch2[1]);
49
+ expect(eventBatch2[2].key).to.equal("[CLY]_orientation");
50
+ expect(eventBatch2[2].segmentation.mode).to.be.ok;
51
+ cy.check_view_event(eventBatch2[3], "/cypress/fixtures/scroll_test_2.html", undefined, false); // new page
52
+ });
37
53
  });
38
54
  });
39
55
  it("Check if scrolls are sent if for single page apps/sites", () => {
@@ -72,57 +88,85 @@ describe("Browser heatmap tests, clicks", () => {
72
88
  it("Check if the clicks are send", () => {
73
89
  cy.visit("./cypress/fixtures/click_test.html");
74
90
  cy.get("#click").click(clickX, clickY);
75
- // its in event queue as we are checking directly after the click
76
- cy.fetch_local_event_queue(hp.appKey).then((rq) => {
77
- cy.log(rq);
78
- expect(rq.length).to.equal(1);
79
- expect(rq[0].key).to.equal("[CLY]_action");
80
- cy.check_commons(rq[0]);
81
-
82
- const seg = rq[0].segmentation;
83
- click_check(seg, 8, 8);
84
- });
85
- cy.fetch_local_request_queue(hp.appKey).then((rq) => {
86
- cy.log(rq);
87
- expect(rq.length).to.equal(2);
91
+ // There should be 3 requests: session -> event batch 1 -> event batch 2
92
+ hp.waitFunction(hp.getTimestampMs(), 1000, 100, () => {
93
+ cy.fetch_local_request_queue(hp.appKey).then((rq) => {
94
+ cy.log(rq);
95
+ expect(rq.length).to.equal(3);
96
+ const beginSessionReq = rq[0];
97
+ const eventBatch1 = JSON.parse(rq[1].events);
98
+ const eventBatch2 = JSON.parse(rq[2].events);
99
+
100
+ // 1st req
101
+ cy.check_session(beginSessionReq, undefined, undefined, hp.appKey);
102
+
103
+ // 2nd req
104
+ expect(eventBatch1.length).to.equal(2);
105
+ expect(eventBatch1[0].key).to.equal("[CLY]_orientation");
106
+ expect(eventBatch1[0].segmentation.mode).to.be.ok;
107
+ cy.check_view_event(eventBatch1[1], "/cypress/fixtures/click_test.html", undefined, false); // start view
108
+
109
+ // 3rd req
110
+ expect(eventBatch2[0].key).to.equal("[CLY]_action");
111
+ cy.check_commons(eventBatch2[0]);
112
+ const seg = eventBatch2[0].segmentation;
113
+ click_check(seg, 8, 8);
114
+ });
88
115
  });
89
116
  });
90
117
  it("Check if the DOM restriction works if non targeted child clicked", () => {
91
118
  cy.visit("./cypress/fixtures/click_test.html?dom=click2");
92
119
  // this click must be ignored as it is not click2
93
120
  cy.get("#click").click(clickX, clickY);
94
- cy.fetch_local_event_queue(hp.appKey).then((rq) => {
95
- cy.log(rq);
96
- expect(rq.length).to.equal(0);
97
- });
98
- cy.fetch_local_request_queue(hp.appKey).then((rq) => {
99
- cy.log(rq);
100
- expect(rq.length).to.equal(2);
121
+ // There should be 2 requests: session -> event batch 1
122
+ hp.waitFunction(hp.getTimestampMs(), 1000, 100, () => {
123
+ cy.fetch_local_request_queue(hp.appKey).then((rq) => {
124
+ cy.log(rq);
125
+ expect(rq.length).to.equal(2);
126
+ const beginSessionReq = rq[0];
127
+ const eventBatch1 = JSON.parse(rq[1].events);
128
+
129
+ // 1st req
130
+ cy.check_session(beginSessionReq, undefined, undefined, hp.appKey);
131
+
132
+ // 2nd req
133
+ expect(eventBatch1.length).to.equal(2);
134
+ expect(eventBatch1[0].key).to.equal("[CLY]_orientation");
135
+ expect(eventBatch1[0].segmentation.mode).to.be.ok;
136
+ cy.check_view_event(eventBatch1[1], "/cypress/fixtures/click_test.html", undefined, false); // start view
137
+ });
101
138
  });
102
139
  });
103
140
  it("Check if the DOM restriction works only the child is clicked", () => {
104
141
  cy.visit("./cypress/fixtures/click_test.html?dom=click2");
105
142
  // only click2 must be perceived
106
- cy.get("#click").click(clickX, clickY).wait(1000);
107
- cy.get("#click2").click(clickX, clickY).wait(1000);
143
+ cy.get("#click").click(clickX, clickY);
144
+ cy.get("#click2").click(clickX, clickY);
108
145
  cy.get("#click3").click(clickX, clickY);
109
- cy.fetch_local_event_queue(hp.appKey).then((rq) => {
110
- cy.log(rq);
111
- expect(rq.length).to.equal(0);
112
- });
113
- // as we waited the call is in request queue now
114
- cy.fetch_local_request_queue(hp.appKey).then((rq) => {
115
- cy.log(rq);
116
- // first 2 is session and orientation
117
- expect(rq.length).to.equal(3);
118
- const clickEv = JSON.parse(rq[2].events);
119
- // only single event must exist
120
- expect(clickEv.length).to.equal(1);
121
- expect(clickEv[0].key).to.equal("[CLY]_action");
122
- cy.check_commons(clickEv[0]);
123
-
124
- const seg = clickEv[0].segmentation;
125
- click_check(seg, 79, 8);
146
+ hp.waitFunction(hp.getTimestampMs(), 1000, 100, () => {
147
+ // There should be 3 requests: session -> event batch 1 -> event batch 2
148
+ cy.fetch_local_request_queue(hp.appKey).then((rq) => {
149
+ cy.log(rq);
150
+ expect(rq.length).to.equal(3);
151
+ const beginSessionReq = rq[0];
152
+ const eventBatch1 = JSON.parse(rq[1].events);
153
+ const eventBatch2 = JSON.parse(rq[2].events);
154
+
155
+ // 1st req
156
+ cy.check_session(beginSessionReq, undefined, undefined, hp.appKey);
157
+
158
+ // 2nd req
159
+ expect(eventBatch1.length).to.equal(2);
160
+ expect(eventBatch1[0].key).to.equal("[CLY]_orientation");
161
+ expect(eventBatch1[0].segmentation.mode).to.be.ok;
162
+ cy.check_view_event(eventBatch1[1], "/cypress/fixtures/click_test.html", undefined, false); // start view
163
+
164
+ // 3rd req
165
+ expect(eventBatch2[0].key).to.equal("[CLY]_action");
166
+ cy.check_commons(eventBatch2[0]);
167
+ const seg = eventBatch2[0].segmentation;
168
+ click_check(seg, 80, 8);
169
+ });
126
170
  });
127
171
  });
128
172
  });
@@ -0,0 +1,60 @@
1
+ var Countly = require("../../lib/countly");
2
+ var hp = require("../support/helper");
3
+
4
+ /**
5
+ * init countly
6
+ */
7
+ function initMain() {
8
+ Countly.init({
9
+ app_key: "YOUR_APP_KEY",
10
+ url: "https://try.count.ly",
11
+ debug: true,
12
+ test_mode: true
13
+ });
14
+ }
15
+
16
+ describe("Integration test", () => {
17
+ it("int, no consent, no offline_mode", () => {
18
+ initMain();
19
+ const idType = Countly.get_device_id_type();
20
+ const id = Countly.get_device_id();
21
+ const consentStatus = Countly.check_any_consent();
22
+ Countly.remove_consent();
23
+ Countly.disable_offline_mode();
24
+ Countly.add_event({ key: "test", count: 1, sum: 1, dur: 1, segmentation: { test: "test" } });
25
+ Countly.start_event("test");
26
+ Countly.cancel_event("gobbledygook");
27
+ Countly.end_event("test");
28
+ Countly.report_conversion("camp_id", "camp_user_id");
29
+ Countly.recordDirectAttribution("camp_id", "camp_user_id");
30
+ Countly.user_details({ name: "name" });
31
+ Countly.userData.set("set", "set");
32
+ Countly.userData.save();
33
+ Countly.report_trace({ name: "name", stz: 1, type: "type" });
34
+ Countly.log_error({ error: "error", stack: "stack" });
35
+ Countly.add_log("error");
36
+ Countly.fetch_remote_config();
37
+ Countly.enrollUserToAb();
38
+ const remote = Countly.get_remote_config();
39
+ Countly.track_sessions();
40
+ Countly.track_pageview();
41
+ Countly.track_errors();
42
+ Countly.track_clicks();
43
+ Countly.track_scrolls();
44
+ Countly.track_links();
45
+ Countly.track_forms();
46
+ Countly.collect_from_forms();
47
+ Countly.collect_from_facebook();
48
+ Countly.opt_in();
49
+ // TODO: widgets
50
+ // TODO: make better
51
+ cy.fetch_local_request_queue().then((rq) => {
52
+ cy.log(rq);
53
+ hp.testNormalFlow(rq, "/__cypress/iframes/integration%2Fintegration.js", hp.appKey);
54
+ expect(consentStatus).to.equal(true); // no consent necessary
55
+ expect(remote).to.eql({}); // deepEqual
56
+ expect(rq[0].device_id).to.equal(id);
57
+ expect(rq[0].t).to.equal(idType);
58
+ });
59
+ });
60
+ });
@@ -0,0 +1,25 @@
1
+ /* eslint-disable require-jsdoc */
2
+ var hp = require("../support/helper");
3
+
4
+ describe("Multi instancing tests", () => {
5
+ it("Check if request queue has the correct info", () => {
6
+ cy.visit("./cypress/fixtures/multi_instance.html");
7
+ hp.waitFunction(hp.getTimestampMs(), 1000, 100, () => {
8
+ cy.fetch_local_request_queue(hp.appKey + "1").then((rq) => {
9
+ cy.fetch_local_request_queue(hp.appKey + "2").then((rq2) => {
10
+ cy.fetch_local_request_queue(hp.appKey + "3").then((rq3) => {
11
+ cy.fetch_local_request_queue(hp.appKey + "4").then((rq4) => {
12
+ hp.testNormalFlow(rq, "/cypress/fixtures/multi_instance.html", hp.appKey + "1");
13
+ hp.testNormalFlow(rq2, "/cypress/fixtures/multi_instance.html", hp.appKey + "2");
14
+ hp.testNormalFlow(rq3, "/cypress/fixtures/multi_instance.html", hp.appKey + "3");
15
+ hp.testNormalFlow(rq4, "/cypress/fixtures/multi_instance.html", hp.appKey + "4");
16
+ expect(rq[0].device_id).to.not.equal(rq2[0].device_id);
17
+ expect(rq3[0].device_id).to.not.equal(rq4[0].device_id);
18
+ expect(rq[0].device_id).to.not.equal(rq3[0].device_id);
19
+ });
20
+ });
21
+ });
22
+ });
23
+ });
24
+ });
25
+ });