Google Remarketing code / cookies

262 views
Skip to first unread message

RobT

unread,
Jan 31, 2014, 11:35:32 AM1/31/14
to cookie...@googlegroups.com
Hi - I need to add Google Remarketing code to my site and have CookieControl turn it on / off along with the Analytics. Firstly I assume if you want to add something other than Analytics, you do as below:

onAccept:function(){ccAddAnalytics(),ccAddRemarketing()},
onReady:function(){},
onCookiesAllowed:function(){ccAddAnalytics(),ccAddRemarketing()},
onCookiesNotAllowed:function(){},


i.e. a comma followed by your named function? What's the difference between Accept and Allowed by the way?


This is the Remarketing code I need on my site:

<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = XXXXXXXX;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/986417847/?value=0&amp;guid=ON&amp;script=0"/>
</div>
</noscript>


If I chop out the variables and use the jquery getscript command as per your default analytics example (I added hello world to check it was being called):

          function ccAddRemarketing() {
            jQuery.getScript("//www.googleadservices.com/pagead/conversion.js", function() {
              alert("Hello World!");
              var google_conversion_id = xxxxxxxx;
              var google_custom_params = window.google_tag_params;
              var google_remarketing_only = true;
            });
          }


This, on checking with Google Tag Assistant causes the following errors so it's clear I need to get all the Remarketing code into this block somehow:

Error: No HTTP response detected
Error: Missing <noscript> tag
Warning: Missing CDATA comments

Please advise
Regards,
Rob


Gerasimos Tzoganis

unread,
Jan 31, 2014, 12:55:30 PM1/31/14
to cookie...@googlegroups.com
Hi Rob


onAccept:function(){ccAddAnalytics(),ccAddRemarketing()},
onReady:function(){},
onCookiesAllowed:function(){ccAddAnalytics(),ccAddRemarketing()},
onCookiesNotAllowed:function(){},


i.e. a comma followed by your named function? What's the difference between Accept and Allowed by the way?

No, you should separate them with a semicolon (;) as normally in javascipt. OnAccept will be fired when the user explicitly accepts cookies. OnCookiesAllowed is fired every time CC runs and determines that cookies are allowed (they might have been accepted in a previous page load for example).

About your second question, there is no point in adding the noscript part of the code in CookieControl initialization script. The reason is that a noscript part of an html page is only run only if javascript is disabled, so if cookiecontrol is able to run, that means noscript won't run :). You can add that part normally in your page as before.

However note that I guess this needs to be reflected in your cookie policy somehow, ie explain that even when javascript is disabled that cookie will be set, and that the user cannot block that.

Hope these clarify thing a bit.

Kind regards,
Gerasimos

RobT

unread,
Jan 31, 2014, 3:12:54 PM1/31/14
to cookie...@googlegroups.com
Hi and thanks for the reply. I understand about the noscript which isn't particularly a problem and the missing CDATA isn't the end of the world although it means it may not work in some browsers  but the missing HTTP response implies that the code isn't working i.e. it's not tracking properly.

Do you know of any other way that this can be entered as calling the script with the variables in the function after is failing?

Cheers,
Rob

Gerasimos Tzoganis

unread,
Jan 31, 2014, 4:07:51 PM1/31/14
to cookie...@googlegroups.com
Hi Rob,

I admit I haven't used Google Remarketing and I ran a bit too quickly through your post before. Now I see in the remarketing code that you need to include in your site, the three variable declarations precede the loading of the conversion.js. I assume the latter needs these variables to work. However, in the code inside the ccAddRemarketing() function, firstly you load the conversion script, and then, after it's fully loaded, you declate the three variables. So, I think the following should work:

          function ccAddRemarketing() {
            var google_conversion_id = xxxxxxxx;
           
var google_custom_params = window.google_tag_params;
           
var google_remarketing_only = true;
            jQuery
.getScript("//www.googleadservices.com/pagead/conversion.js", function() {
              alert
("Hello World!");

           
});
         
}


The above code should have the exact same effect with the original.

About CDATA, you would be ok if you enclose the entire initialization code of Cookie Control in them, you could see for example the source Civic's home page.

Kind regards,
Gerasimos

RobT

unread,
Jan 31, 2014, 4:54:27 PM1/31/14
to cookie...@googlegroups.com
Hi - Thanks again. I've just tried that in a variety of ways and the tag assistant's still reporting the same errors. I've put Analytics and Remarketing into Google Tag Manager and am switching that on and off (at least on anyway; see my other post on here).

This seems to work; does it look sane to you?

          function ccAddGoogleTag() {
            (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
            new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
            j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
            '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
            })(window,document,'script','dataLayer','XXX-XXXXXX');           
          }

Regards,
Rob
Reply all
Reply to author
Forward
0 new messages