Adding Events to the Third-Party Scripts manually
1. Adding Events to the Third-Party Scripts manually
Block the whole third-party functionality for blocking the third-party cookies. This means that Google Analytics / YouTube videos / Facebook buttons / AdSense or anything else you have blocked will not work until the user agrees with the cookie policy.
Find your JavaScript code that sets the third-party cookies and change the following points:
- Replace the type attribute "text/javascript" to "text/plain". (If the type attribute is missing, add it)
- Now add the data category attribute and set it to the respective category Id or category internal name from the list of cookie categories <mandatlydata-cookiecategoryid="ID"> or <mandatlydata-cookiecategoryname="Category internal name">
- You can find a cookie's category Id or category internal name from Cookie Compliance -> Categories -> Cookie category grid.
- You can also find a cookie’s category Id from Cookie Compliance -> Websites -> Add/Edit -> Preference Center -> Edit Category.
JavaScript code with the above changes will now respond to the user's consent in real-time, without refreshing the page.
After following these steps for all third-party code on your page, you have finished blocking third-party cookies manually.
Below is an example of these changes in the Google analytics script.
Google Analytics script example:
Original Script:
<script type="text/javascript"> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXXX-X', 'auto'); ga('send', 'pageview'); </script> |
For example: Set the mandatlydata-cookiecategoryid="0003", 0003 suggests the Cookie Category Id for Analysis Category and hence this tag will be fired when the user sets the Analysis category as Active and consents to the banner. You can also set the mandatlydata-cookiecategoryname="Analysis"> instead of Category id.
Replace 0003 or Analysis with the Cookie Category Id or Internal name you want to fire.
Change this to:
<script type="text/plain" mandatlydata-cookiecategoryid="0003"> Or <script type="text/plain" mandatlydata-cookiecategoryname="Analysis"> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXXX-X', 'auto'); ga('send', 'pageview'); </script> |
Note:
Manual Blocking Script option needs to be enabled while using the Custom tags, Custom events or GTM events on your website.
To enable the Manual Blocking Script option in your Mandatly account:
Navigate to Websites -> Edit website -> Advanced Settings and turn on the Manual Blocking Script option.
Relevant Resources: