How to get the GA4 Client ID in a few ways because you need to use the Client ID in some way ➡ ➡ ➡
1. You are in the land of "I have little control and I'm desperate":The Client Id is cookie, and you could try to grab the cookie with two variablesconst cookieObjCid = new URLSearchParams(document.cookie.replaceAll("&", "%26").replaceAll("; ", "&"));
const gaClientId = cookieObjCid.get("_ga").match(/[0-9]+\S[0-9]+$/g);
2. You have the power of the backend and call on the forces of gtag API:After you run the config tag, then do this or that...gtag("get", "G-MEASUREMENTID", "client_id", resolve); });
gtagClient.then((client_id) => {
window.gtagClient1 = client_id;
});
OR
gtag("get", "G-MEASUREMENTID", "client_id", (client_id) => {
window.gtagClient2 = client_id;
});
3. You think GTM is amazing and the people that create community templates are really great people for sharing:In that case, Simo has a template #IYKYK 😎