As modern browsers tighten restrictions on client-side tracking (cookies, ad blockers, ITP), server-side tagging has become critical for accurate conversion tracking. This article guides you step-by-step through setting up Snapchatβs Conversions API (CAPI) using Google Tag Manager Server-Side (sGTM) to track Product Sales events.
π― Why Use Snapchat CAPI via Server-Side GTM?
- β Improved Attribution Accuracy
- β Bypass Ad Blockers & Cookie Restrictions
- β First-Party Data Reliability
- β Enhanced Pixel Data Resilience
π§° Prerequisites
Before we start, ensure you have:
- Snapchat Ads account
- Snapchat Pixel ID and Access Token
- Google Tag Manager Server Container setup
- Custom backend (Node.js, Python, etc.) or Shopify/BigCommerce
- GTM Web Container already implemented on your site
π Step 1: Generate Snapchat Access Token & Pixel
- Go to your Snapchat Ads Manager.
- Navigate to Business Settings > Pixels.
- Create a Snap Pixel and copy the Pixel ID.
- Under Business API, generate a CAPI Access Token.
π Step 2: Set Up GTM Server-Side Container
- Go to tagmanager.google.com.
- Create a new Server Container.
- Deploy the server container on App Engine (GCP) or Cloud Run.
- Set up a Custom Domain (e.g.,
tags.yoursite.com
) for the server GTM.
Configure the sGTM container to accept requests from your websiteβs domain.
βοΈ Step 3: Send Purchase Events to GTM Server Container
Modify your frontend tracking (e.g., GTM Web Container or Shopify Script Editor) to send purchase data to the server.
Hereβs a GTM Web Tag example to send data to your sGTM:
fetch('https://tags.yoursite.com/collect', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
event_name: 'Purchase',
email: 'user@example.com',
phone: '+1234567890',
value: 129.99,
currency: 'USD',
transaction_id: 'txn_123456789',
items: [
{
item_id: 'sku_001',
item_name: 'Sneakers',
quantity: 1,
price: 129.99
}
]
})
});
This sends purchase data to the GTM server container for further processing.
π₯ Step 4: Create Custom Snapchat CAPI Tag in GTM Server Container
In your Server Container:
π§ a) Create a New Tag
- Tag Type: Custom HTTP Request
- Name:
Snapchat CAPI Purchase
π§ b) Set Up HTTP Request Code
Hereβs an advanced Snapchat CAPI HTTP Request Template:
const pixelId = 'YOUR_PIXEL_ID';
const accessToken = 'YOUR_ACCESS_TOKEN';
const requestBody = {
pixel_id: pixelId,
event_type: 'PURCHASE',
timestamp: new Date().toISOString(),
event_conversion_type: 'WEB',
event_tag: 'purchase',
user: {
email: data.email ? hash(data.email) : undefined,
phone: data.phone ? hash(data.phone) : undefined
},
properties: {
currency: data.currency || 'USD',
price: data.value,
transaction_id: data.transaction_id,
items: data.items || []
}
};
const response = sendHttpRequest('https://tr.snapchat.com/v2/conversion', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`
},
body: JSON.stringify(requestBody)
});
return { response: response.body };
function hash(input) {
return CryptoJS.SHA256(input.trim().toLowerCase()).toString();
}
π‘ You may need to include CryptoJS if it’s not built-in, or pre-hash from your site.
π c) Trigger Configuration
Trigger the tag on custom event β e.g., event_name equals Purchase
.
π§ͺ Step 5: Test Snapchat CAPI Integration
- Go to Snapchat Events Manager.
- Choose your Pixel > View Events.
- Use
Snap Test Event Code
for debugging if needed. - Test a purchase event via your website.
- Validate if events are arriving from server-side (event source should say
CAPI
).
π Step 6: Secure & Optimize the Data Layer
- β Hash all user PII using SHA256
- β Use first-party domain in sGTM
- β Set proper CORS headers on sGTM server
- β Log and monitor failed requests
π Optional Enhancements
Feature | Benefit |
---|---|
Queue + Retry Logic | Handles Snapchat API timeouts/failures |
BigCommerce/Shopify Hooks | Automate server events from purchases |
Multi-Event CAPI Tags | Add AddToCart , ViewContent , etc. |
Offline Conversion Uploads | Match sales post-click using CSV uploads |
π Example JSON Payload to Snapchat CAPI
{
"pixel_id": "abc123",
"event_type": "PURCHASE",
"event_conversion_type": "WEB",
"timestamp": "2025-05-29T16:20:00Z",
"user": {
"email": "hashed_email",
"phone": "hashed_phone"
},
"properties": {
"currency": "USD",
"price": 199.99,
"transaction_id": "order_789",
"items": [
{
"item_id": "sku789",
"item_name": "Wireless Earbuds",
"quantity": 1,
"price": 199.99
}
]
}
}
π Troubleshooting Tips
Problem | Solution |
---|---|
Events not showing in UI | Use test event token or check logs in sGTM |
Hashing errors | Ensure SHA256 and lowercase + trimmed input |
CORS/403 Errors | Adjust server container headers for custom domains |
API Throttling | Monitor limits (200 QPS per account β Snapchat) |
β Summary
Setting up Snapchat CAPI via GTM Server-Side for product sales allows eCommerce stores to track purchase events more reliably, securely, and with better ad optimization.
If you’re investing in Snapchat Ads, CAPI is not optionalβitβs essential.