Add Google AdSense with PIWIK PRO tag manager

I want to integrate the following vendors

  • Google AdSense (for publishers)
  • Amazon Affiliate Program
  • PIWIK PRO consent management

Does it make sense to use the PIWIK PRO tag manager? When adding/creating a new tag, AdSense doesn’t appear in the list, only Google Ads (which is not for the publisher) What am I not getting?

Should I use Google tag manager instead?

Later we want to use analytics too. Just curious, does it make sense to use Google Analytics and include it via PIWIK PRO tag manager? The reason I would favour Google Analytics is merely because maybe it works better with Google AdSense? But I understand that Google Analytics is not very compliant with GDPR (DSGVO) in Europe, so still on the fence on which one to use. In fact, I only need to implement PIWIK PRO in order to use the consent manager to start with, and then analytics would be easy to try out.

You should be able to install AdSense with Piwik PRO Tag Manager. In general, Piwik PRO Tag Manager and GTM are really similar tools.

There are no predefined templates, but you can achieve the same result by using custom html code tag. All the codes to generate ads should be available on your AdSense account.

Regarding Google Analytics and GTM. It’s your call, but my recommendation is always to go for a solution that gives you full transparency regarding where and how the data is hosted. From the functional point of view, most likely you don’t need two tools that do the same.

1 Like

OK so far so good. I reckon I should classify Google AdSense cookies as Remarketing or Marketing Automation? Then the user can give or refuse consent for AdSense cookies as a whole. But now I wonder how to get the user’s consent for the use of personalised data to show personalised ads, which is required in the EU according to GDPR (DSGVO). It’s a something I would just switch on in the AdSense settings page, not much insight is given here by Google.

I’m not an expert here but I’d simply enable personalized ads via additional piece of code once the consent for personalization is there. Here are some examples.

