AxiTrace Subscribe event - parameters, required fields, and integration examples.

Subscribe Event

Track newsletter signups, mailing list subscriptions, and other opt-in events. This event maps to Facebook Subscribe and TikTok Subscribe standard events, enabling lead generation attribution and subscriber acquisition analysis.

POST /v1/subscribe

When to Use This Event

The subscribe event should be triggered when a user opts in to receive communications. This typically occurs when:

  • User signs up for a newsletter
  • User subscribes to email updates or notifications
  • User opts in to marketing communications
  • User joins a mailing list or waitlist
  • User registers for product updates or announcements
Lead Generation Tracking

Subscribe events are valuable for measuring top-of-funnel conversions and lead generation effectiveness. Track these events to analyze which traffic sources generate the most engaged subscribers.

Client-Side vs Server-Side Tracking

Choose One Approach - Not Both

For each subscribe action, use either the JavaScript SDK or the server-side API - not both.

The JavaScript SDK automatically fires Facebook and TikTok pixels with a matching eventID, then sends the event to the AxiTrace backend which forwards it to CAPI. Facebook/TikTok deduplicates using the shared eventID, counting one event.

If you also send the same event via the server-side PHP SDK or API, it generates a different eventID - causing Facebook/TikTok to count the event twice.

Recommendation: Use server-side tracking for subscribe events triggered after form validation. This ensures only validated emails are tracked, the event fires reliably even if the page redirects, and secret keys stay secure. Use the JavaScript SDK only when server-side tracking is not practical (e.g., single-page apps with no backend form handler).

Request Parameters

User Identification

At least one of these identifiers is required:

Field Type Description
client_id string Your custom user/visitor identifier (use SDK's vt_vid cookie value)
user_id string Authenticated user ID
session_id string Current session identifier (use SDK's vt_sid cookie value)
Server-Side: Match SDK User Identifiers

For server-side events, pass the same user identifiers that the JavaScript SDK generates. The SDK stores these in cookies:

  • vt_vid - Visitor ID (persistent anonymous identifier → use as client_id)
  • vt_sid - Session ID (current browsing session → use as session_id)
  • vt_uid - User ID (set via identify() → use as user_id)

Read these cookies and pass them in your server-side events to properly link all events to the same user profile. See the User Identification guide for complete details.

Subscription Details

Field Type Required Description
email string Recommended Subscriber's email address. If provided, must be a valid email format (contains @ and a dot after it). Improves Facebook CAPI match quality.
subscription_type string Recommended Type of subscription: newsletter, updates, marketing, product_updates, etc.
eventSalt string Optional Your stable ID for this subscription. A retried request with the same eventSalt is stored once.
value number Optional Value of the subscription, zero or more. Context for Leads, never revenue.
currency string Optional ISO 4217 code of value and of the product prices, for example EUR.
products array Optional Products the subscription is about, in the transaction line shape. An invalid line is dropped and the subscription is still stored. See Rules for lead products.

Customer Data (for Facebook CAPI)

Include these fields in the params object to enhance Facebook Conversions API matching:

Field Type Description
phone string Phone number (E.164 format recommended, e.g., +14155551234)
first_name string Subscriber's first name
last_name string Subscriber's last name
city string City name
state string State or province (2-letter code for US, e.g., CA)
zip string ZIP or postal code
country string Country code (ISO 3166-1 alpha-2, e.g., US, GB)
gender string Gender: m or f

Additional Parameters (via params)

Field Type Description
source string Where the subscription came from: footer, popup, sidebar, checkout
list string Mailing list identifier or name
fbp string Facebook Pixel browser ID (from _fbp cookie)
fbc string Facebook Click ID (from _fbc cookie or URL)

Facebook & TikTok Pixel Mapping

When using the JavaScript SDK, AxiTrace automatically fires the corresponding pixel events:

AxiTrace Event Facebook Pixel TikTok Pixel
subscribe Subscribe Subscribe

The SDK fires fbq('track', 'Subscribe', params, {eventID: eventSalt}) and ttq.track('Subscribe', params, {event_id: eventSalt}) in the browser, then sends the event to the AxiTrace backend which forwards it to Facebook CAPI and TikTok Events API with the same eventSalt for pixel-CAPI deduplication.

Event Name Aliases

The JavaScript SDK accepts these name formats that all map to the same event: subscribe and newsletter.subscribe. Both are routed to the same handler internally and map to Facebook/TikTok Subscribe.

Products and Value (Leads)

A subscription can carry the products it is about and a value, as root products, value and currency, plus an eventSalt so a retry is stored once. All are optional, appear on the lead in Leads and are never counted as revenue. An invalid product line is dropped; the subscription is always stored. Calls without these fields work exactly as before.

<?php
// PHP SDK 1.12.0 or later
$event = (new SubscribeEvent('reader@example.com'))
    ->setSubscriptionType('box')
    ->setEventSalt('subscription-' . $subscriptionId)
    ->setValue(29.00, 'EUR')
    ->addProduct(['sku' => 'BOX-M', 'name' => 'Monthly box', 'finalUnitPrice' => 29.00, 'quantity' => 1]);
$axitrace->track($event);

// or through the helper's $params
$axitrace->subscribe('reader@example.com', [
    'subscription_type' => 'box',
    'eventSalt' => 'subscription-' . $subscriptionId,
    'value' => 29.00,
    'currency' => 'EUR',
    'products' => [['sku' => 'BOX-M', 'name' => 'Monthly box', 'finalUnitPrice' => 29.00, 'quantity' => 1]],
]);
Axitrace._instance.track('subscribe', {
    email: 'reader@example.com',
    subscription_type: 'box',
    value: 29,
    currency: 'EUR',
    products: [{ sku: 'BOX-M', name: 'Monthly box', finalUnitPrice: 29, quantity: 1 }]
});

The full rules and the HTTP API body are on the Leads page.

Server-Enriched Fields

The following fields are automatically added by the server:

Field Description
ip Client IP address (extracted from X-Forwarded-For, CF-Connecting-IP, etc.)
userAgent Browser User-Agent string
timestamp Server timestamp (ISO 8601 format)

Examples

JavaScript SDK

// Basic newsletter subscription
Axitrace._instance.track('subscribe', {
    email: 'user@example.com',
    subscription_type: 'newsletter'
});

// Detailed subscription with customer data
Axitrace._instance.track('subscribe', {
    email: 'john@example.com',
    subscription_type: 'marketing',
    first_name: 'John',
    last_name: 'Doe',
    source: 'popup',
    list: 'weekly-deals'
});

Server-Side (cURL)

# Basic subscription
curl -X POST https://stat.axitrace.com/v1/subscribe \
  -u "sk_live_YOUR_SECRET_KEY:" \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "value-from-vt_vid-cookie",
    "session_id": "value-from-vt_sid-cookie",
    "email": "subscriber@example.com",
    "subscription_type": "newsletter"
  }'

Server-Side with Customer Data (cURL)

# Full subscription with customer data for Facebook CAPI
curl -X POST https://stat.axitrace.com/v1/subscribe \
  -u "sk_live_YOUR_SECRET_KEY:" \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "value-from-vt_vid-cookie",
    "session_id": "value-from-vt_sid-cookie",
    "email": "john@example.com",
    "subscription_type": "newsletter",
    "params": {
        "first_name": "John",
        "last_name": "Doe",
        "phone": "+14155551234",
        "city": "San Francisco",
        "state": "CA",
        "zip": "94102",
        "country": "US",
        "source": "footer",
        "list": "weekly-newsletter",
        "fbp": "fb.1.1234567890.987654321",
        "fbc": "fb.1.1234567890.AbCdEfGhIjKl"
    }
  }'

Server-Side (AxiTrace PHP SDK)

<?php
use AxiTrace\AxiTraceClient;
use AxiTrace\Model\Event\SubscribeEvent;

$client = new AxiTraceClient('sk_live_YOUR_SECRET_KEY');

// Create subscribe event - email is required by the PHP SDK
$event = new SubscribeEvent('john@example.com');

// Set user identifiers (from SDK cookies)
$event->setClientId($_COOKIE['vt_vid'] ?? '');
$event->setSessionId($_COOKIE['vt_sid'] ?? '');

// Set subscription details
$event->setSubscriptionType('newsletter');

// Optional: Add Facebook CAPI data for better match quality
$event->setPhone('+14155551234');
$event->setFirstName('John');
$event->setLastName('Doe');
$event->setFbp($_COOKIE['_fbp'] ?? '');
$event->setFbc($_COOKIE['_fbc'] ?? '');

// Optional: Add custom params
$event->setParams([
    'source' => 'footer',
    'list' => 'weekly-newsletter',
]);

$response = $client->track($event);
// $response['eventId'] = "a1b2c3d4-..."

Server-Side (PHP - raw cURL)

<?php
// Newsletter signup handler
$secretKey = getenv('AXITRACE_SECRET_KEY');

// Read AxiTrace SDK cookies - CRITICAL for user profile linking
$visitorId = $_COOKIE['vt_vid'] ?? null;
$sessionId = $_COOKIE['vt_sid'] ?? null;

// Read Facebook cookies for CAPI
$fbp = $_COOKIE['_fbp'] ?? null;
$fbc = $_COOKIE['_fbc'] ?? null;

// Get form data
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$firstName = $_POST['first_name'] ?? null;
$lastName = $_POST['last_name'] ?? null;

if (!$email) {
    http_response_code(400);
    echo json_encode(['error' => 'Invalid email']);
    exit;
}

// Add to your email service (Mailchimp, SendGrid, etc.)
$mailchimp->addSubscriber($email, $firstName, $lastName);

// Track to AxiTrace
$data = [
    'client_id' => $visitorId,
    'session_id' => $sessionId,
    'email' => $email,
    'subscription_type' => 'newsletter',
    'params' => array_filter([
        'first_name' => $firstName,
        'last_name' => $lastName,
        'source' => $_POST['source'] ?? 'footer',
        'list' => 'main-newsletter',
        'fbp' => $fbp,
        'fbc' => $fbc,
    ]),
];

// Remove null values
$data = array_filter($data, fn($v) => $v !== null);

