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
Endpoints
Track website event
/track-website-eventTrack user behavior on your website. Usually called via the JavaScript tracking snippet.
Request body
| Name | Type | Description |
|---|---|---|
public_keyrequired | string | Public tracking key. |
anonymous_id | string | UUID for anonymous tracking. |
session_id | string | Session UUID. |
email | string | Identified user email, when known. |
event_type | string | One of the event types listed below. |
event_name | string | Human-readable event name. |
event_data | object | Event-specific payload. |
page_url | string | Full page URL. |
page_title | string | Page title. |
referrer | string | Referrer URL. |
page_language | string | Language 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_language | string | Browser language preference (navigator.language). Feeds the "browser language" profile property source. Sent automatically by the snippet. |
timestamp | string | Event timestamp in UTC. |
Event types
page_view- Standard page viewproduct_view- Product page viewedadd_to_cart- Item added to cartpurchase- Purchase completedcustom- Custom eventidentify- User identificationset_properties- Set custom fields on the identified subscriber;event_dataholds 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"
}'Set profile properties
/track-website-eventWrite 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
emailthat resolves to a subscriber in your account). Events from anonymous visitors are stored but no properties are written. - Each key in
event_datamust 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
etmatchET), 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,identifyandset_propertiesevents usingpage_language,browser_language,page_urlandreferrer.
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.
<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>