Skip to content

Install with Google Tag Manager

Load the My Journey Analytics web library from your Google Tag Manager container, forward data layer events and identify signed-in users.

If your site already uses Google Tag Manager, you can add My Journey Analytics without changing your site's code. You create one tag that loads the library on every page, and optionally a second tag that passes your data layer events on to us.

To send events from a server container instead, see Server-side Google Tag Manager.

Before you start

You need:

  • your project key and your project's address, both shown with the web snippet in Project settings in the app;
  • permission to edit and publish your Tag Manager web container.

If you use a custom tracking domain, use it as the address: for example https://t.example.com. Otherwise use your region's address, which is https://app.myjourneyanalytics.com for the Australian region.

1. Create two Constant variables

Keeping the key and the address in variables means every tag below uses the same values.

  1. In your container, open Variables and, under User-Defined Variables, click New.
  2. Choose the Constant type, name it MJ Project Key and paste your project key as the value. Save.
  3. Create a second Constant variable named MJ Tracking Domain with your address as the value, starting with https:// and without a trailing slash. Save.

2. Create the loader tag

  1. Open Tags, click New and choose Custom HTML as the tag type.
  2. Name the tag My Journey Analytics - Loader and paste the code below.
  3. Under Triggering, choose All Pages, or Initialization - All Pages to load the library as early as possible.
  4. Save the tag.