$ch = curl_init('https://stat.axitrace.com/v1/subscribe');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_USERPWD => $secretKey . ':',
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'User-Agent: MyApp/1.0'
    ],
    CURLOPT_POSTFIELDS => json_encode($data)
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode === 200) {
    $result = json_decode($response, true);
    // Subscription tracked: $result['eventId']
}

Server-Side (Python)

import os
import requests
from flask import request, jsonify

secret_key = os.environ.get('AXITRACE_SECRET_KEY')

@app.route('/subscribe', methods=['POST'])
def subscribe():
    # Read AxiTrace SDK cookies - CRITICAL for user profile linking
    visitor_id = request.cookies.get('vt_vid')
    session_id = request.cookies.get('vt_sid')

    # Read Facebook cookies for CAPI
    fbp = request.cookies.get('_fbp')
    fbc = request.cookies.get('_fbc')

    # Get form data
    email = request.form.get('email')
    first_name = request.form.get('first_name')
    last_name = request.form.get('last_name')

    if not email or '@' not in email:
        return jsonify({'error': 'Invalid email'}), 400

    # Add to your email service
    mailchimp.add_subscriber(email, first_name, last_name)

    # Track to AxiTrace
    data = {
        'client_id': visitor_id,
        'session_id': session_id,
        'email': email,
        'subscription_type': 'newsletter',
        'params': {
            'first_name': first_name,
            'last_name': last_name,
            'source': request.form.get('source', 'footer'),
            'list': 'main-newsletter',
            'fbp': fbp,
            'fbc': fbc,
        }
    }

    # Remove None values from params
    data['params'] = {k: v for k, v in data['params'].items() if v}

    response = requests.post(
        'https://stat.axitrace.com/v1/subscribe',
        auth=(secret_key, ''),
        headers={
            'Content-Type': 'application/json',
            'User-Agent': 'MyApp/1.0'
        },
        json=data
    )

    if response.status_code == 200:
        result = response.json()
        return jsonify({
            'success': True,
            'message': 'Successfully subscribed!'
        })

    return jsonify({'error': 'Subscription failed'}), 500

Response

Success Response (200 OK)

{
    "success": true,
    "eventId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "action": "subscribe"
}

Error Responses

Status Error Description
400 at least one of client_id, user_id, or session_id is required No user identifier provided
400 invalid email format Email provided but not in valid format (must contain @ and a dot after it)
401 unauthorized Invalid or missing API key

Integration Examples

Mailchimp Integration

<?php
// After Mailchimp API call succeeds
$mailchimpResponse = $mailchimp->lists->addListMember($listId, [
    'email_address' => $email,
    'status' => 'subscribed',
    'merge_fields' => [
        'FNAME' => $firstName,
        'LNAME' => $lastName,
    ],
]);

if ($mailchimpResponse->id) {
    // Track to AxiTrace
    trackAxitraceSubscribe($email, $firstName, $lastName, 'newsletter', 'mailchimp');
}

WordPress / Contact Form 7

<?php
// Hook into Contact Form 7 submission
add_action('wpcf7_mail_sent', function($contact_form) {
    $submission = WPCF7_Submission::get_instance();
    if (!$submission) return;

    $data = $submission->get_posted_data();

    // Check if this is a newsletter form
    if ($contact_form->id() !== YOUR_NEWSLETTER_FORM_ID) return;

    $email = sanitize_email($data['your-email'] ?? '');
    if (!$email) return;

    $secret_key = get_option('axitrace_secret_key');
    $visitor_id = $_COOKIE['vt_vid'] ?? null;
    $session_id = $_COOKIE['vt_sid'] ?? null;

    wp_remote_post('https://stat.axitrace.com/v1/subscribe', [
        'headers' => [
            'Authorization' => 'Basic ' . base64_encode($secret_key . ':'),
            'Content-Type' => 'application/json',
        ],
        'body' => json_encode([
            'client_id' => $visitor_id,
            'session_id' => $session_id,
            'email' => $email,
            'subscription_type' => 'newsletter',
            'params' => [
                'first_name' => $data['your-name'] ?? '',
                'source' => 'contact-form-7',
            ],
        ]),
        'timeout' => 10,
    ]);
});

Best Practices

  • Track after validation - Fire the event after email validation succeeds, not on form submission
  • Use subscription_type - Differentiate between newsletter, marketing, product updates, etc.
  • Include source - Track where the subscription form appeared (popup, footer, sidebar)
  • Link to browser session - Pass SDK cookie values to connect subscriptions with browsing behavior
  • Pass Facebook cookies - Include _fbp and _fbc for better CAPI matching
  • Include customer data - Add name, phone, location for improved Facebook attribution
  • Don't double-track - Choose either JS SDK or server-side for each subscribe event. Sending both creates duplicate events with different eventIDs.
Lead Attribution Analysis

Subscribe events enable powerful lead generation analysis. AxiTrace helps you identify:

  • Which traffic sources generate the most subscribers
  • Subscription rates by campaign, ad set, and ad
  • Time from first visit to subscription
  • Which subscription forms perform best
  • Subscriber-to-customer conversion rates