2K members online now
2K members online now
Learn how to create your first experiment and get tips on creating A/B, redirect, and multivariate tests.
Guide Me

how to test element that uses <script> tag?

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

i'd like to A/B test an image gallery, but it uses a <script> tag which isn't allowed.  i tried adding the tag to the HEAD but that's forbidden as well.


i see the option to run JavaScript, but this is a third party gallery and i'm not sure how to edit the JS.  i reached out to them, but save a reply from their developer, am i stuck?


thanks for any help!

1 Expert replyverified_user
Marked as Best Answer.
Accepted by topic author chuck c

how to test element that uses &amp;lt;script&amp;gt; tag?

Google Employee
# 2
Google Employee



Is the image gallery script external (i.e. <script src="....."></script>) or inline

(i.e. <script> ... </script>)?


In the first external case you may try out a javascript change with this code:


var script = document.createElement('script');




In the inline case, just add the code (i.e. "..." part) in the javascript change.


This is not guaranteed to work if the library requires to be executed at a particular time; Optimize can only run it after it has loaded itself, and the element that you are attaching the javascript change to, has been parsed in the page (you can use "head" for CSS selector to make it run as soon as possible).


But you can always tryout and then use the "preview" button from the experiment page to see if it will work. Since you don't know much about how library works, its worth using the "share preview" option and test your variation on different browsers and devices/networks to be more confident.


how to test element that uses &amp;lt;script&amp;gt; tag?

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

it's the first kind, <script src="....."></script>.  between this explanation, and a little help from the developer, i was able to get it working.


thank you for the help!