Skip to content

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 ​

  1. CashMyCell redirects users to your website with cmc_id appended as a URL parameter
  2. Script 1 captures the cmc_id and stores it in a browser cookie
  3. Script 2 reads the stored cmc_id upon 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 without async attribute 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
const referenceId = "order_123"; //  Replace with actual unique identifier

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) +
    "&reference_id=" + encodeURIComponent(referenceId) +
    "&ts=" + Date.now();
}

Implementation Notes ​

  • Replace orderValue with 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 ​

  1. Dynamic Order Value: Always replace "1499" with actual order value from your system
  2. Timing: Execute this script AFTER the order is confirmed in your system
  3. No Dependencies: Script works independently, no external libraries needed
  4. 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, referenceId? }) {
  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)}&reference_id=${encodeURIComponent(referenceId)}&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';
  const referenceId = document.querySelector('.woocommerce-order-id')?.textContent || '';

  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)}&reference_id=${encodeURIComponent(referenceId)}&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 }}';
  const referenceId = '{{ order.order_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)}&reference_id=${encodeURIComponent(referenceId)}&ts=${Date.now()}`;
  }
})();
</script>
{% endif %}

Troubleshooting ​

Script not capturing cmc_id ​

  • Check URL: Verify CashMyCell is sending cmc_id in 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 orderValue is being replaced with actual value
  • Network tab: Check if tracking pixel request was sent in DevTools
  • Cookie presence: Use DevTools to verify cmc_id cookie exists

Common Issues ​

IssueSolution
Script runs but no cookieCheck URL has ?cmc_id=value parameter
Cookie exists but conversion not sentVerify Script 2 is on confirmation page
Order value shows as wrongEnsure dynamic value replacement before execution
Multiple tracking callsAdd guard to prevent duplicate Script 2 execution

Next Steps ​

CashMyCell Conversion Tracking API · Developed by Panicle Tech