Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions app/javascript/packages/prompt-on-navigate/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ describe('promptOnNavigate', () => {

window.dispatchEvent(event);

expect(trackEvent).to.have.been.calledOnceWith(PROMPT_EVENT);
expect(trackEvent).to.have.been.calledOnceWith(PROMPT_EVENT, { path: '/' });
trackEvent.resetHistory();

sandbox.clock.tick(2000);
expect(trackEvent).not.to.have.been.called();

sandbox.clock.tick(3000);
expect(trackEvent).to.have.been.calledWith(STILL_ON_PAGE_EVENT, {
path: '/',
seconds: 5,
});
});
Expand All @@ -56,7 +57,7 @@ describe('promptOnNavigate', () => {

window.dispatchEvent(event);

expect(trackEvent).to.have.been.calledOnceWith(PROMPT_EVENT);
expect(trackEvent).to.have.been.calledOnceWith(PROMPT_EVENT, { path: '/' });
trackEvent.resetHistory();

sandbox.clock.tick(5000);
Expand All @@ -65,6 +66,7 @@ describe('promptOnNavigate', () => {

sandbox.clock.tick(10000);
expect(trackEvent).to.have.been.calledWith(STILL_ON_PAGE_EVENT, {
path: '/',
seconds: 15,
});
});
Expand All @@ -91,6 +93,7 @@ describe('promptOnNavigate', () => {

sandbox.clock.tick(15000);
expect(trackEvent).to.have.been.calledWith(STILL_ON_PAGE_EVENT, {
path: '/',
seconds: 30,
});
});
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/packages/prompt-on-navigate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function promptOnNavigate(options: PromptOnNavigateOptions = defaults): (
ev.preventDefault();
ev.returnValue = '';

trackEvent(PROMPT_EVENT);
trackEvent(PROMPT_EVENT, { path: window.location.pathname });

const stillOnPageIntervalsInSeconds = [...options.stillOnPageIntervalsInSeconds];
let elapsed = 0;
Expand All @@ -46,6 +46,7 @@ export function promptOnNavigate(options: PromptOnNavigateOptions = defaults): (

stillOnPageTimer = window.setTimeout(() => {
trackEvent(STILL_ON_PAGE_EVENT, {
path: window.location.pathname,
seconds: elapsed,
});
scheduleNextStillOnPagePing();
Expand Down
9 changes: 7 additions & 2 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3581,18 +3581,23 @@ def user_marked_authed(authentication_type:, **extra)

# User was shown an "Are you sure you want to navigate away from this page?" message from their
# browser (via onbeforeunload). (This is a frontend event.)
def user_prompted_before_navigation
# @param [String] path Path where this event was encountered.
def user_prompted_before_navigation(path:, **extra)
track_event(
'User prompted before navigation',
path: path,
**extra,
)
end

# User was shown an "Are you sure you want to navigate away from this page?" prompt via
# onbeforeunload and was still on the page <seconds> later. (This is a frontend event.)
# @param [String] path Path where this event was encountered.
# @param [Integer] seconds Amount of time user has been on page since prompt.
def user_prompted_before_navigation_and_still_on_page(seconds:, **extra)
def user_prompted_before_navigation_and_still_on_page(path:, seconds:, **extra)
track_event(
'User prompted before navigation and still on page',
path: path,
seconds: seconds,
**extra,
)
Expand Down