Support » Plugin: Smart Cookie Kit » Refresh page load on Acceptance

  • Hi thanks for great plugin (will dontate if I get this fixed:)

    I want to add google adsence Auto ads via tag manager. (so I need the visitor to first accept the cookie) in order to load the script. (I already enable tag manager via your plugin and it works great)

    I have added the Auto ads via tagmanager using this method https://stackoverflow.com/questions/47365877/how-to-add-adsense-in-google-tag-manager

    But I need the page to reload on acceptance so it can be redrawn with the ads included IF they accept the cookie.

    So its essentially the same action if the user declines then accepts using the button.

    thanks in advance

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter SEO Expert

    (@wesitegeezer)

    Sorry this is what I need to do .. any help appreciated

    https://developers.google.com/doubleclick-gpt/samples/configure-cookies

    <!doctype html>
    <html>
      <head>
        <meta charset="utf-8">
        <title>Configure Cookie Options</title>
        <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
        <script>
          window.googletag = window.googletag || {cmd: []};
          var cookiesEnabled = 1;
    
          googletag.cmd.push(function() {
            // Cookies are enabled by default. Set cookie options to 1 to disable.
            //
            // To ensure this option takes effect for all ad requests, place this
            // call before any calls to enableServices or display.
            googletag.pubads().setCookieOptions(cookiesEnabled);
    
            googletag.defineSlot('/6355419/Travel/Europe/France',[728, 90], 'banner-ad')
                .addService(googletag.pubads());
            googletag.enableServices();
          });
    
          function toggleCookieOptions(button) {
            // Cookie options can be changed at any time. Changes apply to all
            // subsequent ad requests.
            //
            // Set to 0 to enable cookies, 1 to disable.
            cookiesEnabled = cookiesEnabled === 0 ? 1 : 0;
    
            googletag.cmd.push(function() {
              googletag.pubads().setCookieOptions(cookiesEnabled);
    
              // Refresh all ads on the page for changes to take affect.
              googletag.pubads().refresh();
    
              button.setAttribute('data-enabled', cookiesEnabled);
            });
          }
        </script>
        <style>
          button::after {
            content: "DISABLED";
            color: red;
            font-weight: bold;
          }
          button[data-enabled="0"]::after {
            content: "ENABLED";
            color: green;
            font-weight: bold;
          }
        </style>
      </head>
      <body>
        <div id="banner-ad" style="width: 728px; height: 90px;">
          <script>
            googletag.cmd.push(function() {
              googletag.display('banner-ad');
            });
          </script>
        </div>
        <div>
          <button onclick="toggleCookieOptions(this);">
            Cookies
          </button>
        </div>
      </body>
    </html>
    Plugin Author shark986

    (@shark986)

    Hello,
    a page refresh won’t solve your need and (to be honest) would go against the idea behind the plugin because it makes the user experience worse.

    We can get that the Ads will start without cookies (according to the Google cookie options that you linked to me) for default, even if user has never accepted cookies, and from when the user accepts cookies, the Ads will start using cookies on the next page visited by the user.

    To this goal, if you want to start to use cookies as soon as possible (regardless of user experience), we can force a page refresh with some custom code.

    Please, let me know what is your preference.

    First of all, I see the code on your site and it seems that there is an error. I see in the page:

    <script async src=https://securepubads.g.doubleclick.net/tag/js/gpt.js></script> <script><script class="SCK-Block-Statistics SCK-Block-Profiling">
    

    It seems that there is a second “script” tag, like you entered this code to include Ads:

    <script async src=https://securepubads.g.doubleclick.net/tag/js/gpt.js>
    </script><script><script> ... </script>
    

    Do you see the second “script” in the middle?
    “<script async src=https://securepubads.g.doubleclick.net/tag/js/gpt.js>
    </script><script><script>”

    So, please, correct that code as the first thing.
    Let me know, Nicola

    Thread Starter SEO Expert

    (@wesitegeezer)

    Hi Nicola, thanks for taking the time to reply to me, much appreciated. I will really appreciate the example as once I can see how it is done I will be able to repeat in future myself.
    =======================
    This as the actual code from the site https://admanager.google.com/ to serve ads on my site. I have the form already on the site, so just need this consent bundled in with that.

    code in the head

    <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
    <script>
      window.googletag = window.googletag || {cmd: []};
      googletag.cmd.push(function() {
        googletag.defineSlot('/2197111111/SMR-LB-TOP', [[728, 90], [970, 90], [320, 50]], 'div-gpt-ad-158764111111-0').addService(googletag.pubads());
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
      });
    </script>

    code in the body that shwos the add block on the page

    
    <!-- /21976090514/SMR-LB-TOP -->
    <div id='div-gpt-ad-158764111111-0'>
      <script>
        googletag.cmd.push(function() { googletag.display('div-gpt-ad-158764111111-0'); });
      </script>
    </div>
    Plugin Author shark986

    (@shark986)

    And how do you put that code in your site?
    Could you check the code inserted in your site?

    I think that the code you inserted in the site is not the same as the one you took from https://admanager.google.com/.

    Thread Starter SEO Expert

    (@wesitegeezer)

    Ok I think It’s correct now sorry…

    If you search source </head>

    Ive placed it in my head.php just before the closing </head>

    • This reply was modified 1 year, 3 months ago by SEO Expert.
    Thread Starter SEO Expert

    (@wesitegeezer)

    I use tag assistant chrome to see the cookies load before/after cookie consent.tag assistant google chrome

    So this needs to load upon consent

    <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
    <script>
      window.googletag = window.googletag || {cmd: []};
      googletag.cmd.push(function() {
        googletag.defineSlot('/2197111111/SMR-LB-TOP', [[728, 90], [970, 90], [320, 50]], 'div-gpt-ad-158764111111-0').addService(googletag.pubads());
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
      });
    </script>

    and this snippet to insert a banner is in the header.php

    <div id='div-gpt-ad-1587580236580-0'>
      <script>
        googletag.cmd.push(function() { googletag.display('div-gpt-ad-1587580236580-0'); });
      </script>
    </div>

    ads not live yet so no ad loads. As need to sort the cookie first. 🙂

    • This reply was modified 1 year, 3 months ago by SEO Expert.
    Thread Starter SEO Expert

    (@wesitegeezer)

    Hi can I bump this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Refresh page load on Acceptance’ is closed to new replies.