I have a problem with GA4.
I need the first time a user visits the site (when he does not have any cookies google) with the first pageview sent a cookie _ga which stores ClientID and another cookie with information about the session.
In previous version of GA3 counter you could use parameter gtag('config', 'UA-XXXXXX-YY', { send_page_view: false })
In that case, the counter would create a cookie, but would not send pageview. After creating the cookie, we sent gtag('config', .... ) with the ClientID parameters we wanted.
But in GA4 when using gtag('config', 'MEASUREMENT_ID', { send_page_view: false }) the cookie is not set at all.
Does anyone know how to make the cookies are created but the pageview is not sent?
Without GTM!
I had the same problem.
Ad blockers
Check if nothing is blocking the sending to GA in your browser, like AD blockers or even Firefox:
Misconfiguration of data layer
Maybe your data layer is corrupted. Try to copy the exact snippet from GA.
Cookie Consent Tools
Maybe some Consent Tools are blocking cookies, try:
gtag('consent', 'update', {
ad_storage: 'granted',
analytics_storage: 'granted',
});
Final
If all it's ok, GA will send collect requests:
Related
I have a sub-domain that I am unable to put GTM or GA tracking code on. I have GA on the main domain.
I can retrieve the _ga cookie and get the Client ID but but if a user has not been to the main website they won't have one.
My question is:
Can I set a cookie called _ga (in the same format as GA sets it) and will this get picked up by GA if the user then goes back to the main website?
This article seems to be what you need:
Cookie Settings And Subdomain Tracking In Universal Analytics
https://www.simoahava.com/analytics/cookie-settings-and-subdomain-tracking-in-universal-analytics/
I have enabled userId feature in Google Analytics.
On Login page i am setting userId. and also on other pages which user visits after login.
Problem:
User A logs In
User A logs out
User B logs(in same browser session)
User B logs out
User A logs in again logs( In same browser session)
User A log out
In user explorer report for above scenario in google analytics, Count of sessions for user A and B is 1 and 1 respectively.
And also, User A session duration includes the timing of user B' session duration
Expected:
user A should have 2 sessions count and user B should have one.
Do I need to do something when user logs out?
I have also tried by statrting new session explicitly when user logs in, But related custom dimensions are not set in that case.
To start new session i have used this link Is it possible to manually end a Google Analytics Session?
ga('send', 'pageview', { 'sessionControl': 'end' });
Written this code on logout event. this will forcefully end session of the user and custom dimensions data is also preserved
I have a client that has a site in Germany. Due to Germany privacy laws and the client's request, I need to use session cookies or "convenience cookies" instead of tracking cookies. The requirement simply is that the cookie must be deleted when the users closes the browser.
I can't tell what type of cookies google is using and if there a way to configure this in Google Analytics.
Google Analytics uses a permanent cookie (i.e. one with a long lifetime that is renewed every time the visitor returns) and you cannot configure cookie lifetime in Google Analytics. The cookie stores a client id and is required to recognize recurring users; your client will not be able to recongize recurring users or to create user based segments. I doubt that GA makes that much sense under the circumstances.
What you can do is to configure Google not to set cookies at all by setting the "storage:none" option when you create the tracker. Then you could set a client id for the session in a session cookie, and pass the value as client id to the tracker.
ga('create', 'UA-XXXX-Y', {
'storage':'none',
'clientId': 'value from the cookie'
});
Btw. German law does not require you to use session cookies only (you need to provide a comprehensive privacy policy, an opportunity for an opt-out from tracking and your client needs an agreement with Google pertaining to the processing of data on behalf of your client, a "Vereinbarung zur Auftragsdatenvereinbarung". Google provides a document that you just need to sign. And you must not save personally identifiable data). So this is probably just your client being a bit overcautious.
Just came across this question since I had to do something similar for compliance. The solution to set the GA cookies to session is as follows:
ga('create', 'UA-XXXX-Y', {
'cookieExpires': 0,
'cookieFlags': 'expires=0;secure;samesite=none;httponly'
});
Hopefully it solves the issue for anyone looking for it
I use different ways to send events to Google Analytics on my website. Some user interface interations sends using ga.js but some user actions (eq.: succesful auth or transaction) is possible to send only from server-side (PHP) using measurment protocol.
Events are both successfully sent and come to GA, but there's no link between JS and PHP events. For example, user entered website, clicked some buttons (stats sent by JS) and made a transaction (stats sent by PHP). After that i see JS events linked to one session but PHP event isn't linked. It just displayed as separate event.
What information should i store and pass to measurment protocol to have that events linked?
You need to send the client id (as set in the ga cookie, because this is the key GA uses to group visits into sessions) and possibly the user ip override and user agent override.
I have a little web browser in my application that hits a webpage using Google analytics. That little web browser has cookies and local disk storage disabled.
Are my user analytics going to be skewed because of this? Is every user reported as a new user when in actuality they are an existing one?
Yes, your Analytics data is going to be impacted. For example, you will not be able to differentiate hits between Sessions and Returning Visitors. As you say, each Visitor will be reported as a new one.
Analytics uses the Client ID parameter to uniquely identify a Visitor. As the official Field Reference states:
Client ID
Required for all hit types.
Anonymously identifies a browser instance. By default, this value is
stored as part of the first-party analytics tracking cookie with a
two-year expiration.
If your application can generate a unique key for each user and persist it elsewhere that in cookies or localStorate, you could still create your own Client ID:
Disabling Cookies
By default, analytics.js uses a single cookie to persist a unique
client identifier across pages. In some cases you might want to use
your own storage mechanism and send data directly to Google Analytics
without the use of cookies.
You can disable analytics.js from setting cookies using the following:
ga('create', 'UA-XXXX-Y', {
'storage': 'none',
'clientId': '35009a79-1a05-49d7-b876-2b884d0f825b'
});
When you disable cookie storage, you will have to supply your own
clientId parameter except for the special case where you are using
cross-domain linking parameters.
Yes. Google Analytics uses the client ID to determine if a user is new or returning.
Note, if your users are logged in (probably not though without cookies), then you can use the user ID feature to determine new from returning users.