Implement Click ID Persistence
The click ID (rdt_cid) is a match key that helps attribute click conversions more accurately. It’s appended to the landing page URL when a user clicks through an ad from Reddit. We recommend sharing it for all available conversion events.
By default, this match key is automatically shared when passing events with the Reddit Pixel. You can implement click ID persistence to share it for the Conversions API (CAPI).
Click ID will be automatically passed when integrating with Tealium or the Ads Manager Google Tag Manager flow.
Before you start
- Set up CAPI. Here’s how to get started.
- Ensure your landing pages preserve URL parameters. This keeps the click ID intact through redirects.
1. Find the click ID
You can retrieve the click ID from your landing page’s URL.
// Get the click ID (rdt_cid) from the URL
function getClickIdFromUrl() {
const params = new URLSearchParams(window.location.search);
return params.get('rdt_cid');
}
const clickId = getClickIdFromUrl();
2. Set up click ID persistence
Choose one method to ensure the click ID persists:
- URL
- Cookies
- Storage
- Forms
- Server
- Variables
Read the click ID from your URL (e.g., ?rdt_cid=123).
Recommended for static or low-complexity sites. Not for cases where you want to hide parameters or keep the URL clean.
example.com/page?rdt_cid=123
Ensure compliance with regional consent requirements when using browser-based storage.
Store the click ID as a browser cookie on initial page load. This value persists across pages and sessions if not deleted.
Recommended for traditional, multi-page websites. Requires cookie consent and will fail if cookies are disabled.
// Set a cookie
document.cookie = `rdt_cid=${clickId}; path=/; expires=Fri, 31 Dec 9999 23:59:59 GMT`;
// Read a cookie
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
Ensure compliance with regional consent requirements when using browser-based storage.
Save the click ID in the browser’s localStorage or sessionStorage using the Web Storage API.Tip: Use localStorage to persist between sessions and sessionStorage to persist until the tab closes.
Useful for single-page apps or websites that don’t rely on cookies.
// Option 1: Local storage
localStorage.setItem('rdt_cid', clickId);
const storedClickId = localStorage.getItem('rdt_cid'); //retrieve from storage
// Option 2: Session storage
sessionStorage.setItem('rdt_cid', clickId);
const storedClickId = sessionStorage.getItem('rdt_cid'); //retrieve from storage
Include the click ID as a hidden input in forms to pass back to your server automatically.
Great for forms or checkout flows where form submissions trigger conversions.
<form action="/submit" method="post">
<input type="hidden" id="rdt_cid_field" name="rdt_cid" value="">
<!-- other form fields -->
<button type="submit">Submit</button>
</form>
<script>
// Populate the hidden field with the click ID, if available
if (clickId) {
document.getElementById('rdt_cid_field').value = clickId;
}
</script>
Store the click ID in the user’s server-side session upon landing and reuse it for backend event processing.
Recommended for sites already handling user sessions. Recommended for securing data and avoiding browser storage limits.
Assign the click ID to a global JavaScript variable for access across on-page scripts.
Good for single-page applications or light-weight JS-based flows. Only persists for the current page view.
let rdt_cid = clickId; // Use this variable in your scripts
3. Test your integration
When ready, test your setup to check that the click ID is being preserved and passed. Open your test URL and select your ad. Ensure the rdt_cid value in the landing page URL matches data.events[].click_id in your CAPI event payload.