React-ga: Can't write cookies in google chrome

Created on 14 Oct 2020  路  4Comments  路  Source: react-ga/react-ga

I have enabled cookies in every way that I can find in the browsers settings but with the debug = true flag enabled I am seeing the following in console

Initializing Google Analytics.
analytics_debug.js:25 Running command: ga("create", "UA-xxxxxxxxxxx, "auto")
analytics_debug.js:25 Creating new tracker: t0
analytics_debug.js:25 New visitor. Generating new clientId
analytics_debug.js:25 Generating new gid
analytics_debug.js:25 Cookie write failed.
analytics_debug.js:25 Cookie write failed.
analytics_debug.js:25 Running command: ga("send", {hitType: "pageview", page: "/page"})
analytics_debug.js:25 Cookie write failed.
analytics_debug.js:25 Cookie write failed.
analytics_debug.js:25 Storage not available. Aborting hit

This is leading to no analytics data being sent up to GA. I have tested using both localhost and our deployed website. The problem seems specific to chrome as it's not happening in firefox or safari. I tried updating to the latest version of react-ga 3.1.2 but the issue persists.

Additional info: it could be related to running the app inside an iframe. Chrome version: Version 86.0.4240.75 (Official Build) (x86_64) Mac-OS

This WAS working previously and has suddenly stopped working within the last few weeks.

Most helpful comment

I did find a work-around for this issue if anyone else has the same problem: You must manually call the ga() method with { cookieFlags: "SameSite=None; Secure" }

        ReactGA.initialize(trackingId, { useExistingGa: true });
        ga("create", trackingId, 'auto', { cookieFlags: "SameSite=None; Secure" });

All 4 comments

I did find a work-around for this issue if anyone else has the same problem: You must manually call the ga() method with { cookieFlags: "SameSite=None; Secure" }

        ReactGA.initialize(trackingId, { useExistingGa: true });
        ga("create", trackingId, 'auto', { cookieFlags: "SameSite=None; Secure" });

This bug was causing me to not track sessions. Fix worked 馃殌

Great fix, Thanks @amcinerneynewf

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hlodver picture hlodver  路  4Comments

alxvallejo picture alxvallejo  路  4Comments

achhranitesh picture achhranitesh  路  3Comments

Robinnnnn picture Robinnnnn  路  6Comments

Dimomir picture Dimomir  路  3Comments