Skip to main content
SDKsWeb

Activity and page tracking

Automatic page views, session and foreground events, and batched activity for the MotiSig web SDK.

The web SDK tracks engagement activity internally: automatic page views from the script tag, and optional session/foreground events via enableActivityTracking. These events are sent to POST /activity/batch and stored with eventCategory: engagement.

Public event() calls always use eventCategory: custom, regardless of event name. You can use any name you like with event(); only the SDK's internal activity batch path records engagement.

Automatic page views (script tag)

When loaded via the script tag (default data-auto-page-view="true"), the SDK sends page.viewed on first load and on every client-side route change (it wraps history.pushState / replaceState and listens for popstate). Each page view is flushed immediately via the activity batch endpoint.

Disable automatic page views with data-auto-page-view="false":

<script
  src="https://motisig.ai/cdn/web/v1/motisig.js"
  data-sdk-key="YOUR_SDK_KEY"
  data-project-id="YOUR_PROJECT_ID"
  data-auto-page-view="false"
  async
></script>

You can also send your own events via event() with any name (for example pricing_page_opened). Those are stored as custom, even if the name matches an SDK activity event like page.viewed.

enableActivityTracking(options?)

Opt-in via window.motisig.enableActivityTracking(...).

window.motisig.enableActivityTracking({
  appOpens: true,        // default true: emits session_start + app_open on enable
  flushIntervalMs: 30_000, // default 30s
});

On enable (when appOpens !== false) the SDK emits:

  • session_start
  • app_open

Then, on tab visibility changes:

  • app_foreground when the tab becomes visible
  • app_background when the tab is hidden

Options

OptionDefaultDescription
appOpenstrueEmit session_start and app_open when tracking starts
flushIntervalMs30000How often the buffered activity batch is flushed
pushReceivedReserved for push activity
pushDismissedReserved for push activity
screenViewsReserved for screen-view activity

Batching

Activity events are buffered and flushed to POST /activity/batch:

  • On the flushIntervalMs timer (default every 30s)
  • Immediately for each page.viewed event
  • When the buffer reaches 20 events
  • On pagehide (tab close / navigation away)

Each batched event carries a sessionId (stable per page session), the resolved client context, and userId or anonymousId. If a flush fails, the batch is re-queued for the next attempt.