@sharedid-edge/module-clickid
The clickid module for SharedID Edge: it keeps the ad click IDs in your landing page's URL in server-set first-party cookies, so a conversion on a later page view, or a later visit, can still be attributed.
Ad platforms add a click ID to the landing page's URL: gclid, gbraid and wbraid (Google Ads), dclid (Display & Video 360), fbclid (Meta), msclkid (Microsoft Advertising) and ttclid (TikTok). Today each vendor's tag keeps its own with document.cookie (_gcl_aw, _fbc, _uetmsclkid), which Safari caps at 7 days, and at 24 hours on a page reached through a link decorated by a known tracker. The worker sees the landing page's URL on the first /_sid/sync or /_sid/v1 call of the page view. With this module it stores each click ID it finds in a cookie it sets itself, for 90 days from the click, where your conversion tags, analytics pipeline or server-side tagging can read it later.
Click IDs are never put in the /_sid/v1 payload: no eids, no ortb2, nothing in ext. They can't reach bidders.
Contents
- Turning it on
- The cookies
- Reading a click ID
- Who uses the click IDs
- Where the URL comes from
- Response
- Consent and opt-out
- Settings
- When it runs:
/_sid/syncand/_sid/v1 clickidorreflectfor Google's_gcl_aw?- Not yet supported
- Using it in code
- Troubleshooting
Turning it on
The module is built into every adapter. It does nothing until you list it in SID_MODULES.
Enable it, in
packages/adapters/cloudflare/wrangler.jsonc(the other adapters take the same variables):jsonc"vars": { "SID_MODULES": "clickid", // or e.g. "reflect,clickid" "SID_COOKIE_DOMAIN": ".example.com" // optional: share the cookies across your subdomains }No
SID_MODULE_CONFIGis needed for the seven default parameters. See Settings to turn some off, rename cookies or add parameters such as LinkedIn'sli_fat_id.Make sure the landing page calls the worker. If the page runs Prebid.js with SharedID Edge's
pixelUrl(Prebid.js setup), there's nothing to add: Prebid.js calls/_sid/syncon page views and the browser sends the landing page as theReferer. Otherwise, or to be independent of the referrer policy, call/_sid/v1with the page's URL as early as you can:html<script> fetch('/_sid/v1?url=' + encodeURIComponent(location.href), { credentials: 'include' }); </script>Add the consent parameters you have (
gdpr,gdpr_consent,us_privacy,coppa=1), as for any/_sid/v1call (see Consent).Deploy, then check with a made-up click ID:
shcurl -si 'https://www.example.com/_sid/v1?url=https%3A%2F%2Fwww.example.com%2F%3Fgclid%3Dtest-123' | grep -i '^set-cookie: _sid_' # Set-Cookie: _sid_gclid=1794447131.test-123; Max-Age=7776000; Expires=…; Path=/; Domain=.example.com; SameSite=Lax; Secure
The cookies
| Parameter | Ad platform | Cookie (default name) |
|---|---|---|
gclid | Google Ads | _sid_gclid |
gbraid | Google Ads (iOS app campaigns, web to app) | _sid_gbraid |
wbraid | Google Ads (iOS, app to web) | _sid_wbraid |
dclid | Display & Video 360, Campaign Manager 360 | _sid_dclid |
fbclid | Meta | _sid_fbclid |
msclkid | Microsoft Advertising | _sid_msclkid |
ttclid | TikTok | _sid_ttclid |
- Value:
<click time>.<id>: the time the worker saw the click, in Unix seconds, a dot, and the click ID exactly as it came, after one round of URL decoding. For example_sid_gclid=1794447131.EAIaIQobChMIexample_BwE. - Only safe values are stored: letters, digits and
.,_,~,-, at most 512 characters. Anything else (a value still percent-encoded, with spaces, or too long) is ignored, never rewritten. When a parameter appears twice in the URL, the first is used. - Lifetime:
maxAgeDays, 90 days by default, counted from the click. That's the longest click-through conversion window Google Ads allows (the default is 30 days), the retention Microsoft suggests formsclkid, and the lifetime of Google's_gcl_awand Meta's_fbccookies; Meta's and TikTok's attribution windows are shorter (see Who uses the click IDs). Later visits don't extend it. The same click ID seen again (a reload, a bookmarked landing URL) leaves the cookie as it is; a different click ID for the same parameter replaces it. - Attributes:
Path=/,SameSite=Lax,Secure(over https),Domainfrom the module'sdomain(elseSID_COOKIE_DOMAIN, else host-only;"domain": "auto"gives the domain Prebid.js reports on the request (cookie_domain, sent withpixelCookieDomain: true), checked against the host asSID_COOKIE_DOMAIN=autois, else none (host-only)), andHttpOnlyonly if you sethttpOnly: true. They're readable by page scripts by default, since the usual consumer is a conversion tag. - Cookies of other parameters are left alone: a
fbclidlanding doesn't touch_sid_gclid.
Reading a click ID
The ID is everything after the first dot (IDs may contain dots themselves):
function clickId(name) {
const cookie = document.cookie.split('; ').find(c => c.startsWith(name + '='));
if (cookie === undefined) return undefined;
const value = cookie.slice(name.length + 1);
const dot = value.indexOf('.');
return { id: value.slice(dot + 1), clickedAt: new Date(Number(value.slice(0, dot)) * 1000) };
}
// For example, with a conversion event in your analytics pipeline (RudderStack expects properties.gclid):
const gclid = clickId('_sid_gclid');
if (gclid !== undefined) rudderanalytics.track('Order Completed', { gclid: gclid.id, revenue: 42 });Server-side tagging on the same registrable domain (with SID_COOKIE_DOMAIN or domain set so the cookie reaches it) reads the same cookie from the request; with httpOnly: true, only server-side code can.
Who uses the click IDs
Vendor tags don't read _sid_* cookies: they keep writing their own. Send the stored ID to the platform from your own code, typically with a server-side conversion:
| Parameter | The vendor tag's own cookie | Sending a stored ID |
|---|---|---|
gclid, gbraid, wbraid | _gcl_aw, _gcl_gb (Google's cookie list, 90 days; Google doesn't document which holds gbraid or wbraid) | Google Ads API click conversions: gclid, gbraid, wbraid; send every one you have (Google) |
dclid | _gcl_dc (90 days) | Floodlight (Campaign Manager 360) |
fbclid | _fbc = fb.<n>.<milliseconds>.<fbclid> | Conversions API fbc. Build it as fb.1.<click time × 1000>.<id> and don't change the ID's case (Meta) |
msclkid | _uetmsclkid | Conversions API userData.msclkid; Microsoft suggests keeping the latest one for 90 days, as this module does (Microsoft) |
ttclid | ttclid (TikTok) | Events API ttclid, on every web event |
IDs the browser strips can't be kept: see Troubleshooting. Firefox's Strict mode also strips fbclid (Mozilla), and Brave strips fbclid, gclid and msclkid (Brave).
Other platforms can be added with params: LinkedIn li_fat_id, X twclid, Pinterest epik, Snapchat ScCid and Reddit rdt_cid.
Why it pays, and for whom
The mechanism. Safari caps cookies written by document.cookie at 7 days (WebKit), and at 24 hours on a page reached from a known tracker through a URL with a query string (WebKit), which is how most ad clicks arrive. A conversion after that, but still inside the platform's attribution window, has no click to be credited to. The platform then under-reports the campaign's conversions, and its automated bidding, which targets conversions or conversion value (Google), learns that the campaign returns less than it does: it bids lower, wins fewer of the auctions that actually convert, and the campaign looks less profitable to whoever sets its budget. Uploading the stored click ID with the conversion gives the platform back the click.
A click ID lands where the ad's click goes. The platform adds it to the advertiser's landing URL, so it reaches the site the visitor clicks to, not the site the ad was shown on. What this module keeps is the attribution of ads the site runs itself that bring visitors to its own pages. So it helps, directly, a site that buys traffic:
- A store or any advertiser sending paid clicks to its own pages: more of its Safari conversions are credited, so its smart bidding and reported return on ad spend reflect what the campaigns actually earn.
- A publisher that advertises itself: subscriptions, newsletters, app installs or events promoted on Google, Meta, Microsoft or TikTok, landing on its own site.
- A publisher that buys traffic to monetize it (traffic arbitrage): it pays the platforms for clicks and earns from the ads its pages show. It is the advertiser for that traffic. Platforms optimize its campaigns on the conversion events it reports back, such as engaged sessions or revenue per visit, so events that happen after Safari's caps, on a return visit or a later page, get credited to the campaign that bought the visitor, and its bidding buys more of the visitors who earn.
It doesn't, by itself, make a site's ad space worth more. Ads shown on your pages send their clicks, and their click IDs, to the advertisers' sites, so running this module on your site doesn't change how those advertisers measure your inventory. Click IDs never go to bidders either. There is an indirect effect when advertisers keep their click IDs: Google's display network and Meta's and Microsoft's audience networks tag clicks from publisher placements too, so an advertiser that keeps click IDs past Safari's caps credits more late conversions to the placements that drove them, and automated bidding pays more for placements that convert. That raises demand for inventory that drives Safari conversions, but it comes from advertisers adopting this kind of storage on their own sites, not from the publisher running it.
Where the URL comes from
In order:
- the
urlquery parameter of the request (the snippet above sendslocation.href); - otherwise the
Refererheader. A same-origin request sends the full page URL, query string included, under the browser's default referrer policy (strict-origin-when-cross-origin). This is what makes the/_sid/synccall from Prebid.js work with no page code.
Either way, the URL's host must be the request's own host or one listed in hosts; anything else is ignored. And the request itself must come from your site: one the browser marks Sec-Fetch-Site: cross-site, or whose Referer is on another host, stores nothing, even with a url on your host. So another site can't plant a click ID through a link to your worker. A request with neither header (curl, or a page with Referrer-Policy: no-referrer in a browser that doesn't send Sec-Fetch-Site) is judged by its URL alone.
Response
The module only sets cookies, so it reports empty and adds nothing to the payload. A landing page's /_sid/v1 call, with SID_COOKIE_DOMAIN=.example.com, real output:
GET /_sid/v1?url=https%3A%2F%2Fwww.example.com%2Fshoes%3Ffbclid%3DIwAR2example_aem
Cookie: _pubcid=c29cb2ae-769d-42f6-891a-f53cadee823d
HTTP/1.1 200 OK
Cache-Control: no-store
Content-Type: application/json; charset=utf-8
Set-Cookie: _sid_fbclid=1794447131.IwAR2example_aem; Max-Age=7776000; Expires=Wed, 10 Feb 2027 01:32:11 GMT; Path=/; Domain=.example.com; SameSite=Lax; Secure
Set-Cookie: _pubcid=c29cb2ae-769d-42f6-891a-f53cadee823d; Max-Age=31536000; Expires=Fri, 12 Nov 2027 01:32:11 GMT; Path=/; Domain=.example.com; SameSite=Lax; Secure
Set-Cookie: _pubcid_sv=c29cb2ae-769d-42f6-891a-f53cadee823d; Max-Age=31536000; Expires=Fri, 12 Nov 2027 01:32:11 GMT; Path=/; Domain=.example.com; SameSite=Lax; Secure; HttpOnly{
"v": 1,
"sharedid": "c29cb2ae-769d-42f6-891a-f53cadee823d",
"eids": [{ "source": "pubcid.org", "uids": [{ "id": "c29cb2ae-769d-42f6-891a-f53cadee823d", "atype": 1 }] }],
"ext": { "modules": { "clickid": { "ms": 0, "status": "empty" } } }
}The payload is the same with or without a click ID, and when consent denies storage. With invalid settings the status is error and nothing is set. On /_sid/sync, X-SharedID-Modules: clickid=empty shows it ran (see Responses).
Consent and opt-out
Click IDs exist to measure and attribute advertising, so the rules are at least as strict as for the SharedID. Nothing is stored, and the click ID cookies the browser has are deleted, when:
- the SharedID can't be stored: the opt-out cookie, Global Privacy Control (
Sec-GPC: 1),coppa=1, a TC string that doesn't give the SharedID's consent, or GDPR applying (bygdpr=1or the visitor's location) without a TC string; - US privacy: the
us_privacystring opts out of sale (its third character isY, as in1YYN). It's read from theus_privacyparameter, else from theusprivacycookie that IAB's CCPA framework uses, since Prebid.js's/_sid/synccall carries no consent parameters; - TCF: when there's a TC string (the
gdpr_consentparameter or the CMP'seuconsent-v2cookie) or GDPR applies, the publisher TC segment must consent to Purposes 1 and 7 (store and access information on a device; measure advertising performance).
Deleting needs the module to run, so it checks Purposes 1 and 7 itself rather than declaring them as module purposes (core skips a module with missing purposes before it runs).
Opt-out: /_sid/optout deletes every click ID cookie of the configuration the browser sent, whether or not clickid is in SID_MODULES, including parameters you've since switched off with enabled: false.
Vendor consent isn't checked. The worker doesn't decode per-vendor consent yet, so the module doesn't check consent for Google (GVL ID 755), Meta, Microsoft or TikTok, only the publisher purposes above. If your CMP setup needs vendor consent before a click ID is kept, call /_sid/v1 only after it's given, and keep clickid off /_sid/sync (SID_SYNC_MODULES, see When it runs).
Google Consent Mode (ad_storage, ad_user_data) lives in the page and never reaches the worker. If you use Consent Mode, call /_sid/v1 with url only once ad_storage is granted and keep clickid off /_sid/sync, or switch off gclid, gbraid, wbraid and dclid. Prebid.js issue #16159 proposes a Consent Mode v2 module for Prebid.js; until consent signals like that reach the worker, this is the page's job.
Settings
All optional, in SID_MODULE_CONFIG:
{
"clickid": {
"params": [
{ "name": "dclid", "enabled": false },
{ "name": "fbclid", "cookie": "fbclid_kept" },
{ "name": "li_fat_id", "cookie": "_sid_li_fat_id" }
],
"maxAgeDays": 90,
"domain": "example.com",
"httpOnly": false,
"hosts": ["shop.example.com"]
}
}| Setting | Default | What it does |
|---|---|---|
params | the seven above | Entries { "name", "cookie"?, "enabled"? }. One naming a default parameter changes it (enabled: false turns it off; cookie renames its cookie); any other adds a parameter, kept in cookie (default _sid_<name>). Names start with a letter, then letters, digits, _ or - (at most 64), and match case-sensitively (ScCid isn't sccid). At most 20 parameters in all. |
maxAgeDays | 90 | The cookies' lifetime from the click, 1 to 400 days. |
domain | SID_COOKIE_DOMAIN | example.com for Domain=.example.com, host-only for no Domain, or auto for the domain Prebid.js reports on the request (cookie_domain), else no Domain. |
httpOnly | false | true hides the cookies from page scripts, for server-side consumers only. |
hosts | none | Other hostnames (lower case, up to 20) whose URLs count as landing pages, for a landing page on one host whose /_sid/v1 call goes to another. The request's own host always counts. Only hosts on the same site (registrable domain) as the worker work from a browser, which marks a call from another site Sec-Fetch-Site: cross-site. |
Cookie names can't be _pubcid, _pubcid_sv, _pubcid_optout, ts-ec, euconsent-v2 or _sid_keep (the reflect module's keeper), nor your configured SharedID cookie names, and two parameters can't share a cookie. Any other mistake (an unknown key, a wrong type, a duplicate) makes the module report error on every call and set nothing; the error doesn't say which value is wrong, so check against this table.
When it runs: /_sid/sync and /_sid/v1
Its routes are v1 and sync. On /_sid/sync, the call Prebid.js makes on page views, it reads the landing page from the Referer.
Syncs aren't cached while it runs there. Normally the browser reuses a sync response for SID_SYNC_CACHE_SECONDS (a day). The browser's cache is keyed on the sync URL, which is the same on every page, so a cached sync would skip the worker on every landing page until it expired, and miss those clicks. So whenever clickid runs on /_sid/sync, the response is Cache-Control: no-store: one worker request per page view that calls pixelUrl, instead of one a day. If that's too many requests, keep it on /_sid/v1 only, with the snippet on your pages, by listing the other modules in SID_SYNC_MODULES:
"SID_MODULES": "reflect,clickid",
"SID_SYNC_MODULES": "reflect" // or "none"clickid or reflect for Google's _gcl_aw?
They do different jobs:
reflectkeeps cookies the page already wrote. If Google's tag (with the conversion linker) writes_gcl_awand your Google Ads conversions read it,reflectwithrestorekeeps that cookie server-set and brings it back after Safari deletes it. Google's tags keep working unchanged.clickidwrites cookies of its own from the URL, which no tag has to have written. Use it when the consumer is your code: an analytics or event pipeline (RudderStack'sproperties.gclid, Jitsu), offline conversion uploads, server-side tagging, or a platform whose tag you don't run. It coversgbraidandwbraid, whose cookie Google doesn't document, and non-Google platforms.
Using both is fine: they set different cookies. For gclid you rarely need both.
Not yet supported
- Vendor cookie formats. Writing the platforms' own cookies (
_gcl_aw=GCL.<seconds>.<gclid>,_fbc=fb.1.<milliseconds>.<fbclid>,_uetmsclkid=_uet<msclkid>), so vendor tags pick them up unchanged, is a planned follow-up. Meta documents_fbc; the_gcl_awand_uetmsclkidvalue formats aren't documented by Google or Microsoft (GCL.<seconds>.<gclid>is what third-party implementations write), so each has to be checked against the vendor's tag, and the cookies compete with the vendors' own tags and server-side copies. - Per-vendor TCF consent (above).
Using it in code
import { createHandler, resolveConfig } from '@sharedid-edge/core';
import { clickIdModule, clickIdModuleConfig } from '@sharedid-edge/module-clickid';
const handler = createHandler({ config: resolveConfig({ SID_MODULES: 'clickid' }), modules: [clickIdModule] });
clickIdModuleConfig({ params: [{ name: 'li_fat_id' }] }); // validates settings; throws a TypeError on a mistakeThe package also exports landingUrl, clickIdFrom and storedClickId, the steps above, and clickIdDenial, the consent check.
Troubleshooting
- No
_sid_*cookie after landing with?gclid=…:- Check
ext.modules.clickidin the/_sid/v1response (orX-SharedID-Moduleson/_sid/sync).errormeans invalid settings; no entry meansclickidisn't inSID_MODULES(or, on/_sid/sync, not inSID_SYNC_MODULES). X-SharedID-Status: denied: …on the response means consent denied storage; so do aus_privacyopt-out of sale and a TC string without Purpose 7, which leave no header. See Consent and opt-out.- The referrer policy. Without
url, the module needs the full landing URL in theReferer. A page or site withReferrer-Policy: no-referrer,originorstrict-origin(as a header or a<meta name="referrer">tag) sends no query string, so there's nothing to find. Use the snippet withurl, or a policy that keeps same-origin URLs (strict-origin-when-cross-origin, the default, orsame-origin). - The landing page doesn't call the worker. The click ID is only in the landing page's URL. A landing page without Prebid.js (or whose sync doesn't fire on that page) and without the
/_sid/v1snippet passes it by, and the next page's URL no longer has it. Add the snippet to landing pages. - The URL is on another host: a landing page on
shop.example.comcalling the worker onwww.example.comneeds"hosts": ["shop.example.com"]. - On AWS (Lambda behind CloudFront), the function doesn't see your site's host unless
SID_PUBLIC_ORIGIN(the template'sSidPublicOrigin) is your site's origin, so every landing page looks like it's on another host. See the Lambda adapter's The site's host. - The value was rejected: values with characters outside letters, digits and
._~-, still percent-encoded, or longer than 512 characters are ignored. Real click IDs fit; a test value liketest 123doesn't. - Safari strips some parameters. Safari's Link Tracking Protection removes known click IDs, such as
gclidandfbclid, from URLs in Private Browsing, in links opened from Mail and Messages, and with Advanced Tracking and Fingerprinting Protection on. The page never sees them, so there's nothing to keep. That's expected, not something to work around.
- Check
- The cookie's expiry doesn't move on later visits. By design: the lifetime counts from the click. A new click ID replaces it.
- A click on a second landing page wasn't kept. With
clickidon/_sid/syncthe sync isn't cached; check thatCache-Controlon/_sid/syncisno-store. If it showsprivate, max-age=…,clickiddidn't run there.