Documentation & Setup Guide
🚀 Quickstart
Get your CJ (Commission Junction) tracking up and running in 5 simple steps. This guide will walk you through the complete setup process.
Estimated Time: 10-15 minutes
📋 Step-by-Step Setup
Get Your CJ Credentials
Before you begin, you'll need the following information from your CJ Affiliate account:
- Enterprise ID: Your CJ Enterprise identifier (contact your CJ Affiliate account manager to get this)
- Advertiser ID: Your advertiser account ID (Your CJ Affiliate account number)
- Action Tracker ID: The tracking ID for your program (contact your CJ Affiliate account manager to get this)
- API Token: Your CJ API authentication token (Log into your CJ Affiliate account → Settings → API Access → Generate API Token)
Configure Your Storefront
Navigate to the Settings page and select your storefront from the dropdown.
Fill in the following fields:
- Enterprise ID
- Advertiser ID
- Action Tracker ID
- API Token (click the eye icon to toggle visibility)
- Mode: Select
Testfor sandbox testing orLivefor production - Currency: Your store's default currency (e.g., USD)
Important: Always test in Test mode first before switching to Live.
Install the Tracking Script
After saving your configuration, click the "Install Script" button in the Settings page.
This will automatically inject the tracking script into your BigCommerce storefront. The script will:
- Capture CJ tracking parameters (
cjeventandcjdata) from affiliate links - Store them in cookies with a 30-day expiration
- Send click data to our backend for storage
- Detect order confirmations and sync order data to CJ
Success Indicator: You should see a green "Script installed successfully" message.
Test the Integration
To verify everything is working correctly:
- Visit your storefront with a test affiliate link containing CJ parameters:
https://yourstore.com/?cjevent=test123&cjdata=test456
- Check the browser console for
[CJ Tracker]log messages - Navigate to the Logs page to see if the click was recorded
- Complete a test purchase and check the Orders page to verify order sync
Monitor and Verify
Once set up, you can monitor your tracking through:
- Dashboard: View conversion summaries, revenue, and retry queue status
- Orders Page: See all tracked orders with their CJ sync status
- Logs Page: Review all API calls, errors, and debugging information
📊 What Data is Tracked
Click Tracking Data
When a customer clicks an affiliate link, the following data is captured and stored:
| Data Field | Source | Description | Storage |
|---|---|---|---|
cjevent | URL Parameter | CJ Event identifier from the affiliate link (e.g., 3c92d6abc25311f0838302140a18b8f6) | Cookie (30 days) + Database |
cjdata | URL Parameter | CJ Data identifier from the affiliate link (e.g., MXxOfDB8WXww) | Cookie (30 days) + Database |
sessionId | Generated | Unique session identifier created on first visit (stored in cookie) | Cookie (30 days) + Database |
ipAddress | Request Headers | Customer's IP address (from x-forwarded-for or x-real-ip headers) | Database |
userAgent | Browser | Customer's browser user agent string | Database |
storeHash | BigCommerce | Your BigCommerce store identifier | Database |
channelId | BigCommerce | Sales channel ID (for multi-channel stores) | Database |
siteId | BigCommerce | Site ID (for Catalyst storefronts) | Database |
Order Tracking Data
When a customer completes a purchase, the following order data is synced to CJ:
| Data Field | Source | Description |
|---|---|---|
orderId | BigCommerce Order | BigCommerce order ID |
cjevent | Cookie (from click) | CJ Event identifier captured during the initial click |
cjdata | Cookie (from click) | CJ Data identifier captured during the initial click |
amount | BigCommerce Order | Order total amount (extracted from order.total_inc_tax or order.total) |
currency | BigCommerce Order / Config | Order currency (from order.currency_code or configured default) |
eventTime | Generated | ISO timestamp of when the order was synced |
⚙️ How It Works
Tracking Flow
Here's the complete flow of how CJ tracking works in this app:
Customer Clicks Affiliate Link
Customer visits your store via an affiliate link containing CJ parameters:
https://yourstore.com/products/item?cjevent=abc123&cjdata=xyz789
Script Captures Parameters
The tracking script (tracker.js) automatically:
- Extracts
cjeventandcjdatafrom URL parameters - Stores them in browser cookies with 30-day expiration
- Sends click data to
/api/save-clickendpoint - Backend stores click data in database (prevents duplicates)
Customer Browses and Purchases
As the customer navigates your store, the CJ parameters remain in cookies. When they complete checkout:
- Script detects order confirmation page (checks URL path and DOM elements)
- Extracts order ID from BigCommerce data or page elements
- Retrieves
cjeventandcjdatafrom cookies
Order Sync to Backend
Script sends order data to /api/sync-order endpoint:
- Backend fetches full order details from BigCommerce API
- Extracts order amount, currency, and other required fields
- Checks for existing order to prevent duplicates
- Creates order record in database with status
pending
Post to CJ API
Backend posts order to CJ Tracking API (GraphQL):
- Uses configured credentials (Enterprise ID, Action Tracker ID, API Token)
- Sends
createOrdersmutation with order data - Updates order status to
senton success orfailedon error - If CJ credentials are missing or API fails, creates OutboxJob for retry
- Clears CJ cookies after successful sync to prevent duplicate submissions
🔌 API Endpoints
Internal APIs
The app uses the following API endpoints:
POST /api/save-click
Saves CJ click tracking data when a customer visits via an affiliate link.
Request Body:
{
"storeHash": "string",
"channelId": "number",
"siteId": "number",
"cjevent": "string",
"cjdata": "string",
"sessionId": "string",
"userAgent": "string"
}POST /api/sync-order
Syncs order data to CJ when a customer completes a purchase.
Request Body:
{
"storeHash": "string",
"channelId": "number",
"siteId": "number",
"orderId": "string",
"cjevent": "string",
"cjdata": "string"
}GET /api/orders
Retrieves paginated list of orders with filtering and sorting.
GET /api/logs
Retrieves paginated list of API call logs with filtering and sorting.
GET /api/storefronts/[storefrontId]/config
Gets or updates storefront configuration (CJ credentials, settings).
POST /api/storefronts/[storefrontId]/script
Installs or uninstalls the tracking script in BigCommerce.
🔧 Troubleshooting
Common Issues
Script Not Installing
- Verify your BigCommerce API credentials are correct
- Check that you have the necessary permissions (Scripts API access)
- Ensure your storefront (channel/site) is correctly configured
- Check the browser console and Logs page for error messages
Orders Not Syncing to CJ
- Verify CJ credentials are correct in Settings (Enterprise ID, Advertiser ID, Action Tracker ID, API Token)
- Check that you're in the correct mode (Test vs Live)
- Ensure CJ parameters (
cjevent,cjdata) are present in cookies before checkout - Check the Logs page for CJ API errors
- Verify order status in Orders page - failed orders will show error details
Duplicate Orders
- The app prevents duplicates by checking for existing orders with the same store ID and order ID
- CJ cookies are automatically cleared after successful order sync
- If you see duplicates, check the Orders page for order status and attempt count
Missing CJ Parameters
- Ensure affiliate links include
cjeventand/orcjdataparameters - Check browser console for
[CJ Tracker]log messages - Verify cookies are being set (check browser DevTools → Application → Cookies)
- Ensure cookies haven't expired (30-day expiration)
❓ Frequently Asked Questions
Q: Do I need to modify my storefront code?
A: No! The tracking script is automatically injected into your BigCommerce storefront via the BigCommerce Scripts API. No code changes are required.
Q: What happens if a customer clears their cookies?
A: If cookies are cleared before checkout, the order will still be created in your database, but it won't be synced to CJ (since CJ parameters are required). The order will show as pending status.
Q: Can I test without real affiliate links?
A: Yes! You can manually add CJ parameters to any URL:
https://yourstore.com/?cjevent=test123&cjdata=test456Make sure you're in
Test mode in Settings.Q: How long are CJ parameters stored?
A: CJ parameters are stored in cookies for 30 days. After a successful order sync, they are automatically cleared to prevent duplicate submissions.
Q: What's the difference between Test and Live mode?
A: Test mode posts to CJ's sandbox environment (tracking.api.cj.com/graphqltest), while Live mode posts to production (tracking.api.cj.com/graphql). Always test in Test mode first!
Q: What if an order fails to sync to CJ?
A: Failed orders are stored in the OutboxJob queue for retry. You can view failed orders in the Orders page and manually retry them (retry functionality coming soon).
Q: Can I use this with multiple storefronts?
A: Yes! Each storefront can have its own CJ configuration. Use the storefront selector in the header to switch between storefronts.
💬 Support & Resources
Need additional help? Here are some resources:
- View Logs: Check API calls and errors in real-time
- View Orders: Monitor order sync status and troubleshoot issues
- Settings: Review and update your CJ configuration
For technical support or questions, please contact your development team or refer to the CJ Affiliate API documentation.