Skip to content

Conversation

@tyiuhc
Copy link
Collaborator

@tyiuhc tyiuhc commented Dec 17, 2025

Summary

Support time_on_page page trigger, fired when the end user has been on the page for a specified durationMs.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

@macroscopeapp
Copy link

macroscopeapp bot commented Dec 17, 2025

Add time_on_page trigger and publish time_on_page events via SubscriptionManager.setUpTimeOnPagePublisher in subscriptions.ts

Introduce a time_on_page trigger with timers, initial publish, and activation checks; extend message payloads and PageObject types to support durationMs-based evaluation.

📍Where to Start

Start with SubscriptionManager.setUpTimeOnPagePublisher in subscriptions.ts.

Changes since #242 opened

  • Removed clearTimeout invocation from SubscriptionManager class's setTimeout callback for time_on_page trigger scheduling [945bbbb]
  • Refactored time_on_page trigger mechanism to use message payload-based duration tracking instead of internal state [91f88e1]

Macroscope summarized c6ed9a4.

@promptless
Copy link

promptless bot commented Dec 17, 2025

📝 Documentation updates detected!

Updated existing suggestion: Document new page trigger types for Web Experiment

@stephen-choi-amplitude stephen-choi-amplitude requested a review from a team December 18, 2025 17:49
if (page.trigger_type === 'time_on_page') {
const triggerValue = page.trigger_value as TimeOnPageTriggerValue;
const durationMs = triggerValue.durationMs;
const timeoutId = setTimeout(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. It's missing visibilitychange event handler to reset when the user moves away from the current tab
  2. Q: When there are multiple page objects with the time on page trigger type, are there any potential issues?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. should time on page be cumulative? Or should the trigger be reset to 0 if it has not already fired?
  2. there should not be issues with this, but deduping of page object-triggered actions will be more formally addressed in another PR.

Copy link
Collaborator

@stephen-choi-amplitude stephen-choi-amplitude Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Per tech doc:

The timer resets whenever the user leaves the tab/window and returns

IOW, clear timeout when the current tab is hidden, and restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants