Integration Guide
Complete guide to integrating CashMyCell Conversion Tracking API into your website.
Overview
CashMyCell uses a click identifier (cmc_id) passed via URL parameters to track user journeys from redirection to successful order completion. The integration requires adding two JavaScript snippets at specific points in your flow.
Flow Summary
- CashMyCell redirects users to your website with
cmc_idappended as a URL parameter - Script 1 captures the
cmc_idand stores it in a browser cookie - Script 2 reads the stored
cmc_idupon order confirmation and sends the conversion data to the CashMyCell tracking endpoint
Script 1 – Capture and Store cmc_id
Place this script on your product redirection / landing page. Its purpose is to extract the cmc_id from the URL and store it as a cookie for later use.
javascript
const params = new URLSearchParams(window.location.search);
const cmcId = params.get("cmc_id");
if (cmcId) {
document.cookie = "cmc_id=" + cmcId + "; path=/; max-age=2592000";
}Implementation Notes
- The cookie expiry is set to 30 days (2592000 seconds)
- Ensure this script runs on every entry page where users may land from CashMyCell
- Place it in your page's
<head>or early in the<body>tag - No DOM manipulation required, runs asynchronously
Best Practices
- Run this script as early as possible on page load
- Use it on all landing pages where CashMyCell traffic may arrive
- Consider wrapping in a
<script>tag withoutasyncattribute for guaranteed execution
Script 2 – Order Completion Tracking
Place this script on your checkout confirmation / order success page. It retrieves the stored cmc_id and notifies CashMyCell that an order has been completed.
javascript
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(";").shift();
return null;
}
const cmcId = getCookie("cmc_id");
const orderValue = "1499"; // Replace with actual order value
if (cmcId) {
const img = new Image();
img.src = "https://api.cashmycell.com/api/v1/public/order-complete" +
"?status=COMPLETED" +
"&order_value=" + encodeURIComponent(orderValue) +
"&cmc_id=" + encodeURIComponent(cmcId) +
"&ts=" + Date.now();
}Implementation Notes
- Replace
orderValuewith the actual order amount at runtime - The request is sent as a tracking pixel (Image request), so no UI impact occurs
- Ensure this script executes only after a successful order
- Place on the order confirmation/thank you page
Important Considerations
- Dynamic Order Value: Always replace
"1499"with actual order value from your system - Timing: Execute this script AFTER the order is confirmed in your system
- No Dependencies: Script works independently, no external libraries needed
- Error Handling: Even if request fails, it won't affect user experience
Example Implementations
React Component
jsx
import { useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';
// Script 1: Capture and store cmc_id
export function CaptureTracking() {
useEffect(() => {
const params = new URLSearchParams(window.location.search);
const cmcId = params.get('cmc_id');
if (cmcId) {
document.cookie = `cmc_id=${cmcId}; path=/; max-age=2592000`;
}
}, []);
return null;
}
// Script 2: Track order completion
export function OrderCompleteTracking({ orderValue }) {
useEffect(() => {
const getCookie = (name) => {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
return null;
};
const cmcId = getCookie('cmc_id');
if (cmcId) {
const img = new Image();
img.src = `https://api.cashmycell.com/api/v1/public/order-complete?status=COMPLETED&order_value=${encodeURIComponent(orderValue)}&cmc_id=${encodeURIComponent(cmcId)}&ts=${Date.now()}`;
}
}, [orderValue]);
return null;
}Plain JavaScript (WooCommerce/WordPress)
javascript
// Add to header.php or theme's functions.php
(function() {
const params = new URLSearchParams(window.location.search);
const cmcId = params.get('cmc_id');
if (cmcId) {
document.cookie = `cmc_id=${cmcId}; path=/; max-age=2592000`;
}
})();
// Add to order-received.php or thank-you page template
(function() {
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
return null;
}
const cmcId = getCookie('cmc_id');
const orderValue = document.querySelector('.woocommerce-price-amount')?.textContent || '0';
if (cmcId) {
const img = new Image();
img.src = `https://api.cashmycell.com/api/v1/public/order-complete?status=COMPLETED&order_value=${encodeURIComponent(orderValue)}&cmc_id=${encodeURIComponent(cmcId)}&ts=${Date.now()}`;
}
})();Shopify (Liquid Template)
liquid
<!-- Add to theme.liquid header section -->
<script>
(function() {
const params = new URLSearchParams(window.location.search);
const cmcId = params.get('cmc_id');
if (cmcId) {
document.cookie = `cmc_id=${cmcId}; path=/; max-age=2592000`;
}
})();
</script>
<!-- Add to order confirmation page (thank-you.liquid) -->
{% if order %}
<script>
(function() {
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
return null;
}
const cmcId = getCookie('cmc_id');
const orderValue = '{{ order.total_price }}';
if (cmcId) {
const img = new Image();
img.src = `https://api.cashmycell.com/api/v1/public/order-complete?status=COMPLETED&order_value=${encodeURIComponent(orderValue)}&cmc_id=${encodeURIComponent(cmcId)}&ts=${Date.now()}`;
}
})();
</script>
{% endif %}Troubleshooting
Script not capturing cmc_id
- Check URL: Verify CashMyCell is sending
cmc_idin the URL parameter - Cookie permissions: Ensure third-party cookies are not blocked
- Timing: Confirm Script 1 runs before user navigates away
- Check browser console: Look for any JavaScript errors
Conversion not tracking
- Check Script 2 placement: Ensure it's on the order confirmation page
- Verify order value: Confirm
orderValueis being replaced with actual value - Network tab: Check if tracking pixel request was sent in DevTools
- Cookie presence: Use DevTools to verify
cmc_idcookie exists
Common Issues
| Issue | Solution |
|---|---|
| Script runs but no cookie | Check URL has ?cmc_id=value parameter |
| Cookie exists but conversion not sent | Verify Script 2 is on confirmation page |
| Order value shows as wrong | Ensure dynamic value replacement before execution |
| Multiple tracking calls | Add guard to prevent duplicate Script 2 execution |
Next Steps
- See API Details for endpoint specifications
- Contact Support for integration assistance