New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

countly-sdk-web

Package Overview
Dependencies
Maintainers
3
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

countly-sdk-web - npm Package Compare versions

Comparing version 23.2.0 to 23.2.1

countly-sdk-web-23.02.1.tgz

3

CHANGELOG.md

@@ -0,1 +1,4 @@

## 23.02.1
- Mitigated an issue that could have caused view IDs to be terminated prematurely when using manual sessions and end_session was called abruptly
## 23.02.0

@@ -2,0 +5,0 @@ - Events are now recorded with an internal ID.

91

cypress/integration/consents.js

@@ -17,55 +17,2 @@ /* eslint-disable cypress/no-unnecessary-waiting */

}
// gathered events. count and segmentation key/values must be consistent
const eventArray = [
// first event must be custom event
{
key: "a",
count: 1,
segmentation: {
1: "1"
}
},
// rest can be internal events
{
key: "[CLY]_view",
count: 2,
segmentation: {
2: "2"
}
},
{
key: "[CLY]_nps",
count: 3,
segmentation: {
3: "3"
}
},
{
key: "[CLY]_survey",
count: 4,
segmentation: {
4: "4"
}
},
{
key: "[CLY]_star_rating",
count: 5,
segmentation: {
5: "5"
}
},
{
key: "[CLY]_orientation",
count: 6,
segmentation: {
6: "6"
}
}
];
// event adding loop
function events() {
for (var i = 0, len = eventArray.length; i < len; i++) {
Countly.add_event(eventArray[i]);
}
}

@@ -105,6 +52,6 @@ /**

Countly.add_consent(["events"]);
events();
hp.events();
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(1);
consent_check(eq, eventArray, true);
consent_check(eq, hp.eventArray, true);
});

@@ -116,7 +63,7 @@ });

initMain(true);
Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback"]);
events();
Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "push", "clicks"]);
hp.events();
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(5);
consent_check(eq, eventArray, false, true);
expect(eq.length).to.equal(6);
consent_check(eq, hp.eventArray, false, true);
});

@@ -128,7 +75,7 @@ });

initMain(true);
Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "events"]);
events();
Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "events", "push", "clicks"]);
hp.events();
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(6);
consent_check(eq, eventArray, false, false);
expect(eq.length).to.equal(7);
consent_check(eq, hp.eventArray, false, false);
});

@@ -140,6 +87,6 @@ });

initMain(false);
events();
hp.events();
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(6);
consent_check(eq, eventArray, false, false);
expect(eq.length).to.equal(7);
consent_check(eq, hp.eventArray, false, false);
});

@@ -151,5 +98,5 @@ });

initMain(true);
Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback"]);
Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "push", "clicks"]);
Countly.change_id("Richard Wagner II", false);
events();
hp.events();
cy.fetch_local_event_queue().then((eq) => {

@@ -163,8 +110,8 @@ expect(eq.length).to.equal(0);

initMain(true);
Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback"]);
Countly.add_consent(["sessions", "views", "users", "star-rating", "apm", "feedback", "push", "clicks"]);
Countly.change_id("Richard Wagner the second", true);
events();
hp.events();
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(5);
consent_check(eq, eventArray, false, true);
expect(eq.length).to.equal(6);
consent_check(eq, hp.eventArray, false, true);
});

@@ -171,0 +118,0 @@ });

@@ -19,20 +19,36 @@ // TODO: click and scrolls tests but scrolls first, with html files

describe("Browser heatmap tests, scrolls", () => {
it("Check if scrolls are sent if page url changes", () => {
it("Check if scrolls are sent if page url changes, multi page", () => {
cy.visit("./cypress/fixtures/scroll_test.html");
cy.scrollTo("bottom");
cy.visit("./cypress/fixtures/scroll_test_2.html");
cy.fetch_local_request_queue(hp.appKey).then((rq) => {
cy.log(rq);
// 2 session and 1 orientation 1 event
expect(rq.length).to.equal(4);
// first object of the queue should be about begin session, second is orientation
cy.check_session(rq[0], undefined, undefined, hp.appKey);
cy.check_view_event(JSON.parse(rq[1].events)[1], "/cypress/fixtures/scroll_test.html", undefined, false);
// 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
cy.check_session(rq[2], -0.5, undefined);
// fourth object of the queue should be events in the queue, there must be 4 of them
cy.check_view_event(JSON.parse(rq[3].events)[0], "/cypress/fixtures/scroll_test.html", 0, false);
cy.check_scroll_event(JSON.parse(rq[3].events)[1]);
// number 3 is orientation
cy.check_view_event(JSON.parse(rq[3].events)[3], "/cypress/fixtures/scroll_test_2.html", undefined, false); // new page not new view
hp.waitFunction(hp.getTimestampMs(), 1000, 100, () => {
cy.fetch_local_request_queue(hp.appKey).then((rq) => {
cy.log(rq);
// There should be 4 requests: session -> event batch 1 -> session_duration -> event batch 2
expect(rq.length).to.equal(4);
const beginSessionReq = rq[0];
const eventBatch1 = JSON.parse(rq[1].events);
const sessionDurationReq = rq[2];
const eventBatch2 = JSON.parse(rq[3].events);
// 1st req
cy.check_session(beginSessionReq, undefined, undefined, hp.appKey);
// 2nd req
expect(eventBatch1.length).to.equal(2);
expect(eventBatch1[0].key).to.equal("[CLY]_orientation");
expect(eventBatch1[0].segmentation.mode).to.be.ok;
cy.check_view_event(eventBatch1[1], "/cypress/fixtures/scroll_test.html", undefined, false); // start view
// 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
cy.check_session(sessionDurationReq, -0.5, undefined);
// 4th object of the queue should be events in the queue, there must be 4 of them
expect(eventBatch2.length).to.equal(4);
cy.check_view_event(eventBatch2[0], "/cypress/fixtures/scroll_test.html", 0, false); // end view
cy.check_scroll_event(eventBatch2[1]);
expect(eventBatch2[2].key).to.equal("[CLY]_orientation");
expect(eventBatch2[2].segmentation.mode).to.be.ok;
cy.check_view_event(eventBatch2[3], "/cypress/fixtures/scroll_test_2.html", undefined, false); // new page
});
});

@@ -76,16 +92,27 @@ });

cy.get("#click").click(clickX, clickY);
// its in event queue as we are checking directly after the click
cy.fetch_local_event_queue(hp.appKey).then((rq) => {
cy.log(rq);
expect(rq.length).to.equal(1);
expect(rq[0].key).to.equal("[CLY]_action");
cy.check_commons(rq[0]);
// There should be 3 requests: session -> event batch 1 -> event batch 2
hp.waitFunction(hp.getTimestampMs(), 1000, 100, () => {
cy.fetch_local_request_queue(hp.appKey).then((rq) => {
cy.log(rq);
expect(rq.length).to.equal(3);
const beginSessionReq = rq[0];
const eventBatch1 = JSON.parse(rq[1].events);
const eventBatch2 = JSON.parse(rq[2].events);
const seg = rq[0].segmentation;
click_check(seg, 8, 8);
// 1st req
cy.check_session(beginSessionReq, undefined, undefined, hp.appKey);
// 2nd req
expect(eventBatch1.length).to.equal(2);
expect(eventBatch1[0].key).to.equal("[CLY]_orientation");
expect(eventBatch1[0].segmentation.mode).to.be.ok;
cy.check_view_event(eventBatch1[1], "/cypress/fixtures/click_test.html", undefined, false); // start view
// 3rd req
expect(eventBatch2[0].key).to.equal("[CLY]_action");
cy.check_commons(eventBatch2[0]);
const seg = eventBatch2[0].segmentation;
click_check(seg, 8, 8);
});
});
cy.fetch_local_request_queue(hp.appKey).then((rq) => {
cy.log(rq);
expect(rq.length).to.equal(2);
});
});

@@ -96,10 +123,20 @@ it("Check if the DOM restriction works if non targeted child clicked", () => {

cy.get("#click").click(clickX, clickY);
cy.fetch_local_event_queue(hp.appKey).then((rq) => {
cy.log(rq);
expect(rq.length).to.equal(0);
// There should be 2 requests: session -> event batch 1
hp.waitFunction(hp.getTimestampMs(), 1000, 100, () => {
cy.fetch_local_request_queue(hp.appKey).then((rq) => {
cy.log(rq);
expect(rq.length).to.equal(2);
const beginSessionReq = rq[0];
const eventBatch1 = JSON.parse(rq[1].events);
// 1st req
cy.check_session(beginSessionReq, undefined, undefined, hp.appKey);
// 2nd req
expect(eventBatch1.length).to.equal(2);
expect(eventBatch1[0].key).to.equal("[CLY]_orientation");
expect(eventBatch1[0].segmentation.mode).to.be.ok;
cy.check_view_event(eventBatch1[1], "/cypress/fixtures/click_test.html", undefined, false); // start view
});
});
cy.fetch_local_request_queue(hp.appKey).then((rq) => {
cy.log(rq);
expect(rq.length).to.equal(2);
});
});

@@ -109,24 +146,31 @@ it("Check if the DOM restriction works only the child is clicked", () => {

// only click2 must be perceived
cy.get("#click").click(clickX, clickY).wait(1000);
cy.get("#click2").click(clickX, clickY).wait(1000);
cy.get("#click").click(clickX, clickY);
cy.get("#click2").click(clickX, clickY);
cy.get("#click3").click(clickX, clickY);
cy.fetch_local_event_queue(hp.appKey).then((rq) => {
cy.log(rq);
expect(rq.length).to.equal(0);
});
// as we waited the call is in request queue now
cy.fetch_local_request_queue(hp.appKey).then((rq) => {
cy.log(rq);
// first 2 is session and orientation
expect(rq.length).to.equal(3);
const clickEv = JSON.parse(rq[2].events);
// only single event must exist
expect(clickEv.length).to.equal(1);
expect(clickEv[0].key).to.equal("[CLY]_action");
cy.check_commons(clickEv[0]);
hp.waitFunction(hp.getTimestampMs(), 1000, 100, () => {
// There should be 3 requests: session -> event batch 1 -> event batch 2
cy.fetch_local_request_queue(hp.appKey).then((rq) => {
cy.log(rq);
expect(rq.length).to.equal(3);
const beginSessionReq = rq[0];
const eventBatch1 = JSON.parse(rq[1].events);
const eventBatch2 = JSON.parse(rq[2].events);
const seg = clickEv[0].segmentation;
click_check(seg, 79, 8);
// 1st req
cy.check_session(beginSessionReq, undefined, undefined, hp.appKey);
// 2nd req
expect(eventBatch1.length).to.equal(2);
expect(eventBatch1[0].key).to.equal("[CLY]_orientation");
expect(eventBatch1[0].segmentation.mode).to.be.ok;
cy.check_view_event(eventBatch1[1], "/cypress/fixtures/click_test.html", undefined, false); // start view
// 3rd req
expect(eventBatch2[0].key).to.equal("[CLY]_action");
cy.check_commons(eventBatch2[0]);
const seg = eventBatch2[0].segmentation;
click_check(seg, 80, 8);
});
});
});
});

@@ -10,3 +10,3 @@ /* eslint-disable cypress/no-unnecessary-waiting */

url: "https://try.count.ly",
max_events: -1
test_mode_eq: true
});

@@ -13,0 +13,0 @@ }

@@ -10,3 +10,4 @@ /* eslint-disable cypress/no-unnecessary-waiting */

url: "https://try.count.ly",
max_events: -1
test_mode_eq: true,
test_mode: true
});

@@ -35,3 +36,3 @@ }

sum: 2.97,
dur: 1000,
dur: 300,
segmentation: {

@@ -62,3 +63,3 @@ app_version: "1.0",

});
cy.wait(1000).then(() => {
cy.wait(300).then(() => {
Countly.user_details(userDetailObj);

@@ -81,7 +82,9 @@ cy.fetch_local_request_queue().then((rq) => { // events and user details must be here

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.equal("value");
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.equal("value");
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -95,7 +98,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql(["value"]); // eql is deepequal
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql(["value"]); // eql is deepequal
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -109,7 +114,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.equal("");
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.equal("");
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -123,7 +130,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $setOnce: "value" });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $setOnce: "value" });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -137,7 +146,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $inc: 1 });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $inc: 1 });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -151,7 +162,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $inc: 10 });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $inc: 10 });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -165,7 +178,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $inc: -10 }); // eql is deepequal
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $inc: -10 }); // eql is deepequal
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -179,7 +194,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $inc: "10" });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $inc: "10" });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -193,7 +210,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $mul: 10 });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $mul: 10 });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -207,7 +226,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $mul: -10 });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $mul: -10 });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -221,7 +242,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $mul: "10" });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $mul: "10" });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -235,7 +258,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $max: 10 });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $max: 10 });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -249,7 +274,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $max: "10" });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $max: "10" });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -263,7 +290,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $min: 10 });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $min: 10 });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -277,7 +306,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $min: "10" });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $min: "10" });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -291,7 +322,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $push: [10] });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $push: [10] });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -305,7 +338,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $push: ["10"] });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $push: ["10"] });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -319,7 +354,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $addToSet: [10] });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $addToSet: [10] });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -333,7 +370,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $addToSet: ["10"] });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $addToSet: ["10"] });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -347,7 +386,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $pull: [10] });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $pull: [10] });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -361,7 +402,9 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $pull: ["10"] });
expect(Object.keys(custom).length).to.equal(1);
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(custom.key).to.eql({ $pull: ["10"] });
expect(Object.keys(custom).length).to.equal(1);
});
});

@@ -385,17 +428,19 @@ });

Countly.userData.save();
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(Object.keys(custom).length).to.equal(11);
expect(custom.key).to.equal("value");
expect(custom.key2).to.equal("");
expect(custom.key3).to.eql({ $setOnce: 1 });
expect(custom.key4).to.eql({ $inc: 1 });
expect(custom.key5).to.eql({ $inc: 2 });
expect(custom.key6).to.eql({ $mul: 3 });
expect(custom.key7).to.eql({ $max: 4 });
expect(custom.key8).to.eql({ $min: 5 });
expect(custom.key9).to.eql({ $push: [6] });
expect(custom.key10).to.eql({ $addToSet: [7] });
expect(custom.key11).to.eql({ $pull: [8] });
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(Object.keys(custom).length).to.equal(11);
expect(custom.key).to.equal("value");
expect(custom.key2).to.equal("");
expect(custom.key3).to.eql({ $setOnce: 1 });
expect(custom.key4).to.eql({ $inc: 1 });
expect(custom.key5).to.eql({ $inc: 2 });
expect(custom.key6).to.eql({ $mul: 3 });
expect(custom.key7).to.eql({ $max: 4 });
expect(custom.key8).to.eql({ $min: 5 });
expect(custom.key9).to.eql({ $push: [6] });
expect(custom.key10).to.eql({ $addToSet: [7] });
expect(custom.key11).to.eql({ $pull: [8] });
});
});

@@ -419,10 +464,12 @@ });

Countly.userData.pull("key11", 8);
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(Object.keys(custom).length).to.equal(4);
expect(custom.key).to.equal("value");
expect(custom.key2).to.equal("");
expect(custom.key3).to.eql({ $setOnce: 1 });
expect(custom.key4).to.eql({ $inc: 1 });
hp.waitFunction(hp.getTimestampMs(), 300, 100, () => {
cy.fetch_local_request_queue().then((rq) => {
expect(rq.length).to.equal(1);
const custom = JSON.parse(rq[0].user_details).custom;
expect(Object.keys(custom).length).to.equal(4);
expect(custom.key).to.equal("value");
expect(custom.key2).to.equal("");
expect(custom.key3).to.eql({ $setOnce: 1 });
expect(custom.key4).to.eql({ $inc: 1 });
});
});

@@ -458,3 +505,3 @@ });

});
cy.wait(1000).then(() => {
cy.wait(300).then(() => {
Countly.userData.set("key", "value");

@@ -479,3 +526,3 @@ cy.fetch_local_request_queue().then((rq) => {

});
cy.wait(1000).then(() => {
cy.wait(300).then(() => {
Countly.userData.set("key", "value");

@@ -482,0 +529,0 @@ Countly.userData.save();

@@ -15,2 +15,27 @@ /* eslint-disable cypress/no-unnecessary-waiting */

/**
* Checks if the cvid is the same for all events in the queue but ids are different and pvid is undefined
* @param {string} expectedCvid - expected view id
* @param {Array} eventQ - events queue
* @param {number} startIndex - start index of the queue
* @param {number} endIndex - end index of the queue
*/
function listIdChecker(expectedCvid, eventQ, startIndex, endIndex) {
if (!endIndex || !startIndex || endIndex < startIndex) { // prevent infinite loop
cy.log("Wrong index information");
return;
}
var i = startIndex;
var lastIdList = []; // pool of ids
while (i < endIndex) {
expect(eventQ[i].cvid).to.equal(expectedCvid);
expect(eventQ[i].pvid).to.be.undefined; // there should not be pvid
if (lastIdList.length > 0) {
expect(lastIdList.indexOf(eventQ[i].id)).to.equal(-1); // we check this id against all ids in the list
}
lastIdList.push(eventQ[i].id); // we add this id to the list of ids
i++;
}
}
var pageNameOne = "test view page name1";

@@ -102,3 +127,3 @@ var pageNameTwo = "test view page name2";

//
// request order: view A start -> event A -> view A end -> view B start -> event B -> view B end -> view C start -> event C
// request order: view A start -> internal can custom events -> event A -> view A end -> view B start -> internal can custom events -> event B -> view B end -> view C start -> internal can custom events -> event C
// ===========================

@@ -109,10 +134,14 @@ it("Checks a sequence of events and page views", () => {

Countly.track_view("A");
hp.events(["[CLY]_view"]);
Countly.add_event({ key: "A" });
Countly.track_view("B");
hp.events(["[CLY]_view"]);
Countly.add_event({ key: "B" });
Countly.track_view("C");
hp.events(["[CLY]_view"]);
Countly.add_event({ key: "C" });
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(8);
expect(eq.length).to.equal(26);
cy.log(eq);

@@ -123,18 +152,158 @@

const idA = eq[0].id; // idA
cy.check_event(eq[1], { key: "A" }, undefined, idA); // cvid should be idA
cy.check_view_event(eq[2], "A", 0, false); // no pvid
listIdChecker(idA, eq, 1, 7); // check all internal events in view A
cy.check_event(eq[7], { key: "A" }, undefined, idA); // cvid should be idA
cy.check_view_event(eq[8], "A", 0, false); // no pvid
// event B and view B
cy.check_view_event(eq[3], "B", undefined, idA); // pvid is idA
const idB = eq[3].id; // idB
cy.check_event(eq[4], { key: "B" }, undefined, idB); // cvid should be idB
cy.check_view_event(eq[5], "B", 0, idA); // pvid is idA
cy.check_view_event(eq[9], "B", undefined, idA); // pvid is idA
const idB = eq[9].id; // idB
listIdChecker(idB, eq, 10, 16); // check all internal events in view B
cy.check_event(eq[16], { key: "B" }, undefined, idB); // cvid should be idB
cy.check_view_event(eq[17], "B", 0, idA); // pvid is idA
// event C and view C
cy.check_view_event(eq[6], "C", undefined, idB); // pvid is idB
const idC = eq[6].id; // idC
cy.check_event(eq[7], { key: "C" }, undefined, idC); // cvid should be idC
cy.check_view_event(eq[18], "C", undefined, idB); // pvid is idB
const idC = eq[18].id; // idC
listIdChecker(idC, eq, 19, 25); // check all internal events in view C
cy.check_event(eq[25], { key: "C" }, undefined, idC); // cvid should be idC
});
});
});
// ===========================
// Confirms: CVID | PVID | ID
// ++--------+-----------+-------++
// record events before first view => "" undefined rnd
// record A view => undefined "" idA
// record events under view A => idA undefined rnd
// record A view (close) => undefined "" idA
// record B view => undefined idA idB
// record events under view B => idB undefined rnd
// record B view (close) => undefined idA idB
// record C view => undefined idB idC
// record events under view C => idC undefined rnd
// ++--------+-----------+-------++
// request order: internal can custom events -> view A start -> event A -> view A end -> view B start -> internal can custom events -> event B -> view B end -> view C start -> internal can custom events -> event C
// ===========================
it("Checks a sequence of events and page views, with events before first view", () => {
hp.haltAndClearStorage(() => {
initMain();
hp.events(["[CLY]_view"]); // first events
Countly.track_view("A");
Countly.add_event({ key: "A" });
Countly.track_view("B");
hp.events(["[CLY]_view"]);
Countly.add_event({ key: "B" });
Countly.track_view("C");
hp.events(["[CLY]_view"]);
Countly.add_event({ key: "C" });
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(26);
cy.log(eq);
listIdChecker("", eq, 0, 6); // check all internal events before view A
// event A and view A
cy.check_view_event(eq[6], "A", undefined, false); // no pvid
const idA = eq[6].id; // idA
cy.check_event(eq[7], { key: "A" }, undefined, idA); // cvid should be idA
cy.check_view_event(eq[8], "A", 0, false); // no pvid
// event B and view B
cy.check_view_event(eq[9], "B", undefined, idA); // pvid is idA
const idB = eq[9].id; // idB
listIdChecker(idB, eq, 10, 16); // check all internal events in view B
cy.check_event(eq[16], { key: "B" }, undefined, idB); // cvid should be idB
cy.check_view_event(eq[17], "B", 0, idA); // pvid is idA
// event C and view C
cy.check_view_event(eq[18], "C", undefined, idB); // pvid is idB
const idC = eq[18].id; // idC
listIdChecker(idC, eq, 19, 25); // check all internal events in view C
cy.check_event(eq[25], { key: "C" }, undefined, idC); // cvid should be idC
});
});
});
// check end_session usage
it("Checks a sequence of events and page views, with end_session, no session started", () => {
hp.haltAndClearStorage(() => {
initMain();
hp.events(["[CLY]_view"]); // first events
Countly.end_session(); // no session started must be ignored
Countly.track_view("A");
Countly.add_event({ key: "A" });
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(8);
cy.log(eq);
listIdChecker("", eq, 0, 6); // check all internal events before view A
// event A and view A
cy.check_view_event(eq[6], "A", undefined, false); // no pvid
const idA = eq[6].id; // idA
cy.check_event(eq[7], { key: "A" }, undefined, idA); // cvid should be idA
});
});
});
it("Checks a sequence of events and page views, with end_session, with session started", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.track_sessions();
hp.events(["[CLY]_view"]); // first events
Countly.end_session(); // no view started so must be ignored
Countly.track_view("A");
Countly.add_event({ key: "A" });
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(9); // orientation added
cy.log(eq);
cy.check_event(eq[0], { key: "[CLY]_orientation" }, undefined, ""); // internal event
listIdChecker("", eq, 1, 7); // check all internal events before view A
// event A and view A
cy.check_view_event(eq[7], "A", undefined, false); // no pvid
const idA = eq[7].id; // idA
cy.check_event(eq[8], { key: "A" }, undefined, idA); // cvid should be idA
});
});
});
it("Checks a sequence of events and page views, with end_session, with session started and called after view", () => {
hp.haltAndClearStorage(() => {
initMain();
Countly.track_sessions();
hp.events(["[CLY]_view"]); // first events
Countly.track_view("A");
Countly.end_session(); // no view started so must be ignored
Countly.add_event({ key: "A" });
Countly.track_view("B");
hp.events(["[CLY]_view"]);
cy.fetch_local_event_queue().then((eq) => {
expect(eq.length).to.equal(17); // orientation added
cy.log(eq);
cy.check_event(eq[0], { key: "[CLY]_orientation" }, undefined, ""); // internal event
listIdChecker("", eq, 1, 7); // check all internal events before view A
// event A and view A
cy.check_view_event(eq[7], "A", undefined, false); // no pvid
const idA = eq[7].id; // idA
cy.check_view_event(eq[8], "A", 0, false); // no pvid
cy.check_event(eq[9], { key: "A" }, undefined, idA); // cvid should be idA
cy.check_view_event(eq[10], "B", undefined, idA); // pvid is idA
const idB = eq[10].id; // idB
listIdChecker(idB, eq, 11, 17); // check all internal events in view B
});
});
});
});

@@ -100,2 +100,3 @@ import "./index";

expect(queueObject.id).to.be.ok;
expect(queueObject.pvid).to.be.undefined;
expect(queueObject.id.length).to.equal(21);

@@ -141,2 +142,3 @@ if (hasCvid) {

expect(queueObject.id).to.be.ok;
expect(queueObject.cvid).to.be.undefined;
expect(queueObject.id.length).to.equal(21);

@@ -143,0 +145,0 @@ if (hasPvid) {

@@ -51,2 +51,136 @@ var Countly = require("../../lib/countly");

// gathered events. count and segmentation key/values must be consistent
const eventArray = [
// first event must be custom event
{
key: "a",
count: 1,
segmentation: {
1: "1"
}
},
// rest can be internal events
{
key: "[CLY]_view",
count: 2,
segmentation: {
2: "2"
}
},
{
key: "[CLY]_nps",
count: 3,
segmentation: {
3: "3"
}
},
{
key: "[CLY]_survey",
count: 4,
segmentation: {
4: "4"
}
},
{
key: "[CLY]_star_rating",
count: 5,
segmentation: {
5: "5"
}
},
{
key: "[CLY]_orientation",
count: 6,
segmentation: {
6: "6"
}
},
{
key: "[CLY]_action",
count: 7,
segmentation: {
7: "7"
}
}
];
// event adding loop
/**
* adds events to the queue
* @param {Array} omitList - events to omit from the queue. If not provided, all events will be added. Must be an array of string key values
*/
function events(omitList) {
for (var i = 0, len = eventArray.length; i < len; i++) {
if (omitList) {
if (omitList.indexOf(eventArray[i].key) === -1) {
Countly.add_event(eventArray[i]);
}
}
else {
Countly.add_event(eventArray[i]);
}
}
}
// TODO: this validator is so rigid. Must be modified to be more flexible (accepting more variables)
/**
* Validates requests in the request queue for normal flow test
* @param {Array} rq - request queue
* @param {string} viewName - name of the view
* @param {string} countlyAppKey - app key
*/
function testNormalFlow(rq, viewName, countlyAppKey) {
cy.log(rq);
expect(rq.length).to.equal(8);
const idType = rq[0].t;
const id = rq[0].device_id;
// 1 - 2
expect(rq[0].campaign_id).to.equal("camp_id");
expect(rq[0].campaign_user).to.equal("camp_user_id");
expect(rq[1].campaign_id).to.equal("camp_id");
expect(rq[1].campaign_user).to.equal("camp_user_id");
// 3
const thirdRequest = JSON.parse(rq[2].events);
expect(thirdRequest.length).to.equal(2);
cy.check_event(thirdRequest[0], { key: "test", count: 1, sum: 1, dur: 1, segmentation: { test: "test" } }, undefined, "");
cy.check_event(thirdRequest[0], { key: "test", count: 1, sum: 1, dur: 1, segmentation: { } }, undefined, "");
// 4
const fourthRequest = JSON.parse(rq[3].user_details);
expect(fourthRequest.name).to.equal("name");
expect(fourthRequest.custom).to.eql({});
// 5
const fifthRequest = JSON.parse(rq[4].user_details);
expect(fifthRequest).to.eql({ custom: { set: "set" } });
// 6
const sixthRequest = JSON.parse(rq[5].crash);
expect(sixthRequest._error).to.equal("stack");
// 7
expect(rq[6].begin_session).to.equal(1);
// 8
const eighthRequest = JSON.parse(rq[7].events);
expect(eighthRequest.length).to.equal(2);
cy.check_event(eighthRequest[0], { key: "[CLY]_orientation" }, undefined, "");
cy.check_view_event(eighthRequest[1], viewName, undefined, false);
// each request should have same device id, device id type and app key
rq.forEach(element => {
expect(element.device_id).to.equal(id);
expect(element.t).to.equal(idType);
expect(element.app_key).to.equal(countlyAppKey);
expect(element.metrics).to.be.ok;
expect(element.dow).to.exist;
expect(element.hour).to.exist;
expect(element.sdk_name).to.be.ok;
expect(element.sdk_version).to.be.ok;
expect(element.timestamp).to.be.ok;
});
}
module.exports = {

@@ -59,3 +193,6 @@ haltAndClearStorage,

getTimestampMs,
waitFunction
waitFunction,
events,
eventArray,
testNormalFlow
};

@@ -12,3 +12,3 @@ {

"private": true,
"dependencies": {
"devDependencies": {
"@angular/animations": "~12.2.0",

@@ -24,5 +24,3 @@ "@angular/common": "~12.2.0",

"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"zone.js": "~0.11.4",
"@angular-devkit/build-angular": "~12.2.4",

@@ -41,2 +39,2 @@ "@angular/cli": "~12.2.4",

}
}
}

@@ -6,6 +6,8 @@ {

"dependencies": {
"countly-sdk-web": "^23.02.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^14.2.1",
"countly-sdk-web": "^22.06.1",
"react": "^18.2.0",

@@ -38,2 +40,2 @@ "react-dom": "^18.2.0",

}
}
}

@@ -22,2 +22,2 @@ {

}
}
}
{
"name": "countly-sdk-web",
"version": "23.02.0",
"version": "23.02.1",
"description": "Countly Web SDK",

@@ -5,0 +5,0 @@ "main": "lib/countly.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc