Tracking Click IDs with Cookies for Event Attribution
A common practice is to send traffic to a site through Aftrad. This approach enables the analysis of incoming traffic and allows you to track events, making it possible to measure how effective the traffic is.
One challenge that website owners often face when implementing event tracking is how to store the click_id
passed by Aftrad, so that it can later be used to trigger postback events.
Storing the Click ID in Browser Cookies
An easy and effective solution is to store the click_id
in a browser cookie. This can be done by placing a small JavaScript snippet just before the closing </body>
tag of your webpage.
Below is an example of JavaScript code that extracts the click_id
parameter from the URL and stores it in a cookie for 30 days:
<script>
(function() {
const urlParams = new URLSearchParams(window.location.search);
const clickId = urlParams.get('click_id');
if (clickId) {
// Store in cookie for 30 days
document.cookie = `aftrad_click_id=${clickId}; path=/; max-age=${60 * 60 * 24 * 30}`;
console.log('click_id stored in cookie:', clickId);
}
})();
</script>
Notes:
This script should be placed just before the closing
</body>
tag.You can later retrieve this cookie value to include it in your postback URL when sending conversion events to Aftrad.