How to get the original referrer url on success page?

How to get the original referrer url on success page?

July 23, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get the original referrer url on success page?

Tracking Commission Junction Referrals on Magento Success Page

Tracking where your customers come from is essential for optimizing your marketing efforts and maximizing ROI. In this post, we’ll show you how to determine if the buyer’s original referrer URL came from a Commission Junction (CJ) affiliate link on the success page in Magento.

Identifying the Original Referrer URL

The referral_url variable changes with each navigation between pages during checkout. However, the original referrer remains constant throughout the shopping journey. To access this information, we’ll use the $_SERVER['HTTP_REFERER'] PHP constant, which stores the address of the page that referred you.

Checking for Commission Junction Referrals

Commission Junction affiliate links follow a specific pattern: http://www.jdoqocy.com/click-1245-2342423?SID=TrackingTest. To check if the original referrer matches this format, we can use regular expressions (regex) to match the URL against a pattern.

Here’s an example function that checks for Commission Junction referrals:

public static function isCJReferral()
{
    $referrer = $_SERVER['HTTP_REFERER'];
    $pattern = '/^http:\/\/www\.jdoqocy\.com\/click-\d+-\d+\?SID=[\w-]+$/';

    return (preg_match($pattern, $referrer)) ? true : false;
}

This function retrieves the HTTP_REFERER value and checks if it matches the pattern for Commission Junction affiliate links using preg_match(). If there’s a match, it returns true; otherwise, it returns false.

Integrating with Your Current Function

Now let’s integrate this functionality into your existing getCommissionJunctionUdo() function:

public function getCommissionJunctionUdo($orderId)
{
    // ... (existing code)

    if (self::isCJReferral()) {
        $udo['FIRECJ'] = "TRUE";
    } else {
        $udo['FIRECJ'] = "FALSE";
    }

    // ... (remaining code)
}

We’ve added a call to our new isCJReferral() function and used its return value to set the $udo['FIRECJ'] variable accordingly.

Conclusion

Tracking original referrer URLs is an effective way to understand how customers find your store. By using PHP’s built-in constants and regular expressions, you can easily identify Commission Junction affiliate links and adjust your marketing strategy for better performance.

Remember that tracking must comply with data protection regulations and privacy policies. Always ensure you have the necessary consent before collecting and processing user data.

For more advanced tracking techniques and tools to enhance your Magento e-commerce experience, check out our guide on Advanced Magento Tracking Techniques at Laravel Company.

Happy coding!

Checkout Performance Customers CLI

Our network