• Resolved MarcGuay

    (@marcguay)


    Unfortunately Google Analytics sets this cookie on the “unload” event, so even if cookies are deleted, when the page is refreshed, the cookie re-appears.

    To reproduce include GA on your page. Below is my code, I toggle its inclusion on the page using PHP based on the cookieyes-consent cookie content.

    <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXX"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());  gtag('config', 'G-XXX');
    </script>

    And make sure the _ga and _ga_* cookies and registered in CookieYes.

    When the banner first appears, accept all cookies and refresh the page, you will see the _ga and _ga_* cookies are set.

    Now bring up the cookies settings again and disable the cookie category the GA cookies belong to.

    Refresh the page and you’ll see that the _ga cookie is gone but the _ga_* cookie persists.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support CookieYes Team

    (@cookieyesteam)

    Hi @marcguay,

    Greetings from CookieYes!

    Please confirm whether your site is connected to CookieYes or not. While setting cookies from server side, you will have to check the value of our cookie consent on each request to the backend and decide on adding or removing the script from your site. Also please share us your site URL so that we could help you with a working solution.

    Plugin Support CookieYes Team

    (@cookieyesteam)

    Hi?@marcguay,

    This thread has been inactive for a bit, so we are going to mark it as resolved now. Please feel free to open a new thread or follow-up if you have any further questions or still need help.

    m440

    (@m440)

    Hi @cookieyesteam,

    I can confirm the narrative of @marcguay. It’s exactly how he describes it.

    I think the special asterisk-character is ignored by the plugin resulting in failing to block GA cookies like: _ga_H7QVGTNPMD

    Thread Starter MarcGuay

    (@marcguay)

    Sorry I didn’t notice the follow up questions. My solution was to move the hardcoded GA code to the google-analytics-for-wordpress plugin and it now works as expected.

    The GA code was conditionally included using the following:

    <?php if (conditionally_display_gtm_tag()) : ?>
    <!-- Google Analytics script -->
    <?php endif ?>
    
    function conditionally_display_gtm_tag() {
        
      //if cookieyes cookies are set
      if (isset($_COOKIE['cookieyes-consent'])) {
        
        // Read current user consent
        $CookieConsent = array_column(array_map(function ($pair) {
          return explode(':', $pair);
        }, explode(',', $_COOKIE['cookieyes-consent'])), 1, 0);
        
        //checking whether functional cookies are accepted
        if (filter_var($CookieConsent['analytics'], FILTER_VALIDATE_BOOLEAN)) {
          return true;
        }
      }
    }

    I did a similar integration on a custom non-WP site that required disabling GA via JS before reloading the page so that the cookies were not reset. The docs for this are here: https://developers.google.com/tag-platform/security/guides/privacy#turn-off-analytics.

    m440

    (@m440)

    Hi @marcguay,

    Thank you for answering.
    Are you sure it still works? I’m using google-analytics-for-wordpress (MonsterInsights – Google Analytics Dashboard for WordPress) too, but still experiencing the problem.

    Maybe you are willing to check it again and let me know?

    Thread Starter MarcGuay

    (@marcguay)

    @m440 Are you entering the CookieYes settings manually in the WP admin or have you connected it to the webapp and have the settings managed there? I have it connected to the webapp.

    m440

    (@m440)

    @marcguay

    No, I don’t have it connected to webapp.
    Imo that shouldn’t be a problem.
    FYI, I’ve setup the GA problem cookie as the following:
    – cookie ID: _ga_*
    – domain: .mydomain.com <– replaced by the real domain starting with a dot)
    – duration: 1 year 1 month 4 days
    – category: Analytics
    – description: Google Analytics sets this cookie to store and count page views.
    – advanced options (script URL pattern): googletagmanager.com

    Maybe I made a mistake in it?

    Thread Starter MarcGuay

    (@marcguay)

    Although it “shouldn’t be a problem” we all know that it still could be!

    I have 2 cookies set. One like the one you described and a second with everything the same except the cookie ID is _ga.

    m440

    (@m440)

    @marcguay,

    Yes, you are right about that. I will try that, maybe it will work

    The other cookie is working fine (like being disabled/controlled by CookieYes)

    Anyway, thanks for your help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘The _ga_* cookie is not deleted’ is closed to new replies.