Skip to main content
Version: 0.18

Tracking script

This page document Prisme Analytics tracking script configuration options and JavaScript API.

Configuration options

User tracking is done via an ultra light script (< 1kb) tag added to pages of your website. This script is served by Prisme Analytics instances at /static/wa.js. You can consult its content here.

This script is statically served (e.g. no templating) so configuration is done via data-attributes.

Prisme URL (data-prisme-url)

URL used to send event to a Prisme Analytics instance.

Example: data-prisme-url="https://my-prisme-instance.example.com/custom/subpath"

Default to origin of URL used to load the script:

<!-- Events will be send to https://my-prisme-instance.example.com -->
<script src="https://my-prisme-instance.example.com/static/wa.js" defer></script>

Domain (data-domain)

Domain from which events originate. This is mainly useful if you have multiple domains pointing to the same site.

Default is website host (e.g. location.host in javascript).

See https://developer.mozilla.org/en-US/docs/Web/API/Location/host

Example: data-domain="www.example.com"

Path (data-path)

Path of the viewed page. This is useful if you have a lot of dynamic pages with path parameters and you don't want to track them individually.

<script src="https://my-prisme-instance.example.com/static/wa.js" data-path="/products/:product-id" defer></script>

This options is ignored when manual tracking is enabled or a pageview event was already sent using data-path (e.g. second pageview on websites with client side routing).

Manual (data-manual)

Enable manual tracking if value isn't false. When enabled, a pageview method is added to global prisme object.

Visitor ID (data-visitor-id)

Visitor ID to visitor.

warning

Use this option at your own risk, depending on the value used, you may not be GDPR compliant.

Outbound link tracking is monitoring when users click links that take them away from your website to external sites.

Setting this option to false disable outbound links tracking.

File downloads (data-file-downloads)

File downloads tracking is monitoring when users click links with download attribute.

Setting this option to false disable file downloads tracking.

Status code (data-status)

The HTTP status code associated with page view events. Most commonly used to track 404 (Not Found) errors by setting data-status="404" on error pages, helping identify broken links and missing content.

JavaScript API

Prisme expose all of it's public API functions under window.prisme. If you're using tracking script provided

Page views

Page view events are automatically send on page load and when a new entry is pushed to window.history. This should cover static websites and SPA (Single Page Application) using client side routing.

If you enabled manual tracking, you MUST send pageview event manually using window.prisme.pageview.

This function takes a single parameter, an object with the following optional properties:

  • domain: Viewed page domain name. Default to location.host
  • path: Viewed page path. Default to location.pathname
  • visitorId: Unique identifier associated with the session.

NOTE: If you specify a visitor id that allows you to track your visitor over days, you must ask for their consent.

NOTE: Avoid using Personal Identifiable Information (PII) such as an email address as visitors id.

Examples

Send an simple pageview event:

window.prisme.pageview();

Send a pageview event with custom path:

window.prisme.pageview({ path: "/products/:product-id" });

Custom events

Custom events can be send via the window.prisme.trigger function. This function takes two argument:

  • a string: the name of the event
  • an object: key-value pairs or attributes attached to the event.
note

You don't need to include the date, domain or the path of the page in the object as it is automatically added by Prisme server.

tip

It is recommended to avoid nested JSON objects as it may impact performance at query time.

Examples

Send an empty custom event:

window.prisme.trigger("sign_up");

Send a simple custom event:

window.prisme.trigger("checkout", {
plan: "growth",
frequency: "monthly",
});