So, it would be just an additional tag with (adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=0 (assuming that personalization is disabled in the default tag).

thanks, but I don’t quite get it

Firstly, do i create a new async script tag in which I add said JS code? It seems to define a JS variable, usually these tags just include an external script, sometimes with a get variable.

And if so, if I add it as a separate tag, how do I categorise it in PIWIK? If I use the same category as the AdSense tag already has, won’t both be handled under the same toggle? What I want (or need to do to be honest) is make the user decide between

  1. reject AdSense entirely (so no ads are shown)
  2. allow AdSense with unpersonalised ads
  3. allow AdSense with personalised ads

because 1. would block AdSense from putting cookies in the browser.
2. would allow AdSense to put cookies in the browser
and 3. would put AdSense cookies in the browser and allow it to use third party cookies and other data found in the browser.

To be honest, and I know it’s quite basic but it’s still something that was never totally clear to me. When CMPs say they “use” cookies, do they mean they put cookies in the browser to track the user or use the cookies that are already there. Could be both.

With that in mind, I’m not sure if I actually need (in order to be compliant to EU law) the 3 options as shown above or just a yes or no to the use of personal data (i.e. cookies and whatnot already in the browser), because you cannot refuse ads entirely, at least not this way.

And secondly, I see a new problem.

On the mentioned Google documentation it says that AdSense serves personalised ads by default.

So with the current setup as per your suggestion, the additional tag will leave the value of the variable requestNonPersonalizedAds to default (false) if no consent is given or “no to all” is clicked, hence the use of personal data is allowed. Isn’t that backwards? How can I deny personalised ads by default this way?

I could add another prioritised tag that first does the following

(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=1

and then, in the Remarketing-tag, do

(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=0

when the user gives consent.

Would that be a good practice? Feels like a work-around…

And a follow-up question, how can I create a necessary/functional cookies category that cannot be untoggled? Cause that’s what would come into play here, right?

It’s not possible to have a pre-checked category. To achieve that, most likely you would have to use the JS api.

As for your question, in the main tag I’d make sure that personalized ads are disabled. There would be an additional tag that enables the personalization under other consent category (e.g. a/b testing & personalization). If both categories don’t have consent, you don’t display ads. If the main category has no consent, you also don’t display ads. If only the main category has consent, you display non-personalized ads. And if both have user’s consent, you display personalized ads.

OK I tried that, but how do I know if it works? I can find the testing & personalization cookie stored as checked in the browser (“status”:1), but how do I know if it actually does as supposed to i.e. google setting the variable to 0?
Also, all this still feels a bit like a work-around and not common practice… Doesn’t PIWIK deal with Google AdSense consent management on a daily basis? It seems like I’m the first one to ask this stuff.

I guess it’s more a Google Adsense thing than Piwik PRO. Haven’t seen many questions about AdSense.

To confirm the setup, you can enable the tag manager debug mode to see which tags have been fired.

As for checking if it works, Google’s docs suggest checking the &npa param from the ad request.

I know, but cannot find it anywhere.

Does this param appear if you disable personalization in the main tag? Maybe it’s the matter of tags’ priority?

I also re-arranged the priority of tags as well, putting the main on top. Where should I even look? cookies? local storage? session storage?
and then, what is an ad request per se? an actual displayed ad? cause I don’t see those ATM (not least cause I’m on my local machine).

It should be a standard request in the Network tab in the browser’s console.

another question, the given consent types don’t really express what the tags are doing. I know there’s a “custom consent” type (Lorem Ipsum…) which I could use but I actually need 2 custom consent types, as elaborated above. I can however change the title and description of the given consent types in the consent manager. Is that a good idea? I can see the changes in the consent form and they should do what you would expect, it’s just the name of the type that doesn’t change in the dropdown list of consent types when editing the tags in tag manager. Don’t know if that would be an issue somewhere down the road.

I managed to get non-personalised ads work, no errors anymore in the console in almost all browsers. (the request in the network tab says npa=1)

Personalised ads don’t work though, I get the error

TagError: adsbygoogle.push() error: Only one ‘enable_page_level_ads’ allowed per page

not sure why and there’s no request to googleads in the network tab.

Here’s the current code in the tags:

// for general AdSense consent, category: "Remarketing")
<script data-ad-client="ca-pub-xxx" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js">
</script>
<script>
(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=1;
(adsbygoogle=window.adsbygoogle||[]).push({google_ad_client: "ca-pub-xxx", enable_page_level_ads: true});
</script>
// for personalised AdSense consent, category: "AB Testing and Personalization")
<script>
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=1;
(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=0;
// This will pause ad requests, so users have time to interact with your consent solution.
(adsbygoogle=window.adsbygoogle||[]).push({google_ad_client: "ca-pub-xxx", enable_page_level_ads: true});
// This usually triggers the ad request, but you have paused these.
</script>

I followed these instructions:

I think one problem could be that some part of the code needs to be added to the and some other to the .
How can I accomplish that using PIWIK’s tag manager?

P.S. As mentioned above, I renamed the categories/titles of the tags in the consent forms though

Thanks for help!

What about such piece of code for the second tag?

// for personalised AdSense consent, category: "AB Testing and Personalization")
<script>
(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=0;
</script>

There’s no need to pause things as the tag simply won’t be executed before consent was given. Assuming that the full configuration will load before fetching the js library, it should theoretically work. Just make sure that the 2nd tag has lower priority so that the setting isn’t overwritten.

I tried that and the adds appear now, no more TagError. I reckon I should be seeing npa=0 somewhere in the get variables of the network requests, right? I don’t though. How do I know these are personalised ads I’m seeing.

I guess the default value is 0 so if the param is not available in the add request, most likely it works as intended.

OK so the calls when not personalised have the get variable ?npa=1 and none when it’s personalised. Still cannot tell if it works though, the ads seem pretty random and not related to my browsing history.
Also, when not personalised, I used to see a blocked call to https://pagead2.googlesyndication.com and now just a warning that this call is unencrypted. Not sure if people here on the PIWIK PRO platform can help with that and if so if that raises any eyebrows…

Weird, since https is in use…

As for you question - maybe AdSense support knows some tricks to determine if ads are personalized. Maybe they simply don’t have enough data yet to make the personalization for you. :slight_smile: