nystudio107 / craft-instantanalytics-ga4

Instant Analytics brings full Google GA4 server-side analytics support to your Twig templates and automatic Craft Commerce integration
Other
3 stars 4 forks source link

Don't set cookies until you need to (for cacheability) #30

Closed timkelty closed 6 months ago

timkelty commented 6 months ago

It appears that regardless of configuration, if the plugin is installed, web requests will always end up with a an _ia cookie set. I thought this would be solely controlled with autoSendPageView, but that doesn't appear to be the case.

For example:

'autoSendPageView' => false,
'requireGaCookieClientId' => false,

A blank template still sends up with a Set-Cookie: _ia=….

A response with a Set-Cookie: header is often used an indicator to caching mechanisms that this response should not be cached. This includes static caches like Craft Cloud, Fastly, Varnish, Cloudflare.

In my example, IA is only being used for the Commerce event integration, but having the plugin enabled disabled static cache globally.

khalwat commented 6 months ago

Have you tried using the createGclidCookie setting and setting it to false?

This will not cause IA to use the cookie and, instead, rely on ga4 cookie.

timkelty commented 6 months ago

That seems to work!