Pixel SDK

How the browser pixel works — auto-tracking, custom events, data-skryx-* attributes, consent.

Pixel SDK

The Skryx tracking pixel is a vanilla-JS script, ~3 KB gzipped, no dependencies. Drop one tag in the page head and it auto-instruments page views, search detection, and clicks on tagged elements.

# Install

<script src="https://cdn.skryx.io/pixel.js"
        data-key="pk_live_xxxxx"
        defer></script>

Attributes on the script tag:

Attribute Purpose
data-key Required. Your pk_live_… public key.
data-endpoint Optional. Override the ingestion URL (default https://track.skryx.io/p).
data-debug "1" to log every fired event to console.debug.
data-noauto "1" to skip auto-tracking (page view, URL search, click instrumentation). Manual mode for control freaks.

# Auto-tracking

Without data-noauto, the pixel fires three things automatically on load:

# 1. page.viewed

Every page load. Properties: url, title, referrer, path.

# 2. search.performed (URL-based)

If the URL contains ?q=, ?s=, ?search=, or ?query=, the pixel fires search.performed with that value. Skryx engine queries set this automatically; storefronts using their own search URL pattern get covered too.

The pixel doesn't know how many results your page rendered — it sends results_count: 0. Override by calling skryx.track('search.performed', …) manually with the real count once your page renders.

# 3. Click instrumentation via data-skryx-*

Any element (anchor, button, anything) marked with data-skryx-track becomes a tracker:

<a href="/product/SKU-123"
   data-skryx-track="result.clicked"
   data-skryx-result-id="SKU-123"
   data-skryx-position="3"
   data-skryx-query="wireless headphones"
   data-skryx-price="199.99">
   Sony WH-1000XM5
</a>

When that element (or any descendant) is clicked:

  • data-skryx-track becomes the event name.
  • Every other data-skryx-* attribute becomes a property (with data-skryx- stripped, dashes converted to underscores).
  • Pure-number strings ("3", "199.99") auto-coerce to int / float.
  • The handler runs in the capture phase so it catches clicks even when a child element calls e.stopPropagation().

# Public API on window.skryx

After auto-init, the pixel exposes:

skryx.track('event.name', { prop: 'value' })  // fire any custom event
skryx.identify('user_id', { traits })          // link the session to a logged-in user
skryx.consent(true)                            // grant analytics consent at runtime
skryx.consent(false)                           // revoke; clears anonymous_id
skryx.flush()                                  // force-send the queue (rare)
skryx.config({ debug: true })                  // runtime knob flips

skryx.identify() should fire after login. From that point on every event carries user_id server-side; you can still join to the anonymous_id to reconstruct pre-login behaviour.

# Queue + flush

The pixel batches events client-side and sends them automatically every few seconds. On critical events (order.completed, checkout.started) it flushes immediately — minimises loss when the user is about to close the tab.

On visibilitychange (tab hidden), pagehide, and beforeunload it flushes again via sendBeacon so backgrounded / closing tabs still ship their queue.

The pixel reads localStorage.skryx_cookie_consent on init:

JSON.parse(localStorage.skryx_cookie_consent).analytics === true
  • Truthy → persistent anonymous_id in localStorage. Same visitor identified across sessions.
  • Anything else → session-only tracking. anonymous_id is null on every event. session_id lives in sessionStorage and resets at the end of the browser session.

To revoke later, call skryx.consent(false) — anonymous_id is wiped from localStorage, current session continues session-only.

See /docs/tracking/privacy for the full privacy story.

# Size + performance

  • ~3 KB gzipped, no deps.
  • defer keeps it off the critical path.
  • Endpoint responds in <50 ms (204 No Content). All real processing is async on Skryx's side.
  • sendBeacon ensures events ship even on tab close.
esc