Skip to content

Configuring the JavaScript library

Start-up options for the web library — pageviews, autocapture, session replay masking, storage, privacy and filtering events before they are sent.

The web library works without any configuration beyond the snippet. When you need to change what it collects, add options to the myjourney.init call inside the snippet.

js
myjourney.init("<your project token>", {
  api_host: "https://app.myjourneyanalytics.com",
  defaults: "2026-05-30",
  person_profiles: "identified_only",
  // your extra options go here
});

Keep the token, api_host and defaults exactly as the snippet in Settings → Project → General shows them. To change an option after start-up, call myjourney.set_config({ ... }).

Some behaviour is also controlled from the app, in Settings → Project. Where both exist, the sections below say which one wins.

The defaults date

The defaults option fixes the library's default behaviour to a dated set, so a library update never changes what you collect without you choosing it. With the date in the current snippet, the library:

  • records a pageview on page load and each time the page's path changes in a single-page app;
  • marks visits from localhost and 127.0.0.1 as an internal test user.

Pageviews and page leaves

OptionDefaultWhat it does
capture_pageview'history_change'true records only the first pageview of each page load; false records none, so you send $pageview yourself.
capture_pageleave'if_capture_pageview'Records $pageleave when pageviews are being recorded. true or false to choose yourself.

Autocapture

Autocapture records clicks, changes and form submissions as $autocapture events. See Autocapture for what it records and how to exclude elements.

OptionWhat it does
autocapture: falseTurns autocapture off in this browser.
autocapture: { url_allowlist: [...] }Captures only on pages whose address matches one of the strings or regular expressions.
autocapture: { url_ignorelist: [...] }Never captures on matching pages.
autocapture: { dom_event_allowlist: ["click"] }Limits autocapture to some of click, change and submit.
autocapture: { css_selector_allowlist: [...] }Captures only elements that match one of the CSS selectors.
autocapture: { element_attribute_ignorelist: [...] }Leaves the named attributes out of autocapture events.
mask_all_textLeaves element text out of autocapture events.
mask_all_element_attributesLeaves element attributes out of autocapture events.
rageclickRecords $rageclick when someone clicks the same place repeatedly. On by default; false turns it off.
capture_dead_clickstrue records clicks that change nothing on the page.

Turning off Enable autocapture for web in Settings → Project → Autocapture stops autocapture for the whole project, whatever the code says.

Session replay

Recording starts only when Record user sessions is on in Settings → Project → Session replay. In code:

OptionWhat it does
disable_session_recording: trueNever records in this browser. Use myjourney.startSessionRecording() to start recording yourself.
session_recording: { maskAllInputs: true }Masks everything typed into fields.
session_recording: { maskTextSelector: "*" }Masks the text of matching elements; "*" masks all text.
session_recording: { blockSelector: ".payment-form" }Leaves matching elements out of recordings.

Masking options set in code take priority over Privacy and masking in the app. See Session replay.

Other features

OptionWhat it does
capture_heatmapstrue or false to record heatmap data from this browser, overriding the project setting.
capture_exceptionstrue records uncaught errors and unhandled promise rejections as $exception events; false stops it. Left out, the project's Exception autocapture setting decides.
disable_surveys: trueNever loads or shows surveys in this browser.

Storage and cookies

The library keeps the visitor's ID, session and super properties in the browser.

OptionDefaultWhat it does
persistence'localStorage+cookie'Where to store them: 'localStorage+cookie', 'localStorage', 'cookie', 'sessionStorage' or 'memory' (nothing kept between page loads).
cross_subdomain_cookietrueShares the cookie across your subdomains, such as www.example.com and shop.example.com. It is off automatically on herokuapp.com, vercel.app and netlify.app subdomains.
cookie_expiration365How many days the cookie lasts.
secure_cookietrue on HTTPS pagesSets the cookie's Secure flag.

What the library stores, for your cookie policy:

NameHolds
mj_<project token>_mjaThe visitor's ID, session and super properties.
__mj_opt_in_out_<project token>The visitor's opt-in or opt-out choice.
OptionWhat it does
opt_out_capturing_by_default: trueCaptures nothing until you call myjourney.opt_in_capturing().
respect_dnt: trueCaptures nothing in browsers that send Do Not Track or Global Privacy Control.
property_denylist: ["$referrer"]Removes the named properties from every event before it is sent.
mask_personal_data_properties: trueMasks advertising click IDs such as gclid and fbclid in captured addresses. Add your own query parameter names with custom_personal_data_properties.

To stop storing visitors' IP addresses for the whole project, turn on Discard client IP data in Settings → Project → Privacy.

Edit or drop events before they are sent

before_send runs on every event just before it leaves the browser. Return the event, changed or not, to send it, or null to drop it.

js
myjourney.init("<your project token>", {
  // ...the snippet's options...
  before_send: (event) => {
    if (event && event.properties.$current_url?.includes("/admin")) {
      return null; // never send events from admin pages
    }
    return event;
  },
});

You can pass an array of functions; they run in order, and any one returning null drops the event.

Sessions

session_idle_timeout_seconds sets how long a visitor can be idle before their next event starts a new session. The default is 1800 (30 minutes); values from 60 seconds to 10 hours are accepted. See Sessions.

Start with a known ID

bootstrap starts the library with an ID you already have, for example one your server set for the visitor:

js
bootstrap: { distinctID: "visitor_abc" },

Add isIdentifiedID: true when the ID is a signed-in user's ID rather than an anonymous one. Use an existing visitor ID shows how to do this only on a visitor's first page load.

Run code once the library has loaded

js
loaded: (myjourney) => {
  // the library is ready, for example:
  // myjourney.register({ app_version: "3.2.0" });
},

Can't find what you need? Contact support