Your Browser Does Not Support JavaScript. Please Update Your Browser and reload page. Have a nice day! Using GTM to track a Cookie Banner's Performance | Peak Ace

How can we support your business?

Contact Persons

    *compulsory field







    Peak Ace AG. Leuschnerdamm 13, 10999 Berlin | Telephone: +49 (0)30 – 832 117 447

    • Cookies
    • Feature
    • guide
    14.07.2021

    Track your Cookie Banner Performance with GTM

    Since the EU adopted the GDPR and introduced its corresponding cookie guidelines, using cookie consent banners on your website has become mandatory. A cookie consent banner can help to determine how data can be collected for analysis and thus also for one’s own marketing. It is therefore important that as many users as possible accept the website banner.

    Interestingly, while there are countless consent management platforms (CMPs), there are hardly any meaningful analyses of how users interact with banners. For this reason, we have created a GTM Cookie Consent Checker Template, which allows a deeper and detailed analysis of how users behave towards and interact with banners. How you can implement this on your website is explained below.

    GitHub: https://github.com/peakace/cookie-consent-checker

    Instructions: How to Implement the Peak Ace Cookie Consent Checker

    1. Create a Google BigQuery Table

    First, you need to create a Google Cloud project. In this project, create a dataset with the name “cookie_consent_check”. Select “EU” as the Data Location and create a new table under this dataset, as shown in the following image:

    2. Set up the Google Cloud Function

    The second step requires a Google Cloud Function. To set one up, navigate to Cloud Functions in the menu and click on “Create Function”.

    Name the function “cookie-consent-checker” and select a location within the EU. Select “Allow unauthenticated invocations” in the Trigger menu and save. Click the “Next” button to proceed to the next step.

    You can adjust your settings further under “Runtime, build and connections settings”, but this isn’t mandatory.

    The next step is to change the runtime to Python 3.7 and make sure that the source code contains “Inline Editor”. Copy this Python script into the main.py file.

    If you previously gave your dataset and table different names, you can change that now. In the requirements.txt Copy this content to the requirements.txt: {{content here}}. Then rename the entry point to “cookie_consent_check”.

    Now you can deploy the function. Once you’ve deployed it, click back into the Cloud Function and navigate to the Trigger menu. Here you will find the trigger URL that you will need later for the tag:

    3. Import the Google Tag Manager Custom Template

    You can download the custom template here. In the Tag Manager, navigate to the menu on the left. Select “Templates” and then “New” under Tag Templates.

    Next, click on the burger menu in the Template Editor in the upper right corner. Import and select the tpl file you downloaded earlier. You can save the template after importing and then close it.

    When you create a new tag, you’ll find it under “Custom”. You can add it from there.

    The first three fields are mandatory. They must be filled in.

    In the Cloud Function URL field, enter the trigger URL of the functions from the third step. In the second field, enter the name of the consent cookie. In the third field, enter the click text variable provided by Google Tag Manager. All other fields are optional, but they increase the information rate in the Data Studio Dashboard.

    When activating the Consent Status, you can store a variable that gives a uniform output from different or multilingual click texts. This also works with Click IDs etc., as shown in the example below:

    You can activate the transfer of source/medium and other utm_ parameters under “More Info to Send”. If you want more user information, activate this transfer and set the JavaScript variables as specified in the tag.

    When bot traffic is activated, the traffic is read out in the tag based on the user agent and sent separately to the cloud function. Resourceful marketers can also expand this list themselves by working in the template editor or building their own analyses in Big Query with SQL and the user agent.

    You can edit the browser language under “Banner Language Options”.

    Under “Banner Version Options”, you can choose a banner version that’s suitable for banner A/B tests.

    If there is something you’d like to send that’s missing in the tag, you can add the desired parameters under “Send your own parameters” and send them as well.

    Thus far, the Cookie Consent Checker only works for two different trigger types: the “Element Visibility” for the impression and the “Click – All Elements” for the clicks on the buttons. These two triggers should be set up based on their banner and both should be deposited on the Cookie Consent Checker tag. We recommend using Preview Mode for one last check beforehand to make sure everything is working properly. It’s also worth taking a look at BigQuery to check if your tests arrive there.

    If everything is working properly, you can deploy!

    4. Set up the Cookie Consent Tag

    Provided everything is set up and working correctly, you should be able to see the following in your table in Big Query:

    You can now split this string with a query and write it into a new table. You can find the corresponding query here.

    In the first “From” replace the project ID part with your Google Cloud project ID.

    If you have named your dataset and your table differently, you have to adjust the two parts behind them accordingly. If you have activated the “Send your own parameters” part in the tag, you can still add those in the query in the parameter regex area. To do this, simply copy the last REGEXP line, paste it directly below, and replace the part of the REGEXP between the ” and = with the key name stored in the tag. Run your query once to test if it works.

    You can now save this query as a separate view or run it as a scheduled query once a day. You can save the results in a new table, which you can then link to in the Data Studio.

    5. Link and Set up Google Data Studio

    Copy this Data Studio. When you copy it, you will be prompted to link your data source, which you can then link to the Google Big Query Connector. You should add the following new fields in the data source:

    Banner Accepted (if you have Consent Status enabled in the tag).
    if(CONTAINS_TEXT(Consent_Status, ‘Accept all’) = True,1,0)
    Here, instead of ‘Accept all’, enter what you have defined as “Accept banner” in the tag.

    Banner Accepted (For the version where you have NOT activated the Consent Status in the tag)
    if(CONTAINS_TEXT(Click_Text, ‘Accept all’) = True,1,0)
    Here you enter what your banner has as text instead of ‘Accept all’ in the button when accepting.

    Banner not Accepted (For the version where you have activated the Consent status in the tag)
    if(CONTAINS_TEXT(Consent_Status, ‘Accepted’) = True,0,1)
    Here, instead of ‘Accept all’, enter what you have defined as “Accept banner” in the tag.

    Banner not Accepted (For the version where you have NOT activated Consent Status in the tag)
    if(CONTAINS_TEXT(Click_Text, ‘Accept all’) = True,1,0)
    Here you enter what your banner has as text instead of ‘Accept all’ in the button when accepting.

    Accepted Rate 
    sum(Banner Accepted) / sum(bannerImpression)
    Here you can set the field in advance, because it is a percentage.

    Banner CTR 
    sum(bannerClick) / sum(bannerImpression)
    Here you can set the field in advance, since it is a percentage.

    If you have adopted the labels 1-to-1, all dimensions and metrics should automatically add themselves to the respective widgets. Feel free to create your own dimensions and metrics here or in the query and use them in Data Studio afterwards.

    If you have any questions, we will be happy to help. You can reach us at [email protected].

    Good luck from your Peak Ace Team!

    Emily Wilson

    is a Marketing and Communications Manager at Peak Ace. She joined the company in 2021 and works in the Berlin office. When she isn’t writing for our blog, Emily enjoys travelling, writing, and working on craft projects.