Skip to main content

Tracker API Reference

Complete reference for the SealMetrics JavaScript tracker API.


Global Variables

The tracker exposes three identical global variables:

VariableDescription
sealmetricsRecommended (unique, no conflicts)
smShort form
_smBackup if others conflict

All three work identically:

sealmetrics.conv('purchase', 99.99);
sm.conv('purchase', 99.99);
_sm.conv('purchase', 99.99);

Methods

sealmetrics()

Track a pageview. Called automatically on page load and SPA navigation.

sealmetrics();
sealmetrics(options);
ParameterTypeRequiredDescription
optionsobjectNoConfiguration options
options.groupstringNoContent grouping for this page

Examples:

// Manual pageview (rarely needed)
sealmetrics();

// Pageview with content grouping
sealmetrics({ group: 'blog' });
sealmetrics({ group: 'product' });
sealmetrics({ group: 'checkout' });

When to call manually:

  • Rarely needed — pageviews are automatic
  • Use when you need to override the content group
  • Use for hash-based routing where automatic detection doesn't work

sealmetrics.conv()

Track a conversion (goal completion with monetary value).

sealmetrics.conv(type, amount);
sealmetrics.conv(type, amount, properties);
ParameterTypeRequiredDescription
typestringYesConversion type (e.g., 'purchase', 'lead', 'signup')
amountnumberYesMonetary value. Use 0 for non-monetary conversions
propertiesobjectNoCustom key-value data

Examples:

// Simple purchase
sealmetrics.conv('purchase', 99.99);

// Purchase with properties
sealmetrics.conv('purchase', 149.99, {
order_id: 'ORD-12345',
currency: 'EUR',
payment_method: 'credit_card'
});

// Lead (no monetary value)
sealmetrics.conv('lead', 0, {
form_name: 'contact',
source: 'homepage'
});

// Subscription
sealmetrics.conv('subscription', 49, {
plan: 'pro_monthly',
currency: 'USD'
});

sealmetrics.micro()

Track a microconversion (user interaction or funnel step).

sealmetrics.micro(type);
sealmetrics.micro(type, properties);
ParameterTypeRequiredDescription
typestringYesEvent type (e.g., 'add_to_cart', 'video_play')
propertiesobjectNoCustom key-value data

Examples:

// Simple microconversion
sealmetrics.micro('add_to_cart');

// With properties
sealmetrics.micro('add_to_cart', {
product_id: 'SKU-123',
product_name: 'Blue Shoes',
price: '89.99'
});

// Video engagement
sealmetrics.micro('video_play', {
video_id: 'demo-2025',
video_title: 'Product Tour'
});

// Scroll depth
sealmetrics.micro('scroll_50');

Properties

Properties are key-value pairs attached to conversions and microconversions.

Data Types

All property values are transmitted as strings. Numbers and booleans are automatically converted:

// Both are equivalent
sealmetrics.conv('purchase', 99, { quantity: 3 });
sealmetrics.conv('purchase', 99, { quantity: '3' });

Common Properties

PropertyDescriptionExample
order_idUnique order identifier'ORD-12345'
currencyISO 4217 currency code'EUR', 'USD'
product_idProduct SKU or ID'SKU-123'
product_nameProduct name'Blue Shoes'
categoryProduct category'footwear'
priceItem price'89.99'
quantityNumber of items'2'
payment_methodPayment type'credit_card'
couponDiscount code'SAVE10'
planSubscription plan'pro'
billing_cycleBilling frequency'monthly'

Property Limits

  • Maximum properties per event: No hard limit, but keep reasonable
  • Property name max length: 100 characters
  • Property value max length: 500 characters
  • Total payload max: 64KB

Content Grouping

Content grouping categorizes pages into sections for analysis.

Setting via URL Parameter

<script src="https://t.sealmetrics.com/t.js?id=YOUR_ID&group=blog" defer></script>

Setting via JavaScript

// Override default grouping
sealmetrics({ group: 'product' });

Common Groups

GroupUse Case
blogBlog posts, articles
productProduct detail pages
categoryCategory/listing pages
cartShopping cart
checkoutCheckout flow
landingLanding pages
supportHelp, documentation
accountUser account pages

Payload Specification

Pageview Payload

{
"a": "YOUR_ACCOUNT_ID",
"s": "1abc123def456",
"t": "hmac_token",
"u": "https://example.com/page",
"r": "https://google.com/search",
"p": {
"utm_source": "google",
"utm_medium": "cpc"
},
"z": "Europe/Madrid",
"c": 1703001234567,
"g": "blog"
}
FieldDescription
aAccount ID
sSession ID (auto-generated)
tHMAC anti-spam token
uCurrent URL
rReferrer URL
pURL parameters (UTM, etc.)
zIANA timezone
cTimestamp (milliseconds)
gContent group (optional)

Conversion Payload

Includes all pageview fields plus:

{
"e": "purchase",
"v": 149.99,
"x": {
"order_id": "ORD-12345",
"currency": "EUR"
}
}
FieldDescription
eEvent type
vMonetary value
xCustom properties

Microconversion Payload

Includes all pageview fields plus:

{
"e": "add_to_cart",
"m": true,
"x": {
"product_id": "SKU-123"
}
}
FieldDescription
eEvent type
mMicroconversion flag (true)
xCustom properties

Session Identification

Session IDs are automatically generated using privacy-preserving browser characteristics. No cookies or personal data are used.


Automatic Behavior

Automatic Pageview

A pageview is tracked automatically when the script loads. You don't need to call sealmetrics() manually on page load.

SPA Navigation Detection

The tracker automatically detects Single Page Application navigation by intercepting:

  • history.pushState()
  • history.replaceState()
  • popstate event (browser back/forward)

Each URL change triggers a new pageview with the previous URL as the referrer.

Data Transmission

Events are sent using navigator.sendBeacon() with a fallback to fetch():

  1. sendBeacon (preferred): Works even when closing the tab
  2. fetch with keepalive: Fallback if sendBeacon fails

Content-Type is text/plain to avoid CORS preflight requests.


TypeScript Declarations

For TypeScript projects, add these declarations:

// types/sealmetrics.d.ts
interface SealmetricsOptions {
group?: string;
}

interface SealmetricsFunction {
(options?: SealmetricsOptions): void;
conv(type: string, amount: number, properties?: Record<string, string>): void;
micro(type: string, properties?: Record<string, string>): void;
}

declare global {
const sealmetrics: SealmetricsFunction | undefined;
const sm: SealmetricsFunction | undefined;
const _sm: SealmetricsFunction | undefined;
}

export {};

Technical Specifications

SpecificationValue
Size (minified)2,367 bytes
Size (gzipped)1,313 bytes
DependenciesNone (vanilla JavaScript)
Browser SupportChrome 60+, Firefox 55+, Safari 11.1+, Edge 79+
ES VersionES5 compatible
CookiesNone
localStorageNone
sessionStorageNone