Product View Event
Track when users view a specific product on your website. This event is essential for e-commerce analytics, product recommendations, and retargeting campaigns.
Product View vs Page View
Understanding the difference between product.view and page.view events is important
for proper analytics implementation:
| Aspect | Page View (page.view) |
Product View (product.view) |
|---|---|---|
| Purpose | Track general page navigation | Track specific product interest |
| Facebook Pixel Event | PageView |
ViewContent |
| TikTok Pixel Event | PageView |
ViewContent |
| Required Data | URL | SKU (product identifier) |
| Use Case | Traffic analysis, first touch attribution | E-commerce funnel, product retargeting, value optimization |
| Auto-tracked by SDK | Yes (by default) | No (must be triggered manually) |
On product pages, you should send both page.view and product.view.
These are different events that serve different purposes:
page.view→ Fires FacebookPageViewand TikTokPageView. Captures navigation, UTM parameters, and first touch attribution.product.view→ Fires FacebookViewContentand TikTokViewContent. Captures product interest with SKU, price, and value data for retargeting and value optimization.
The SDK automatically handles page.view. You only need to manually track product.view.
Each event gets its own unique event ID for proper pixel-CAPI deduplication.
Place your product.view tracking code in the <head> section,
not at the end of <body>. Facebook and TikTok In-App Browsers (WebViews)
often close before end-of-body scripts execute. Tracking in <head> ensures the event fires
even in WebView scenarios.
<head>
<!-- 1. Pixel stubs (Facebook, TikTok) -->
<!-- ... pixel init code ... -->
<!-- 2. Load and initialize AxiTrace SDK -->
<script src="https://axi.yourdomain.com/axitrack.js"></script>
<script>
Axitrace.init({
apiUrl: 'https://axi.yourdomain.com',
publicKey: 'pk_live_YOUR_PUBLIC_KEY',
workspaceId: 'VT-XXXXXXXXXXXXXXXXXXXX'
// autoTrackPageViews: true (default) - SDK will fire page.view automatically
});
// 3. Track product view (fires ViewContent on Facebook + TikTok pixels)
Axitrace._instance.track('product.view', {
sku: 'WIDGET-001',
name: 'Premium Widget',
price: 99.99,
value: 99.99,
currency: 'USD'
});
</script>
</head>
Request Parameters
Required Fields
| Field | Type | Description |
|---|---|---|
label |
string | Human-readable label for the event (e.g., product name). Required for server-side /v1/product/view calls. The SDK auto-fills this. |
client |
object | User identification object. Must contain at least one identifier. |
params.sku |
string | Unique product identifier (Stock Keeping Unit). Must be non-empty. |
Client Object
The client object identifies the user. At least one of these fields is required:
| Field | Type | Description |
|---|---|---|
customId |
string | Your custom user identifier (e.g., database user ID) |
uuid |
string | Anonymous device/browser identifier (auto-generated by SDK) |
email |
string | User's email address |
phone |
string | User's phone number (used for Facebook CAPI and TikTok user matching) |
id |
integer | Numeric user ID |
For server-side events, you must pass the same user identifiers that the JavaScript SDK generates. The SDK stores these in cookies:
vt_vid- Visitor ID (persistent anonymous identifier)vt_sid- Session ID (current browsing session)vt_uid- User ID (set viaAxitrace._instance.identify())
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.
Optional Fields
| Field | Type | Description |
|---|---|---|
sessionId |
string | Session identifier for grouping events within a user session |
time |
ISO 8601 | Event timestamp. If not provided or in the future, server time is used |
eventSalt |
string | Unique event ID used for pixel-CAPI deduplication. The SDK auto-generates this. For server-side calls, provide your own UUID to match a pixel event. |
Product Parameters (params object)
| Field | Type | Required | Description |
|---|---|---|---|
sku |
string | Required | Unique product identifier (e.g., WIDGET-001) |
name |
string | Optional | Product name (e.g., Premium Widget). Also sent to Facebook/TikTok as content_name. |
price |
number | Optional | Product price. Must be >= 0. Validated by the server. |
value |
number | Optional | Monetary value for Facebook/TikTok conversion optimization. Sent as value to ViewContent pixel events. If not provided, Facebook ViewContent will be missing value data for optimization. |
currency |
string | Optional | ISO 4217 currency code (e.g., USD, EUR, GBP). Must be non-empty if provided. |
category |
string | Optional | Product category (e.g., Electronics). Also sent to Facebook as content_category. |
categories |
array | Optional | Array of category hierarchy (e.g., ["Electronics", "Gadgets", "Widgets"]) |
brand |
string | Optional | Product brand (e.g., WidgetCo) |
variant |
string | Optional | Product variant (e.g., Blue / Large) |
image |
string | Optional | Product image URL |
url |
string | Optional | Product page URL. Auto-filled by SDK from window.location.href if not provided. |
regularPrice |
number | Optional | Original price before discount |
discountPrice |
number | Optional | Discounted price |
discountPercent |
number | Optional | Discount percentage (e.g., 20 for 20% off) |
inStock |
boolean | Optional | Whether the product is in stock |
stockQuantity |
integer | Optional | Available stock quantity |
rating |
number | Optional | Product rating (e.g., 4.5) |
reviewCount |
integer | Optional | Number of reviews |
Facebook & TikTok Parameter Mapping
The SDK automatically maps your product parameters to Facebook and TikTok standard parameters when calling pixels. You can also pass Facebook-specific fields directly for precise control:
| Your Field | Facebook ViewContent | TikTok ViewContent |
|---|---|---|
value |
value |
value |
currency |
currency |
currency |
name or content_name |
content_name |
content_name |
category or content_category |
content_category |
- |
content_type |
content_type (defaults to product) |
content_type |
content_ids |
content_ids (array of product IDs) |
content_id |
value for Facebook Optimization
The value field is what Facebook/TikTok use for conversion value optimization.
The price field is validated and stored by AxiTrace, but only value
is sent to the pixel. For best results, include both:
Axitrace._instance.track('product.view', {
sku: 'WIDGET-001',
price: 99.99, // Stored in AxiTrace analytics
value: 99.99, // Sent to Facebook/TikTok ViewContent
currency: 'USD' // Required when value is set
});
Pixel-CAPI Deduplication
When you call Axitrace._instance.track('product.view', ...), the SDK automatically:
- Generates a unique
eventSalt(UUID) - Calls
fbq('track', 'ViewContent', {...}, {eventID: eventSalt})if Facebook Pixel is present - Calls
ttq.track('ViewContent', {...}, {event_id: eventSalt})if TikTok Pixel is present - Sends the event to AxiTrace with the same
eventSalt - AxiTrace forwards the event to Facebook CAPI / TikTok Events API with the same event ID
- Meta/TikTok matches browser pixel and server CAPI events, counting the conversion once
Do not call fbq('track', 'ViewContent') or ttq.track('ViewContent') yourself.
The SDK does this automatically with the correct event ID for deduplication. Manual pixel calls would create
duplicate events that cannot be deduplicated.
Marketing Attribution Parameters
The SDK automatically enriches every product.view event with attribution data
(UTM parameters, click IDs, ad platform cookies) extracted from the URL and browser cookies.
The same tracking parameters as page view are captured:
| Category | Parameters |
|---|---|
| UTM Parameters | utm_source, utm_medium, utm_campaign, utm_term, utm_content, utm_id |
| Facebook/Meta | fbclid, fbp, fbc, campaign_id, adset_id, ad_id |
| Google Ads | gclid, gbraid, wbraid |
| Other Platforms | ttclid, ttp, msclkid, twclid, epik, li_fat_id, sccid, rdt_cid |
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, X-Real-IP, etc.) |
userAgent |
Browser User-Agent string |
timestamp |
Server timestamp (ISO 8601 format) |
Examples
JavaScript SDK
// Basic product view
Axitrace._instance.track('product.view', {
sku: 'WIDGET-001',
name: 'Premium Widget',
price: 99.99,
value: 99.99,
currency: 'USD'
});
// Detailed product view with all available data
Axitrace._instance.track('product.view', {
sku: 'WIDGET-001',
name: 'Premium Widget',
price: 79.99,
value: 79.99,
currency: 'USD',
category: 'Electronics',
categories: ['Electronics', 'Gadgets', 'Widgets'],
brand: 'WidgetCo',
variant: 'Blue / Large',
image: 'https://example.com/images/widget-blue.jpg',
url: window.location.href,
regularPrice: 99.99,
discountPrice: 79.99,
discountPercent: 20,
inStock: true,
stockQuantity: 42,
rating: 4.5,
reviewCount: 128
});
Server-Side (cURL)
# Note: Replace client identifiers with values from SDK cookies (vt_vid, vt_sid, vt_uid)
curl -X POST https://stat.axitrace.com/v1/product/view \
-u "sk_live_YOUR_SECRET_KEY:" \
-H "Content-Type: application/json" \
-H "User-Agent: MyApp/1.0" \
-d '{
"label": "Premium Widget",
"client": {
"customId": "value-from-vt_uid-or-vt_vid-cookie",
"uuid": "value-from-vt_vid-cookie"
},
"sessionId": "value-from-vt_sid-cookie",
"params": {
"sku": "WIDGET-001",
"name": "Premium Widget",
"price": 99.99,
"value": 99.99,
"currency": "USD",
"category": "Electronics",
"brand": "WidgetCo",
"url": "https://example.com/products/widget-001",
"inStock": true
}
}'
Server-Side (PHP)
<?php
$secretKey = getenv('AXITRACE_SECRET_KEY');
// Read AxiTrace SDK cookies - CRITICAL for user profile linking
$visitorId = $_COOKIE['vt_vid'] ?? null; // Persistent visitor ID
$sessionId = $_COOKIE['vt_sid'] ?? null; // Current session ID
$userId = $_COOKIE['vt_uid'] ?? null; // Authenticated user ID (if identified)
// Assuming $product is your product object from database
$product = getProductById($_GET['product_id']);
$data = [
'label' => $product->name,
'client' => [
// Use userId if available, otherwise fall back to visitorId
'customId' => $userId ?? $visitorId,
// Always include the visitor UUID for profile linking
'uuid' => $visitorId,
],
// Pass the session ID for session-based analytics
'sessionId' => $sessionId,
'params' => [
'sku' => $product->sku,
'name' => $product->name,
'price' => $product->price,
'value' => $product->price, // For Facebook/TikTok value optimization
'currency' => 'USD',
'category' => $product->category,
'categories' => $product->getCategoryPath(),
'brand' => $product->brand,
'image' => $product->getImageUrl(),
'url' => $product->getUrl(),
'regularPrice' => $product->regularPrice,
'discountPrice' => $product->salePrice,
'inStock' => $product->isInStock(),
'stockQuantity' => $product->stockQuantity,
'rating' => $product->averageRating,
'reviewCount' => $product->reviewCount,
// Pass through UTM parameters if present
'utm_source' => $_GET['utm_source'] ?? null,
'utm_medium' => $_GET['utm_medium'] ?? null,
'utm_campaign' => $_GET['utm_campaign'] ?? null,
'fbclid' => $_GET['fbclid'] ?? null,
'gclid' => $_GET['gclid'] ?? null
]
];
// Remove null values
$data['params'] = array_filter($data['params'], fn($v) => $v !== null);
$data['client'] = array_filter($data['client'], fn($v) => $v !== null);
$ch = curl_init('https://stat.axitrace.com/v1/product/view');
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);
curl_close($ch);
Server-Side (Python)
import os
import requests
from flask import request # Example using Flask
secret_key = os.environ.get('AXITRACE_SECRET_KEY')
# Read AxiTrace SDK cookies - CRITICAL for user profile linking
visitor_id = request.cookies.get('vt_vid') # Persistent visitor ID
session_id = request.cookies.get('vt_sid') # Current session ID
user_id = request.cookies.get('vt_uid') # Authenticated user ID (if identified)
# Assuming product is your product object
product = get_product_by_id(product_id)
response = requests.post(
'https://stat.axitrace.com/v1/product/view',
auth=(secret_key, ''),
headers={
'Content-Type': 'application/json',
'User-Agent': 'MyApp/1.0'
},
json={
'label': product.name,
'client': {
# Use user_id if available, otherwise fall back to visitor_id
'customId': user_id or visitor_id,
# Always include the visitor UUID for profile linking
'uuid': visitor_id,
},
# Pass the session ID for session-based analytics
'sessionId': session_id,
'params': {
'sku': product.sku,
'name': product.name,
'price': float(product.price),
'value': float(product.price), # For Facebook/TikTok value optimization
'currency': 'USD',
'category': product.category,
'brand': product.brand,
'url': product.get_absolute_url(),
'inStock': product.is_in_stock(),
'rating': product.average_rating,
'reviewCount': product.review_count
}
}
)
if response.status_code == 200:
result = response.json()
print(f"Event tracked: {result['eventId']}")
Response
Success Response (200 OK)
{
"success": true,
"eventId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"action": "product.view"
}
Error Responses
| Status | Error | Description |
|---|---|---|
400 |
label is required |
The label field is missing (server-side /v1/product/view only; SDK auto-fills this) |
400 |
params.sku is required for product.view event |
The SKU parameter is missing from params |
400 |
params.sku must be a non-empty string |
SKU is empty or not a string |
400 |
params.price must be a number |
Price is not a valid number |
400 |
params.price must be >= 0 |
Price is negative |
400 |
params.currency must be a non-empty string |
Currency provided but empty |
400 |
client must have at least one identifier (customId, id, uuid, or email) |
No user identifier provided in the client object |
401 |
unauthorized |
Invalid or missing API key |
E-commerce Integration Examples
WooCommerce (WordPress)
Use the wp_head action (not woocommerce_after_single_product) to ensure the tracking
fires in the <head> section. This is critical for Facebook/TikTok In-App Browser (WebView)
compatibility, which may not execute end-of-body scripts.
<?php
// In your theme's functions.php - fires in <head> for WebView compatibility
add_action('wp_head', function() {
if (!is_product()) return;
global $product;
if (!$product) return;
$categories = wp_get_post_terms($product->get_id(), 'product_cat', ['fields' => 'names']);
$price = $product->get_price() ?: 0;
?>
<script>
Axitrace._instance.track('product.view', {
sku: '<?php echo esc_js($product->get_sku()); ?>',
name: '<?php echo esc_js($product->get_name()); ?>',
price: <?php echo $price; ?>,
value: <?php echo $price; ?>,
currency: '<?php echo get_woocommerce_currency(); ?>',
categories: <?php echo json_encode($categories); ?>,
inStock: <?php echo $product->is_in_stock() ? 'true' : 'false'; ?>,
url: '<?php echo esc_js(get_permalink()); ?>'
});
</script>
<?php
}, 99); // Priority 99 to run after AxiTrace SDK init
Shopify
{# Add to theme.liquid <head> section, after AxiTrace SDK init #}
{%- if template contains 'product' -%}
<script>
Axitrace._instance.track('product.view', {
sku: '{{ product.selected_or_first_available_variant.sku | escape }}',
name: '{{ product.title | escape }}',
price: {{ product.price | money_without_currency | remove: ',' }},
value: {{ product.price | money_without_currency | remove: ',' }},
currency: '{{ shop.currency }}',
category: '{{ product.type | escape }}',
brand: '{{ product.vendor | escape }}',
image: '{{ product.featured_image | img_url: "large" }}',
url: '{{ shop.url }}{{ product.url }}',
inStock: {{ product.available }}
});
</script>
{%- endif -%}
Best Practices
- Always include SKU - Required and should be a unique, consistent product identifier across all events (product view, add to cart, purchase)
- Include both
priceandvalue-priceis stored in AxiTrace analytics;valueis sent to Facebook/TikTok for conversion optimization - Always include
currency- Required by Facebook/TikTok whenvalueis present - Track in
<head>- Place product.view tracking in the<head>section after SDK init for In-App Browser compatibility - Don't disable auto page views -
page.view(PageView) andproduct.view(ViewContent) are different events; both should fire on product pages - Don't call pixel events manually - Remove
fbq('track', 'ViewContent')andttq.track('ViewContent'); the SDK handles this with deduplication - Use consistent SKUs - Match the same SKU across product views, add to cart, and transactions
- Include category hierarchy - Helps with category-level analytics and recommendations