Website Tracking
Deploy Analytics.js on your website using the File Builder to start collecting user interactions and page views.
Overview
Collect user behavior data directly from the page using MetaRouter's first-party JS tag. Our tag runs on your domain, giving you full control over data collection with built-in consent management and identity enrichment capabilities.
Already collecting web events with an existing event stream? Consider using the Streaming API instead.
Deploying Website Tracking
MetaRouter website tracking requires two components working together to collect and transmit your user behavior data:
JS Tracking Tag
A lightweight snippet added to your page's <head> section. This tag initializes the tracking library and loads your Analytics.js file.
- •Loads asynchronously to avoid blocking page render
- •Configures your write key and data endpoint
- •Queues events until the full library loads
Analytics.js File
The core tracking library containing your configuration, consent logic, and identity enrichment settings. This file can be hosted in two ways:
- •Your CDN — Host the file on your own infrastructure for complete first-party control
- •Inline on page — Embed directly in your HTML for single-request loading
First-Party Advantage: By hosting Analytics.js on your own domain, all tracking requests appear as first-party traffic, improving data accuracy and avoiding ad-blocker interference.
JS Tracking Tag
The tracking tag is a small JavaScript snippet that you add to every page you want to track. It should be placed in the <head> section of your HTML, as high as possible to ensure early initialization.
What the Tag Does
The tag is responsible for reading and understanding the consent preferences stored by your compliance tool in a cookie on the page. Using this information, the tag fires identity syncs with vendors where compliance allows. Identity syncs are only performed if compliance allows and if the identifier is either absent or has gone stale.
Additionally, the tag sets an anonymousId first-party cookie — a browser-specific identifier that may be used to support user tracking if you wish. It is a randomly generated ID and contains nothing specific to the user.
Once compliance is read and identity syncs are performed (or timeout), event tracking begins. The tracked events are only the ones specifically called by one of the tracking methods below, and all events are enriched with the consent and identity data collected on the page.
Note on Non-Consented Data
Unless you configure the tag to be blocked for compliance or other reasons, the tag will fire events even in situations where the user has opted out of all categories. This data is sent to the processing cluster and not to a downstream destination unless you configure the platform to do so. Some use cases allow for the collection of "non-consented" data for limited internal usage or for anonymized trend tracking.
Additionally, the anonymousId cookie is set regardless of compliance as it contains no user-specific information and is only a "tracking" identifier if you use it as such. Should you need this cookie to not set unless a specific compliance preference has been chosen, please contact your MetaRouter Rep for a custom configuration.
You may wish to consult with your legal team before configuring and implementing this solution. MetaRouter is designed to enforce your compliance preferences, not define them. Read more about consent in the Compliance section →
Analytics.js Hosting Options
The Analytics.js file contains your complete tracking configuration including consent settings, identity resolution rules, and any custom middleware. You have two options for hosting this file:
CDN / Self-Hosting (Recommended)
Download and host the file on your own CDN or web server. This gives you full control over caching, versioning, and deployment.
- • Full cache control
- • Independent deployment cycles
- • Easy rollback capability
Cluster Edge Hosting
Upload directly to your MetaRouter cluster edge. The file is served from your cluster's CDN infrastructure.
- • No infrastructure setup required
- • Managed by MetaRouter
- • Automatic edge distribution
Building Your Files
Both the JS Tag and Analytics.js file are generated together through the MetaRouter File Builder. The tag code includes two deployment-specific components: the writeKeyData Pipeline Identifier used to organize and control data in the platform and A.js file locationAnalytics.js file containing all of the tracking, identity, and compliance details for your data collection.
To build your files:
- Navigate to the Pipelines tab of the UI
- Select (or create) the pipeline that you wish to build files for
- Select "Build New File" from the Analytics.js File section
- Enter all required information for your A.js file configuration
- Click "Save and Build File" at the bottom of the page
- From here you can:
- •View and copy your Code Snippet (JS Tag) for deployment
- •Select "Upload to Cluster" to push the A.js file to the cluster edge
- •Select "Download File" to store the A.js file locally for self-hosting