Tracking code

Website session tracking allows you to:

  • Track both anonymous and known activity on your website and store, and

  • Display capture widgets to visitors.

If you have configured any of the e-commerce data source integrations through the Data sources page, then Ortto session tracking functionality is configured automatically.
Therefore, you do not need to configure the tracking code below for these types of data sources.

Configure the tracking code in your data source

By default a website session tracking code is created for all Ortto accounts. This can be found by navigating to Data sources and selecting the tracking code data source (it will usually be named after your account/instance).

You can find installation instructions by clicking on the tracking code data source. There is an option to copy the code or email the instructions to a developer.

If you have more than one tracking subdomain enabled in your account, you will have the option to select the subdomain to include in the tracking code. Learn more about tracking subdomains in Custom domains.

domain select

If you’re using one of the data sources listed above, the tracking code will automatically be installed (e.g. into your theme.liquid file for Shopify) and will work automatically. No additional setup is required.

The website session tracking works similar to Google Analytics. We recommend adding this code using Google Tag Manager (GTM) or in the <head> …​ </head> section of the HTML on your website.

User session association

User sessions are identified using activities that help with identification, for example:

  • Email clicks;

  • Capture forms;

  • Starting a checkout in Shopify; and

  • Session association in the tracking code.

To associate a known user session by email address replace the default:

ap3c.track({v: 0});

with the following to your tracking code:

ap3c.track({"v":0,"email":"user@emaildomain.com","first":"John","last":"Apple"});

To associate a known user session by external ID replace the default ap3c.track({v: 0}); with the following in your tracking code:

ap3c.track({"v":0,"ei":"ID4674","first":"John","last":"Apple"});

Skip non-existing contacts

If you have configured your tracking code to identify a person/contact by their email addresses but you only want to associate user sessions with contacts that already exist in your CDP (not create new contacts), you can add a skipNonExisting parameter set to true. For example:

ap3c.track({email: "contact@example.com", skipNonExisting: true});

Add a callback for user association

You can add a callback function to ensure that user session association does not get interrupted by other actions or activities. For example, a person performs an action on your website that triggers a custom activity, such as submitting a donation which creates an event for your "Donation received" custom activity.

Adding a callback function will ensure that Ortto can capture both the user association and the custom activity event. Without the callback you may encounter a race condition where the activity function is called before the user association can occur, which may result in contacts missing the custom activity event.

So instead of structuring the track and custom activity functions like this:

ap3c.track({v: 0});
ap3c.activity(act);

structure it like this to ensure that user association has been achieved when the activity function is called:

ap3c.track({email: "contact@example.com"}, func(){
  ap3c.activity(act);
});

Activities created from the website session tracking code

There are two activities that come from the website session tracking:

  • Website session, and

  • User session.

A website session is activity for both anonymous and known sessions. It can be used to report on all website sessions. Each session is limited to 50 pages per session and has a minimum time out of 15 minutes, and a maximum 12 hour session time out. We automatically suppress the website session activity in people and organization contact profiles, so you will only see user sessions because they are associated. Website session activities can be used in reports and for filtering people based on activity in your customer data platform (CDP).

A user session is activity of known sessions. It is a duplicate of a website session activity but associated with a known user (contact) in your database. It has the same limitations of 50 pages per session and has a minimum time out of 15 minutes, and a maximum 12 hour session time out.

If a user association happens during an anonymous session, anonymous activities that occurred within the last 15 minutes will be recorded against the known user (contact). For example, a person who browses your site (anonymously) then signs in will have their anonymous session (web session) data prior to sign-in backfilled (as a user session) once their identifying data has been provided and they become a known user.

Both website session and user session activities will appear after a minimum time out of 15 minutes. The session must conclude and timeout before the activity will be generated.

Tracking across multiple domains

If you use the same tracking code in multiple domains, we recommend sharing the tracking code’s session ID across domains. Doing so will track an individual user (known or anonymous) as they navigate across your domains, such as from your .com domain to your .app domain. This will help avoid a break in the UTM tracking or avoid separate sessions being created for the user.

Usually, Ortto stores session data inside the website cookies to identify and associate the current browsing session with a user. As cross-domain cookies are generally prohibited by modern browsers, you’ll need to use a query parameter to share the session ID between sites.

To share the session ID between domains, append query parameter ap3c=${ap3c.getCookie()} to your website’s redirect function. This will ensure that the cookie from site 1 (mybrand.com) is appended as a query parameter in the page redirect. So when the user visits site 2 (mybrand.app) the tracking code will automatically detect and use the session from site 1 available in the query parameter and continue to track the user’s session (all session activities will be counted within the same session).

Here is an example of the query parameter appended to a site redirect function:

location.href = 'www.mybrand.com?ap3c=${ap3c.getCookie()}';

The ap3c.getCookie() function is provided by Ortto’s tracking code to return the user’s session ID.