html
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.myjourney && window.myjourney.__loaded)||(window.myjourney=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}p||((p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host+"/static/array.js",p.onerror=function(){p=null},(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r));var u=e;for(void 0!==a?u=e[a]=[]:a="myjourney",u.people=u.people||[],Object.defineProperty(u,"toString",{configurable:!0,enumerable:!0,writable:!0,value:function(t){var e="myjourney";return"myjourney"!==a&&(e+="."+a),t||(e+=" (stub)"),e}}),Object.defineProperty(u.people,"toString",{configurable:!0,enumerable:!0,writable:!0,value:function(){return u.toString(1)+".people (stub)"}}),o="init capture getExtension calculateEventProperties register register_once register_for_session unregister unregister_for_session getFeatureFlag getFeatureFlagPayload getFeatureFlagResult getAllFeatureFlags isFeatureEnabled reloadFeatureFlags updateFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSurveysLoaded onSessionId getSurveys getActiveMatchingSurveys onActiveMatchingSurveysChanged renderSurvey displaySurvey cancelPendingSurvey canRenderSurvey canRenderSurveyAsync identify setPersonProperties unsetPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset shutdown setIdentity clearIdentity get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException addExceptionStep captureLog startExceptionAutocapture stopExceptionAutocapture loadToolbar get_property getSessionProperty createPersonProfile setInternalOrTestUser opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing get_explicit_consent_status is_capturing clear_opt_in_out_capturing debug getPageViewId captureTraceFeedback captureTraceMetric".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.myjourney||[]);
myjourney.init({{MJ Project Key}}, {
  api_host: {{MJ Tracking Domain}},
  defaults: '2026-05-30',
  person_profiles: 'identified_only',
  cross_subdomain_cookie: true
});
</script>

The first line is the same loader as the web snippet in Project settings. It defines window.myjourney straight away and queues any calls made before the library has finished loading, so your other tags can call myjourney without waiting.

The start-up options:

OptionWhat it does
api_hostWhere events are sent and the library is loaded from: your tracking domain or your region's address.
defaultsFixes the library's default behaviour to a dated set, so an update never changes what you collect unannounced. Use the date shown in the snippet in Project settings.
person_profiles'identified_only' creates person profiles only for users you identify. Use 'always' to create them for anonymous visitors too.
cross_subdomain_cookieShares the visitor's ID across your subdomains, such as www.example.com and shop.example.com.

3. Forward data layer events (optional)

Pageviews, clicks and form submissions are captured automatically. To also record events your site already pushes to the data layer, such as

js
dataLayer.push({ event: "plan_upgraded", plan: "growth" });

create a forwarder tag:

  1. Create a variable of the Custom Event type named Event Name. It holds the name of the data layer event that fired the tag.
  2. For each value you want to send, create a Data Layer Variable for its key, for example DLV - plan for the key plan.
  3. Create a Custom HTML tag named My Journey Analytics - Forward events with the code below.
  4. Give it a Custom Event trigger that matches the events to forward, for example plan_upgraded|signup_completed with Use regex matching ticked.
  5. Under Advanced Settings → Tag Sequencing, choose to fire My Journey Analytics - Loader before this tag, so the library is always set up first.
html
<script>
  (function () {
    var eventName = {{Event Name}};
    if (!window.myjourney || !eventName) {
      return;
    }
    myjourney.capture(eventName, {
      plan: {{DLV - plan}}
    });
  })();
</script>

List only the properties you want to analyse. Leave out anything personal that you do not need.

4. Identify signed-in users

When your site knows who the visitor is, for example after they sign in, tell the library their ID from your own system. If your site pushes a login event with the user's ID,

js
dataLayer.push({ event: "login", user_id: "user_123", plan: "growth" });

create Data Layer Variables for user_id and plan, and a Custom HTML tag fired by a Custom Event trigger for login, sequenced after the loader as above:

html
<script>
  (function () {
    var userId = {{DLV - user_id}};
    if (!window.myjourney || !userId) {
      return;
    }
    myjourney.identify(userId, { plan: {{DLV - plan}} });
  })();
</script>
  • Events from before the user signed in are linked to the same person.
  • Use a stable ID, such as your database's user ID, not an email address.
  • When the user signs out, call myjourney.reset(); from a tag fired by your sign-out event, so the next person on the same device is not linked to them.

To attach a property to every event the browser sends from now on, rather than to the person, register it:

js
myjourney.register({ site_section: "store" });

More calls are described in the JavaScript web library.

5. Use an existing visitor ID (optional)

If your site or server already gives each visitor a first-party ID in a cookie, the library can start with that ID instead of making its own, so the browser and your server record the visitor under the same ID.

  1. Create a variable of the 1st party cookie type named Visitor ID cookie, reading your cookie.
  2. Replace the myjourney.init(...) call in the loader tag with the code below.
js
var mjOptions = {
  api_host: {{MJ Tracking Domain}},
  defaults: '2026-05-30',
  person_profiles: 'identified_only',
  cross_subdomain_cookie: true
};
var mjVisitorId = {{Visitor ID cookie}};
if (mjVisitorId && document.cookie.indexOf('mj_' + {{MJ Project Key}} + '_mja=') === -1) {
  mjOptions.bootstrap = { distinctID: mjVisitorId };
}
myjourney.init({{MJ Project Key}}, mjOptions);

The check on mj_..._mja, the library's own cookie, starts the visitor with your ID only on their first visit. On later visits the library keeps the ID it has stored, which matters once a visitor has been identified: starting them again from an anonymous ID would undo it.

  • To load the library only after a visitor agrees to analytics, open the loader tag's Advanced Settings → Consent Settings, choose Require additional consent for tag to fire and add analytics_storage. Tag Manager then fires the tag only if that consent is granted when its trigger fires, so choose a trigger that fires after your consent banner has recorded the choice.
  • Alternatively, load the library on every page in the opted-out state by adding opt_out_capturing_by_default: true to the options, and call myjourney.opt_in_capturing(); from a tag that fires when the visitor accepts. Nothing is captured until then.
  • Session replay masks what visitors type by default. To mask page text or leave parts of a page out of recordings, see Privacy and masking.

7. Test and publish

  1. Click Preview, open your site in the Tag Assistant window and check that the loader tag fired on the page.
  2. In the app, open the activity view; your pageview should appear within a minute or so.
  3. When everything looks right, click Submit to publish the container.

If nothing arrives, see the checks at the end of Install the web snippet.

Can't find what you need? Contact support