This code loads GTM only when marketing / targeting or performance consent is granted) on a website using CookieScript. This allows to implement both GTM and CookieScript directly on your site and still respect consent.
There are to optional lines of code:
- you can easily delete the
console.logcommand after making sure that everything works - the dataLayer event push is not necessary but serves as a unique trigger that can be used as an alternative to the dataLayer events that CookieScript fires. This is helpful for firing GA and FB Tags at the same event (resulting in matching event ids) when using a server-side GTM and Meta CAPI for example.
Note: CookieScript changed their API at least once and broke existing similar custom implementations already. Be aware that this may happen again in the future.
