简体   繁体   English

如何在使用 Google 优化工具的 A/B 实验的结束正文标记之前添加脚本标记?

[英]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.

相关问题 如何添加<script> js include to the closing </body> tag in React? - How to add <script> js include to the closing </body> tag in React? 如何在textarea中的结束脚本标签之前添加文本输入? - How can I add the text input before the closing script tag in my textarea? 如何在结束body标签之后创建元素 - How do I create an element after the closing body tag 如何在之前添加脚本代码 </body> 标记ASP.NET - How to Add script codes before the </body> tag ASP.NET 在没有访问权限的结束正文标记之前添加脚本 - Adding a script before the closing body tag without access 如何在包含 jquery.js 之后但在仅使用 javascript 结束 body 标记之前在 html 文件中添加脚本标记? - How to add script tag in the html file after where jquery.js is included but before ending body tag using javascript only? 即使我将 script 标签放在 body 标签的末尾之前,谷歌浏览器也会首先加载 javascript - Google Chrome loads the javascript first even I put the script tag before the end of the body tag Google跟踪代码管理器和优化服务器端实验发送变体 - Google Tag Manager & Optimize Server-Side experiment sending variation 在结束标记之前添加节点? - Add a node before a closing tag? 如何在文章中的每个表之前添加带有类的div标签,并在表关闭标签后使用javascript添加div关闭标签 - How I add div tag with class before every table in the article and add div closeing tag after table closing tag with javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM