Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: track time spent on a page #1876

Merged
merged 27 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
db562b0
feat: track time spent on a page
MoumitaM Oct 8, 2024
9c4a494
chore: moved the comment to appt place
MoumitaM Oct 8, 2024
02ffa04
refactor: trackPageLifecycleEvents fn
MoumitaM Oct 9, 2024
5813d01
chore: review comment addressed
MoumitaM Oct 9, 2024
f864f6a
chore: review comment addressed
MoumitaM Oct 9, 2024
eafe04f
chore: review comment addressed
MoumitaM Oct 9, 2024
5615d68
refactor: trackPageLifecycleEvents fn will be called from load api
MoumitaM Oct 14, 2024
e7e41aa
Merge branch 'develop' into feat/SDK-2478-track-timespent-on-a-page
MoumitaM Oct 14, 2024
72555d5
chore: addressed review comment
MoumitaM Oct 14, 2024
a390642
feat: modified load options structure
MoumitaM Oct 14, 2024
40c683c
chore: trackPageLifecycleEvents fn has been refactored and unit tests…
MoumitaM Oct 16, 2024
cc62338
chore: size limit updated
MoumitaM Oct 16, 2024
ab72611
Merge branch 'develop' into feat/SDK-2478-track-timespent-on-a-page
MoumitaM Oct 16, 2024
e4d5492
chore: typo corrected
MoumitaM Oct 16, 2024
6c7e207
chore: unit tests
MoumitaM Oct 17, 2024
8da4e56
Merge branch 'develop' into feat/SDK-2478-track-timespent-on-a-page
MoumitaM Oct 17, 2024
26a26c5
chore: size limit update
MoumitaM Oct 18, 2024
6455d95
chore: addressed review comments
MoumitaM Oct 18, 2024
56b1859
chore: eslint issue fixed
MoumitaM Oct 18, 2024
92b7442
fix: execution of cb when multiplt event listeners are attached
MoumitaM Oct 21, 2024
82fb915
chore: inline doc updated
MoumitaM Oct 21, 2024
6c9a94d
chore: readme updated
MoumitaM Oct 21, 2024
412beeb
Merge branch 'develop' into feat/SDK-2478-track-timespent-on-a-page
MoumitaM Oct 21, 2024
7c97388
chore: unit test added
MoumitaM Oct 22, 2024
90c97ec
Merge branch 'develop' into feat/SDK-2478-track-timespent-on-a-page
MoumitaM Oct 22, 2024
ebcc0c3
chore: unit test updated
MoumitaM Oct 22, 2024
7aea66e
Merge branch 'feat/SDK-2478-track-timespent-on-a-page' of https://git…
MoumitaM Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ npm install @rudderstack/analytics-js --save
```javascript
import { RudderAnalytics } from '@rudderstack/analytics-js';

const rudderanalytics = new RudderAnalytics();
const rudderAnalytics = new RudderAnalytics();
rudderAnalytics.load(<WRITE_KEY>, <DATA_PLANE_URL>, {});

export { rudderanalytics };
export { rudderAnalytics };
```

- **For CJS using the `require` method**:
Expand All @@ -92,7 +92,7 @@ var RudderAnalytics = require('@rudderstack/analytics-js');
const rudderAnalytics = new RudderAnalytics();
rudderAnalytics.load(<WRITE_KEY>, <DATA_PLANE_URL>, {});

exports.rudderanalytics = rudderAnalytics;
exports.rudderAnalytics = rudderAnalytics;
```

### Sample implementations
Expand Down
17 changes: 17 additions & 0 deletions packages/analytics-js-common/__tests__/utilities/page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,21 @@ describe('onPageLeave', () => {

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

it('should fire the callback on beforeunload event on the next tick even when the tab is inactive', () => {
const evCallback = jest.fn();
onPageLeave(evCallback);

setVisibilityState('hidden');
dispatchDocumentEvent('visibilitychange');

dispatchWindowEvent('beforeunload');

expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenNthCalledWith(1, true);
setTimeout(() => {
expect(evCallback).toHaveBeenCalledTimes(1);
expect(evCallback).toHaveBeenNthCalledWith(1, false);
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
}, 0);
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
});
});
6 changes: 6 additions & 0 deletions packages/analytics-js-common/src/utilities/page.ts
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
pageLeft = true;

callback(isAccessible);

// Reset pageLeft on the next tick
// to ensure callback executes for other listeners
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
setTimeout(() => {
pageLeft = false;

Check warning on line 19 in packages/analytics-js-common/src/utilities/page.ts

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-common/src/utilities/page.ts#L19

Added line #L19 was not covered by tests
}, 0);
MoumitaM marked this conversation as resolved.
Show resolved Hide resolved
MoumitaM marked this conversation as resolved.
Show resolved Hide resolved
}

// Catches the unloading of the page (e.g., closing the tab or navigating away).
Expand Down
Loading