how to keep utm_source data in database when a user sign up via this utm_source

StackOverflow https://stackoverflow.com/questions/18243192

  •  24-06-2022
  •  | 
  •  

Pergunta

I need to keep the new member's origin. I use utm_source for every external source. How can I keep that record from the utm_source inside link when a user from a source e.g. utm_source=facebook, come to my site and sign up? I need to see the source for each members in my database.

Foi útil?

Solução

Google Analytics stores visitor referral information in a cookie called __utmz. After this cookie is set, its contents will be sent with every subsequent request to your domain from that user. So, when a user signs up, you can grab the contents of this cookie and save it to your database. Below are a few links that should help get you started.

Outras dicas

It's not working anymore. I save utm into cookies via js and then save it into DB. Here is a js script:

// Save UTM into cookies
var url = new URL(window.location.href);
var utm_date = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
var utm_source = url.searchParams.get("utm_source");
if (utm_source) {
    document.cookie = "utm_source="+utm_source+"; expires=" + utm_date.toUTCString();
}
var utm_medium = url.searchParams.get("utm_medium");
if (utm_medium) {
    document.cookie = "utm_medium="+utm_medium+"; expires=" + utm_date.toUTCString();
}
var utm_campaign = url.searchParams.get("utm_campaign");
if (utm_campaign) {
    document.cookie = "utm_campaign="+utm_campaign+"; expires=" + utm_date.toUTCString();
}

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top