1

I used the following javascript function for our cookie consent message on our website. How can I add the Mailchimp code to this? The problem is that Mailchimp needs the <script id="mcjs">

Code I'm using to check if someone allows cookies. If so than activate Google Analytics etc.

function BlockCookie() {
var imported = document.createElement('script');
imported.src = 'https://www.googletagmanager.com/gtag/js?id=ANALYTICS_CODE';
document.head.appendChild(imported);

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'ANALYTICS_CODE', { 'anonymize_ip': true });

window._mfq = window._mfq || [];
  (function() {
    var mf = document.createElement(\"script\");
    mf.type = \"text/javascript\"; mf.defer = true;
    mf.src = \"//cdn.mouseflow.com/projects/cae0bb6e-2421-49b4.js\";
    document.getElementsByTagName(\"head\")[0].appendChild(mf);
  })();
}

Mailchimp code I would like to add to the function

<script id="mcjs">!function(c,h,i,m,p){m=c.createElement(h),p=c.getElementsByTagName(h)[0],m.async=1,m.src=i,p.parentNode.insertBefore(m,p)}(document,"script","https://chimpstatic.com/mcjs-connected/js/users/01ad3420bde595/306da052f4.js");</script>
Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
Matthijs
  • 63
  • 7

0 Answers0