Skip to main content

Auto pageview & the tracking API

Once the script is loaded, you have a global JourneyLayer with three methods. Everything is non‑blocking — calls are batched and sent in the background.

Automatic page views

A pageview event fires automatically:

  • on initial page load, and
  • on SPA route changes (history pushState/replaceState/popstate).

You don't call anything. Each pageview captures the URL, path, title, referrer, and device/UTM context. Don't also fire your own pageview — it would double‑count.

JourneyLayer.track(name, properties?)

Record a custom event. Event names are free‑form and auto‑register — no schema to define first.

JourneyLayer.track('Contact Us Submitted', {
name: 'Kishan',
phone: '+91 9999999999',
source_page: location.href,
});
  • name — a human‑readable string. Title Case (Doctor Profile Viewed) is a good convention.
  • properties — any JSON object. Send whatever you'll want to segment and filter on later.

JourneyLayer.identify(traits)

Tie the current visitor to a known person. Call it once you know who they are — after login, or when they submit a form with their email/phone.

JourneyLayer.identify({
identity: '[email protected]', // stable id — usually their email
name: 'Kishan',
phone: '+91 9999999999',
city: 'Delhi',
});

The first non‑null of identity / email / phone becomes the stable identity that stitches the visitor's earlier anonymous activity to them. See Identity merge behavior.

JourneyLayer.reset()

Forget the current identity and start a fresh anonymous id. Call it on logout so the next user on a shared device isn't merged into the previous one.

JourneyLayer.reset();

Guard your calls

The SDK loads asynchronously. If your code might run before it's ready, guard it so the page never breaks:

window.JourneyLayer && JourneyLayer.track('CTA Clicked', { id: 'hero' });

Next

See copy‑paste recipes in Event examples.