Skip to content

Commit

Permalink
chore(release): pull main into develop post release v3.32.0 (#1839)
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs authored Aug 30, 2024
2 parents 06f6a71 + 943bda6 commit 5b81431
Show file tree
Hide file tree
Showing 43 changed files with 330 additions and 92 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rudderstack/analytics-js-monorepo",
"version": "3.31.0",
"version": "3.32.0",
"private": true,
"description": "Monorepo for RudderStack Analytics JS SDK",
"workspaces": [
Expand Down
7 changes: 7 additions & 0 deletions packages/analytics-js-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

## [3.9.1](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/[email protected]...@rudderstack/[email protected]) (2024-08-28)


### Bug Fixes

* handle blur and focus events to detect page leave ([#1837](https://github.com/rudderlabs/rudder-sdk-js/issues/1837)) ([57e735c](https://github.com/rudderlabs/rudder-sdk-js/commit/57e735ced4fb51ec895fbb196b1b879996cc10dd))

## [3.9.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/[email protected]...@rudderstack/[email protected]) (2024-08-16)


Expand Down
6 changes: 3 additions & 3 deletions packages/analytics-js-common/CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## [3.9.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-common@3.8.1...@rudderstack/[email protected].0) (2024-08-16)
## [3.9.1](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-common@3.9.0...@rudderstack/[email protected].1) (2024-08-28)


### Features
### Bug Fixes

* onboarded XPixel Integration ([#1783](https://github.com/rudderlabs/rudder-sdk-js/issues/1783)) ([cf9b8cc](https://github.com/rudderlabs/rudder-sdk-js/commit/cf9b8cc41de341be781fae3108e4a07f2b553dda))
* handle blur and focus events to detect page leave ([#1837](https://github.com/rudderlabs/rudder-sdk-js/issues/1837)) ([57e735c](https://github.com/rudderlabs/rudder-sdk-js/commit/57e735ced4fb51ec895fbb196b1b879996cc10dd))

59 changes: 58 additions & 1 deletion packages/analytics-js-common/__tests__/utilities/page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('onPageLeave', () => {
document.dispatchEvent(new Event(event));
};

const dispatchWindowEvent = (event: 'beforeunload') => {
const dispatchWindowEvent = (event: 'beforeunload' | 'blur' | 'focus') => {
window.dispatchEvent(new Event(event));
};

Expand All @@ -26,6 +26,17 @@ describe('onPageLeave', () => {

dispatchDocumentEvent('pagehide');
expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenCalledWith(false);
});

it('should fire the callback on pagehide event based on visibility state', () => {
setVisibilityState('hidden');
const evCallback = jest.fn();
onPageLeave(evCallback);

dispatchDocumentEvent('pagehide');
expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenCalledWith(true);
});

it('should fire the callback on beforeunload event', () => {
Expand All @@ -34,6 +45,7 @@ describe('onPageLeave', () => {

dispatchWindowEvent('beforeunload');
expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenCalledWith(false);
});

it('should fire the callback on visibilitychange event', () => {
Expand All @@ -43,6 +55,7 @@ describe('onPageLeave', () => {
setVisibilityState('hidden');
dispatchDocumentEvent('visibilitychange');
expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenCalledWith(true);
});

it('should not fire the callback on visibilitychange event if visibilityState is visible', () => {
Expand All @@ -54,13 +67,31 @@ describe('onPageLeave', () => {
expect(evCallback).not.toHaveBeenCalled();
});

it('should fire the callback on blur event', () => {
const evCallback = jest.fn();
onPageLeave(evCallback);

dispatchWindowEvent('blur');
expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenCalledWith(true);
});

it('should not fire the callback on focus event', () => {
const evCallback = jest.fn();
onPageLeave(evCallback);

dispatchWindowEvent('focus');
expect(evCallback).not.toHaveBeenCalled();
});

it('should not fire the callback twice on pagehide event', () => {
const evCallback = jest.fn();
onPageLeave(evCallback);

dispatchDocumentEvent('pagehide');
dispatchDocumentEvent('pagehide');
expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenCalledWith(false);
});

it('should not fire the callback twice on beforeunload event', () => {
Expand All @@ -70,6 +101,7 @@ describe('onPageLeave', () => {
dispatchWindowEvent('beforeunload');
dispatchWindowEvent('beforeunload');
expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenCalledWith(false);
});

it('should fire the callback only once if even multiple events are fired', () => {
Expand All @@ -81,6 +113,7 @@ describe('onPageLeave', () => {
setVisibilityState('hidden');
dispatchDocumentEvent('visibilitychange');
expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenCalledWith(false);
});

it('should fire the callback reliably when visibility changes multiple times', () => {
Expand All @@ -96,6 +129,23 @@ describe('onPageLeave', () => {
setVisibilityState('hidden');
dispatchDocumentEvent('visibilitychange');
expect(evCallback).toHaveBeenCalledTimes(2);

expect(evCallback).toHaveBeenNthCalledWith(1, true);
expect(evCallback).toHaveBeenNthCalledWith(2, true);
});

it('should fire the callback reliably when blur and focus events are fired multiple times', () => {
const evCallback = jest.fn();
onPageLeave(evCallback);

dispatchWindowEvent('blur');
dispatchWindowEvent('focus');
dispatchWindowEvent('blur');
dispatchWindowEvent('focus');
expect(evCallback).toHaveBeenCalledTimes(2);

expect(evCallback).toHaveBeenNthCalledWith(1, true);
expect(evCallback).toHaveBeenNthCalledWith(2, true);
});

it('should fire the callback on pagehide event even after multiple visibility changes happen', () => {
Expand All @@ -110,6 +160,9 @@ describe('onPageLeave', () => {

dispatchDocumentEvent('pagehide');
expect(evCallback).toHaveBeenCalledTimes(2);

expect(evCallback).toHaveBeenNthCalledWith(1, true);
expect(evCallback).toHaveBeenNthCalledWith(2, false);
});

it('should fire the callback on beforeunload event even after multiple visibility changes happen', () => {
Expand All @@ -124,5 +177,9 @@ describe('onPageLeave', () => {

dispatchWindowEvent('beforeunload');
expect(evCallback).toHaveBeenCalledTimes(2);

expect(evCallback).toHaveBeenNthCalledWith(1, true);

expect(evCallback).toHaveBeenNthCalledWith(2, false);
});
});
2 changes: 1 addition & 1 deletion packages/analytics-js-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rudderstack/analytics-js-common",
"version": "3.9.0",
"version": "3.9.1",
"private": true,
"description": "RudderStack JavaScript SDK common code",
"module": "dist/npm/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/analytics-js-common/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
"github": {
"executor": "@jscutlery/semver:github",
"options": {
"tag": "@rudderstack/[email protected].0",
"title": "@rudderstack/[email protected].0",
"discussion-category": "@rudderstack/[email protected].0",
"tag": "@rudderstack/[email protected].1",
"title": "@rudderstack/[email protected].1",
"discussion-category": "@rudderstack/[email protected].1",
"notesFile": "./packages/analytics-js-common/CHANGELOG_LATEST.md"
}
}
Expand Down
25 changes: 21 additions & 4 deletions packages/analytics-js-common/src/utilities/page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const onPageLeave = (callback: (...args: unknown[]) => void) => {
const onPageLeave = (callback: (isAccessible: boolean) => void) => {
// To ensure the callback is only called once even if more than one events
// are fired at once.
let pageLeft = false;
let isAccessible = false;

function handleOnLeave() {
if (pageLeft) {
Expand All @@ -10,21 +11,37 @@ const onPageLeave = (callback: (...args: unknown[]) => void) => {

pageLeft = true;

callback();
callback(isAccessible);
}

// Catches the unloading of the page (e.g., closing the tab or navigating away).
// Includes user actions like clicking a link, entering a new URL,
// refreshing the page, or closing the browser tab
// Note that 'pagehide' is not supported in IE.
// So, this is a fallback.
(globalThis as typeof window).addEventListener('beforeunload', handleOnLeave);
(globalThis as typeof window).addEventListener('beforeunload', () => {
isAccessible = false;
handleOnLeave();
});

(globalThis as typeof window).addEventListener('blur', () => {
isAccessible = true;
handleOnLeave();
});

(globalThis as typeof window).addEventListener('focus', () => {
pageLeft = false;
});

// Catches the page being hidden, including scenarios like closing the tab.
document.addEventListener('pagehide', handleOnLeave);
document.addEventListener('pagehide', () => {
isAccessible = document.visibilityState === 'hidden';
handleOnLeave();
});

// Catches visibility changes, such as switching tabs or minimizing the browser.
document.addEventListener('visibilitychange', () => {
isAccessible = true;
if (document.visibilityState === 'hidden') {
handleOnLeave();
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/analytics-js-cookies/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

## [0.3.7](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/[email protected]...@rudderstack/[email protected]) (2024-08-28)

### Dependency Updates

* `@rudderstack/analytics-js-common` updated to version `3.9.1`
## [0.3.6](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/[email protected]...@rudderstack/[email protected]) (2024-08-16)

### Dependency Updates
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics-js-cookies/CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## [0.3.6](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/[email protected].5...@rudderstack/[email protected].6) (2024-08-16)
## [0.3.7](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/[email protected].6...@rudderstack/[email protected].7) (2024-08-28)

### Dependency Updates

* `@rudderstack/analytics-js-common` updated to version `3.9.0`
* `@rudderstack/analytics-js-common` updated to version `3.9.1`
2 changes: 1 addition & 1 deletion packages/analytics-js-cookies/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rudderstack/analytics-js-cookies",
"version": "0.3.6",
"version": "0.3.7",
"description": "RudderStack JavaScript SDK Cookies Utilities",
"main": "dist/npm/modern/cjs/index.cjs",
"module": "dist/npm/modern/esm/index.mjs",
Expand Down
6 changes: 3 additions & 3 deletions packages/analytics-js-cookies/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
"github": {
"executor": "@jscutlery/semver:github",
"options": {
"tag": "@rudderstack/[email protected].6",
"title": "@rudderstack/[email protected].6",
"discussion-category": "@rudderstack/[email protected].6",
"tag": "@rudderstack/[email protected].7",
"title": "@rudderstack/[email protected].7",
"discussion-category": "@rudderstack/[email protected].7",
"notesFile": "./packages/analytics-js-cookies/CHANGELOG_LATEST.md"
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/analytics-js-integrations/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).

## [3.8.1](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/[email protected]...@rudderstack/[email protected]) (2024-08-28)

### Dependency Updates

* `@rudderstack/analytics-js-common` updated to version `3.9.1`
## [3.8.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/[email protected]...@rudderstack/[email protected]) (2024-08-16)

### Dependency Updates
Expand Down
Loading

0 comments on commit 5b81431

Please sign in to comment.