Resources

    Website tracking API

    Track user behavior on your website. Usually called via the JavaScript tracking snippet.

    How website tracking works

    Website tracking connects what people do on your site to their subscriber profile. Visitors start out anonymous (identified by an anonymous_id); as soon as they are identified with an email address, for example after a signup or login, their earlier session activity is linked to the subscriber. Events power two things: behavioral segment fields (viewed product, page visits, active on site) and automation triggers (website visit, product viewed, custom event).

    In most setups you never call this endpoint yourself: the JavaScript snippet below collects page views automatically and gives you mp('track', ...), mp('identify', ...), mp('product', ...) and mp('set', ...) helpers. Call the endpoint directly when tracking from a backend, a mobile app or a platform where the snippet cannot run.

    Use cases

    • Trigger an automation when a customer views a product, for example a browse-abandonment email.
    • Send custom events (started trial, booked demo) from your backend and use them as automation triggers.
    • Build segments on browsing behavior, for example everyone who visited the pricing page in the last 30 days.
    • Record purchases made outside a connected store so revenue-based segments stay accurate.

    Authentication works differently here

    This endpoint authenticates with your public tracking key in the request body instead of an Authorization header, because it is called from browsers. The key is safe to expose; it can only write events, never read data. Find it under Settings, Website tracking in your dashboard.

    Endpoints

    POST

    Track website event

    /track-website-event

    Track user behavior on your website. Usually called via the JavaScript tracking snippet.

    Request body

    NameTypeDescription
    public_keyrequiredstringPublic tracking key.
    anonymous_idstringUUID for anonymous tracking.
    session_idstringSession UUID.
    emailstringIdentified user email, when known.
    event_typestringOne of the event types listed below.
    event_namestringHuman-readable event name.
    event_dataobjectEvent-specific payload.
    page_urlstringFull page URL.
    page_titlestringPage title.
    referrerstringReferrer URL.
    page_languagestringLanguage of the page (the html lang attribute, for example "et" or "en-GB"). Feeds the "page language" profile property source. Sent automatically by the snippet.
    browser_languagestringBrowser language preference (navigator.language). Feeds the "browser language" profile property source. Sent automatically by the snippet.
    timestampstringEvent timestamp in UTC.

    Event types

    • page_view - Standard page view
    • product_view - Product page viewed
    • add_to_cart - Item added to cart
    • purchase - Purchase completed
    • custom - Custom event
    • identify - User identification
    • set_properties - Set custom fields on the identified subscriber; event_data holds the field values
    curl -X POST "https://api.mailingplatform.net/track-website-event" \
      -H "Content-Type: application/json" \
      -d '{
      "public_key": "mp_your_public_key",
      "anonymous_id": "uuid-for-anonymous-tracking",
      "session_id": "session-uuid",
      "email": "user@example.com",
      "event_type": "page_view",
      "event_name": "Page View",
      "event_data": {
        "path": "/products/shoes",
        "title": "Running Shoes"
      },
      "page_url": "https://yoursite.com/products/shoes",
      "page_title": "Running Shoes - Your Store",
      "referrer": "https://google.com",
      "page_language": "et",
      "browser_language": "et-EE",
      "timestamp": "2024-01-15T10:00:00Z"
    }'
    POST

    Set profile properties

    /track-website-event

    Write custom field values to the identified visitor's subscriber profile. Same endpoint with event_type set_properties; the snippet's mp('set', {...}) helper sends this.

    Behavior

    • Requires an identified visitor (an email that resolves to a subscriber in your account). Events from anonymous visitors are stored but no properties are written.
    • Each key in event_data must match a custom field defined on the subscriber's list; unknown keys are ignored.
    • Values are coerced to the field type: select fields accept only their options (case-insensitive, language codes like et match ET), number and date fields must parse, text is capped at 255 characters.
    • Up to 20 keys per call. Values always overwrite the current value.
    • Account-level property rules configured under Settings, Website tracking run on page_view, identify and set_properties events using page_language, browser_language, page_url and referrer.
    curl -X POST "https://api.mailingplatform.net/track-website-event" \
      -H "Content-Type: application/json" \
      -d '{
      "public_key": "mp_your_public_key",
      "anonymous_id": "uuid-for-anonymous-tracking",
      "session_id": "session-uuid",
      "email": "user@example.com",
      "event_type": "set_properties",
      "event_name": "Profile Properties Set",
      "event_data": {
        "Language": "ET",
        "Plan": "Pro"
      },
      "page_url": "https://yoursite.com/account",
      "timestamp": "2024-01-15T10:00:00Z"
    }'

    JavaScript tracking snippet

    Add this snippet to your website to enable automatic tracking.

    JavaScript
    <script>
    (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'mp.start':
    new Date().getTime(),event:'mp.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='MailingPlatform'?'&l='+l:'';j.async=true;j.src=
    'https://YOUR_TRACKING_DOMAIN/mp.js?k='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','MailingPlatform','YOUR_PUBLIC_KEY');
    
    // Identify a user
    mp('identify', 'user@example.com');
    
    // Track custom events
    mp('track', 'Button Clicked', { button: 'signup' });
    
    // Track product views
    mp('product', { product_id: '123', name: 'Running Shoes', price: 99.99 });
    
    // Set profile properties (custom fields) on the identified visitor
    mp('set', { Language: 'ET', Plan: 'Pro' });
    </script>