[英]How do I add a script tag before the closing body tag for an A/B experiment using Google Optimize?
Using Google Optimize I want to run an A/B test which includes loading an external script for one of the variants.使用 Google Optimize 我想运行一个 A/B 测试,其中包括为其中一个变体加载外部脚本。 In order to do this, I need to be able to add my script before the closing <body>
tag, preferably.为了做到这一点,我需要能够在结束<body>
标记之前添加我的脚本,最好。
<script type="text/javascript" src="https://example.com.js" async></script>
</body>
If I select the body tag using the visual editor, I do not have the option to Edit HTML.如果我使用可视化编辑器选择 body 标记,则无法选择编辑 HTML。 You can Insert HTML, but if I try to append the script tag, Google tells me I have to remove it.您可以插入 HTML,但是如果我尝试附加脚本标记,Google 会告诉我必须将其删除。
Is there a way to do this?有没有办法做到这一点?
you might try adding following snippet instead of inserting the script directly in HTML block:您可以尝试添加以下代码段,而不是直接在 HTML 块中插入脚本:
<script>
var script = document.createElement('script');
script.onload = function () {
//do stuff with the script
};
script.src = "https://example.com.js";
document.body.appendChild(script);
<\script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.