Getting the Google CLID Parameter

Hi All.

I am trying to extract the google CLID Parameter when People
click on my Ads from inside my Worker Script.

Something i must be doing wrong becouse i never see the google CLID Parameter in my Script.
It should be not hard to extract but somehow it does not work.

Here is what i use atm in my Worker:

    const refererpage = request.headers.get("Referer")
    
     // Change status and statusText, but preserve body and headers
    let response = new Response('', {
        status: 302,
        statusText: "HTTP/2",
        headers: {                
            link: "</googleads.php?urlref=" + encodeURIComponent(refererpage) + ">; rel=preload; as=document; crossorigin",
            location: "https://worker-redirectpage.com/landingpage"
        },
    })

    return response

While the above script redirects the User to the Landing Page without any Problems
i dont see in the googleads.php call any gclid parameter.
I only see the domain without any parameters like this:

urlref=https%3A%2F%2Fwww.google.ch%2F

Could it be that the Command “encodeURIComponent(refererpage)” strips the parameters ?
What i am doing wrong and how can i get the Google CLID from my AdWords Clicks inside the Worker ?

Thank you in advance for any help !

There is no gclid param in the Referer URL.

If what you need is the gclid you need to get it from the request.url:

const url = new URL(request.url)
const {searchParams} = url
const gclid = (searchParams.has('gclid')) ? searchParams.get('gclid') : ''
2 Likes

Hi escribeme !

Thank you very much for your Helpfull Answer !
Your Tip solved the Problem !

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.