Installing the Tracking Snippet
The Apex tracking snippet (apex.js) is a lightweight, self-contained script that runs on your website. It handles visitor identification, UTM attribution, experiment assignment, form interception, and event tracking — all automatically.
Adding the Script Tag
Place the snippet in your site's <head> tag. Replace YOUR_PROJECT_KEY with the key from your Apex dashboard (Settings > Project Key).
<script src="https://your-apex-domain/api/apex-js?key=YOUR_PROJECT_KEY" defer></script>
The /api/apex-js endpoint serves the full snippet, configured for your project. The defer attribute ensures it loads without blocking page rendering.
Tip
You can also use the data-key attribute instead of a query parameter: <script src="https://your-apex-domain/api/apex-js" data-key="YOUR_PROJECT_KEY" defer></script>
What the Snippet Does Automatically
Once installed, the snippet runs on every page load and handles:
- Visitor identity — Generates a persistent UUID stored in the
apex_vidcookie (365-day expiry). This ID ties all sessions from the same browser together. - UTM capture — Reads
utm_source,utm_medium,utm_campaign,utm_term, andutm_contentfrom the URL and stores them in theapex_attrcookie. New UTM values merge with existing ones so you never lose first-touch data. - Click ID capture — Captures ad platform click identifiers:
gclid(Google Ads),fbclid(Meta Ads),li_fat_id(LinkedIn Ads), andmsclkid(Microsoft Ads). - Pageview tracking — Sends a
pageviewevent to/api/eventswith the current URL, referrer, and whether this is a landing page visit. - Experiment assignment — Fetches active experiments and applies variant changes to the DOM. See Experiments.
- Form interception — Detects all
<form>elements and injects hidden attribution fields on submit. See Form Tracking. - Engagement tracking — Measures time on page and scroll depth, reported when the visitor leaves.
- Heartbeat — Sends a health signal with snippet version, screen size, and experiment assignments.
Verifying Installation
Open your site with DevTools
Navigate to any page where the snippet is installed and open Chrome DevTools (F12).
Check the Network tab
Filter by apex. You should see a request to /api/apex-js (the snippet itself) and subsequent requests to /api/experiments/active and /api/events.
Check cookies
In the Application tab under Cookies, look for apex_vid (your visitor UUID) and apex_attr (attribution JSON). Both confirm the snippet is running.
Verify from the dashboard
Go to Settings > Snippet in the Apex dashboard and click Verify Installation. Enter your site URL — Apex will confirm it detects the snippet.
Anti-Flicker Behavior
The snippet briefly hides the page (opacity: 0) while it fetches experiments and applies variant changes. This prevents visitors from seeing the original content flash before the variant loads. The page becomes visible as soon as experiments are applied, or after 100ms if no experiments are running.
Info
The anti-flicker mechanism is automatically disabled on /dashboard and /onboarding paths to avoid affecting the Apex app itself.
Cookies Reference
| Cookie | Purpose | Expiry |
|---|---|---|
apex_vid | Persistent anonymous visitor ID (UUID v4) | 365 days |
apex_attr | JSON-encoded UTM parameters and click IDs | 365 days |
Both cookies use SameSite=Lax and are scoped to the root path.
Next Steps
- Client-side experiments — how variant assignment and DOM changes work
- Form tracking — automatic form interception and identity stitching
- Custom events — sending events via the
window.apexAPI