Skip to content
Optima docs
Guides

Track your website

Create a tracking key, install the Web SDK, map page views to events, add a consent banner and check that events arrive.

This guide takes a website from nothing to page views arriving in Optima as events, with visitors asked for consent first. It uses the Web SDK; the code itself is covered in the Web SDK guide.

Before you start

  • You need the integration_editor role for Tracking, content_editor for the consent banner, and data_viewer to check the result, or another role your administrator has given access to these areas — see Licences and roles.
  • The consent banner needs the consent banner feature of the Digital package. Tracking itself needs no extra licence feature.
  • Your schema has an entity type for visitors, with an identifier that can hold the browser's device id (for example visitor with device_id), and an event type page_view. Add them under Settings → Workspace → Schema if they are missing; see Schema.
  • The consent purposes you want to ask about exist, for example analytics and marketing, with a consent policy that has an active version. See Privacy.
  • You can edit the pages of your website, or ask someone who can.

Step 1: Decide what the site may send

  1. Open Tracking in the Data group. It opens on the Settings tab.
  2. Choose the Web tracking entity, for example visitor, and the Web device identifier key, for example device_id.
  3. Set Public base URL to the public address of your Optima host, as your developer or administrator gives it. The install snippet and the confirmation links are built from it.
  4. Choose a Consent mode. Optional stores hits whatever consent they declare, which is a good start while you test. Require drops hits that do not declare the Required purposes you pick.
  5. Pick the Collection purposes, the purposes stamped on what is stored.
  6. Select Save. The change reaches the public side within about 30 seconds.
The Tracking screen on the Settings tab, with the web and mobile tracking entity, identify allowlists, consent mode and public base URL

Everything is an allowlist: what you do not list here is dropped. Every setting is described in Tracking.

Step 2: Create an SDK key

  1. Open the SDK keys tab and select New SDK key.
  2. Enter a Name, for example Kupko shop. Leave Platform on Web.
  3. Under Allowed origins add every address the site is served from, with scheme and host and no path, for example https://www.kupko.example.
  4. Save.

The key is public by design: it can be read in the page source. The allowed origins and the allowlist from step 1 are what protect you. See SDK keys.

Step 3: Map page views to events

Only mapped categories become events.

  1. In the SDK keys tab, select Snippet on your key. The dialog also offers Create recommended mappings, which creates a page_view mapping for the URL, referrer, title, session and campaign fields. Select it. It is disabled with a reason if there is no page_view event type or the mapping already exists.
  2. Or open the Category mappings tab, select New mapping, and enter Category page_view, choose the Event type page_view, and map $context.url to the event's url attribute and $context.title to title.

Step 4: Install the SDK

  1. With the Snippet dialog still open (or reopened), choose Auto-init (recommended) and select Copy. The snippet already holds your key and your host.
  2. Paste it into the head of every page, or into your site template.
<script async src="…the address from the snippet…"
        data-key="…your key…"
        data-page="auto"></script>

data-page="auto" sends a page_view for every page load. If your pages must call the SDK before it has loaded, use Command queue (buffers calls made before the SDK loads) instead. Configuration, events, identifying signed-in visitors and single-page sites are covered in the Web SDK guide.

The Install snippet dialog for a web SDK key with the Auto-init and Command queue snippets and the Create recommended mappings button

You have two choices. Keep the consent platform you already use and let Optima read its answer, or show an Optima consent banner. This guide shows the banner.

  1. Open On-site in the Engage group. On the Digital content screen select New content item.
  2. Set Type to Consent banner and choose the Slot your site asks for. Your developer knows the slot name.
  3. Under Purposes the banner asks about pick analytics and marketing, or leave Ask about every purpose visible in the preference centre on.
  4. Fill the Banner copy for the Default language: Title, Body and the button texts.
  5. Choose the Policy. It is frozen into the banner when you save and recorded on every consent receipt.
  6. Save the item, then select Publish on its row. Only published items are served.
The content item dialog for a consent banner, with purposes, banner copy per language, consent policy, layout and custom style

If you use a consent platform instead, open the Consent & CMP tab of Tracking, set CMP signal mode to Observe, map its tokens in the Purpose map, and switch to Enforce once the Signal coverage shows nearly all traffic carrying a signal. See Consent banner and CMP.

Step 6: Check that it worked

  1. Open the site in a browser and, if the banner appears, answer it. Browse two or three pages.
  2. Open Events in the Data group. Set Event type to page_view, set Source if you know it, and select Look up. Events for your visits should appear within a minute, newest first.
  3. Select the event type badge to open Event detail. url and title should hold the page you visited.
  4. Select the profile in the Profile column to open the visitor's profile. On Consent & Privacy the consents you gave in the banner are listed with their receipts.
The Events screen with filters for event type, profile ID, source and time range above a table of events

Common problems

  • Nothing shows up in Events. The category has no mapping, the mapping is inactive, or the event type has none of the attributes you mapped. Check Category mappings. Also confirm the snippet is on the page and the browser console shows no refused request.
  • The browser refuses the request. The site's address is missing from Allowed origins. Add the exact scheme, host and port.
  • Hits are dropped. Consent mode is Require and the visitor did not grant every required purpose. Switch to Optional while testing.
  • The banner never appears. The item is not published, is outside its schedule, or its URL targeting does not match the page.
  • The snippet shows a placeholder host. Set the Public base URL on the Settings tab.

Next steps

On this page