Sweetalert 在 Google 跟踪代码管理器中工作吗?

问题描述 投票:0回答:2

我一直在将代码从 Sweetalert 复制并粘贴到 Google 跟踪代码管理器中。它不会出现在预览中,并且在提交到网站后也不会出现。 Sweetlart 可以在 Google 跟踪代码管理器中运行吗? (我对此很陌生)

我做了什么:

  1. 在自定义 HTML 中,我将 sweetalert 源代码作为一个标签放入

    <script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>

和 触发:所有页面视图。 标签触发选项:每个事件一次

  1. 我将 sweeralert 弹出脚本放在另一个标签中

   <script>
swal.fire({
 title: "Do you need any consultancy service?",
 text: "Let's",
 type: "info",
 confirmButtonColor: '#000000',
 confirmButtonClass: "contactMeNow_popUpButton",
 confirmButtonText: "Contact Me Now",
 closeOnConfirm: true,
});
</script>

与 标签触发选项:每个事件一次 标签排序:Sweetalert 源代码(上图) 触发:所有页面加载窗口加载。

  1. 我尝试将这两个脚本合并在一个标签中,但它也不起作用。

sweetalert 可以与 Google 跟踪代码管理器配合使用吗?我是不是在剧本或设定上做错了什么?

非常感谢您提前回复。

google-tag-manager sweetalert sweetalert2
2个回答
0
投票
  1. 检查

    chrome devtool
    中的控制台错误。如果这不起作用,可能会出现一些错误。

  2. 稍微修改一下代码以检查

    swal
    是否存在

<script>
// try to console this variable is exist or not
console.log(typeof swal)
console.log(swal)

swal.fire({
 title: "Do you need any consultancy service?",
 text: "Let's",
 type: "info",
 confirmButtonColor: '#000000',
 confirmButtonClass: "contactMeNow_popUpButton",
 confirmButtonText: "Contact Me Now",
 closeOnConfirm: true,
});

</script>

原因可能是即使您较早触发 js 标签。它不能保证第二个标签会哀嚎第一个标签加载完的js。

标签 1 已触发 ----> 标签 2 已触发 ----> 错误

js 开始加载 --------------> 它可能会在这里加载完成


0
投票

在您的“sweetalert popup tag”标签配置中: 添加 : 标签排序:在“sweetalert popup tag”触发之前触发一个标签 并选择“sweetalert 弹出标签”。

一旦执行此操作,JS 代码将在之前加载,并且基于此代码的脚本将正确运行。

它在我的网站上运行良好。

© www.soinside.com 2019 - 2024. All rights reserved.