nystudio107 / craft-instantanalytics

DEPRECATED: Instant Analytics brings full Google Analytics support to your Twig templates and automatic Craft Commerce integration with Google Enhanced Ecommerce.
https://nystudio107.com/
Other
20 stars 9 forks source link

[FR] Ability to Opt Out of setcookie #18

Closed hahnzilla closed 4 years ago

hahnzilla commented 5 years ago

I noticed that a _ia cookie was being set on each request even though we were opting out of autoSendPageView. This can cause issues with cloudflare cdn page caching (which is how I found it :)). I tracked it down to this definition, but I wasn't sure what the best way to go about opting out of it was so I figured I'd start a conversation.

It'd be sweet if there were just a "noGlobals" config method that was checked at the beginning. I can push up a PR if you think that's a good idea.

    public function getGlobals()
    {
        $globals = [];
        $view = Craft::$app->getView();
        if ($view->getIsRenderingPageTemplate()) {
            $request = Craft::$app->getRequest();
            if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) {
                // Return our Analytics object as a Twig global
                $globals = [
                    'instantAnalytics' => InstantAnalytics::$plugin->ia->getGlobals(InstantAnalytics::$currentTemplate),
                ];
            }
        }

        return $globals;
    }
khalwat commented 5 years ago

hmmm yeah this should be doable

khalwat commented 4 years ago

Probably people will want this for GDPR reasons, too.

timkelty commented 4 years ago

Yep, running into the same type of issue with Varnish caching.

timkelty commented 4 years ago

@dhahn in the meantime, a quick and dirty fix would be to throw this in some module code:

        Event::on(
            View::class,
            View::EVENT_AFTER_RENDER_PAGE_TEMPLATE,
            function (TemplateEvent $event) {
                header_remove('Set-Cookie');
            }
        );
khalwat commented 4 years ago

Added in https://github.com/nystudio107/craft-instantanalytics/commit/6816c3e19a15a398e44171cff0d90b8a16c4ce53

timkelty commented 4 years ago

Ummmmm…isn't your condition reversed (should lose the first !)?

https://github.com/nystudio107/craft-instantanalytics/blob/2c601e19632a7c2e66f17317e4fc109a11fe5325/src/services/IA.php#L492

khalwat commented 4 years ago

oops.

khalwat commented 4 years ago

Fixed in: https://github.com/nystudio107/craft-instantanalytics/commit/07753acb2ae828e03c13036876ebd6816e1859c5

Released as 1.1.5