Rich-text Reply

Insert JS Code from MailChimp with Optimizely

jklaiber 08-23-16
Accepted Solution

Insert JS Code from MailChimp with Optimizely

Dear all

 

I created a newsletter signup pop-up with mailchimp. Now I want to test this pop up with Optimizely on my website. MailChimp created the following JS code:

 

<script type="text/javascript" src="//s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script><script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us9.list-manage.com","uuid":"c74bcae51c6790df6ade46b27","lid":"11802a247d"}) })</script>

 

When I want to paste in that code in the editor field in my experiment it says: "unexpected token <"

Do you know how I can fix this? Because if I remove the "<" the JS could would be incorrect... 

Or is there another problem?

 

Thanks a lot!

Best

Johannes

Level 2

CouchPsycho 08-23-16
 

Re: Insert JS Code from MailChimp with Optimizely

Try:

 

jQuery("head").append('<script type="text/javascript" src="//s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script><script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us9.list-manage.com","uuid":"c74bcae51c6790df6ade46b27","lid":"11802a247d"}) })</script>');

Kind regards

 

Michael




"the essence of the creative act is to see the familiar as strange." (anonymous)
jklaiber 09-19-16
 

Re: Insert JS Code from MailChimp with Optimizely

Hi Michael
I tried this and it seemed to work within the editor. But now if I do this in the Preview Mode its not working. I also tried it live but it does not work either. The error message stays the same. Do you see another mistake?

Best
Johannes
Level 2
CouchPsycho 09-19-16
 

Re: Insert JS Code from MailChimp with Optimizely

Hmmm,

not easy. If it works in the editor but not in preview or live it might be a timing problem, which means your experiment is not activated at all or to late. Possibly, the mailchimp-script is waiting for an event to be triggered which already has been triggered before. But since i do not know mailchimp, this is just an idea, not more

Kind regards

Michael






"the essence of the creative act is to see the familiar as strange." (anonymous)
jklaiber 09-19-16
 

Re: Insert JS Code from MailChimp with Optimizely

Thanks a lot. I think I try to contact MailChimp support. Maybe they can help me out with this. But your answer seems to make sense. 

Best

Johannes

Level 2
jaronstein 09-06-17
 

Re: Insert JS Code from MailChimp with Optimizely

I have found a fairly simple solution.

 

Add the first of the two script tags that MailChimp gave you to just above the end head tag inside your site template:  

<script type="text/javascript" src="//s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script>

 This will be either in Shopify, BigCommerce, Magento, etc... Again this will be just inside the end of the head tag.

 

 

Then take the second of the two script tags in the MailChimp code and append it to the head tag using jquery like so: 

 

 

$("head").append('<script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us5.list-manage.com","uuid":"#######","lid":"#######"}) })</script>');

 

 

 

The key here is to install the first script tag inside the head tag inside your template and then using jquery insert the second part of the code.