gpt4 book ai didi

javascript - 在动态加载的脚本中访问 google ga var

转载 作者:行者123 更新时间:2023-12-03 12:06:20 25 4
gpt4 key购买 nike

我动态加载了 html 和 js,并且 html 包含一个按钮链接(使用 Smarty 但与问题无关):

<tr>
...
<td><button id="rid_{$roomRef}" type="button" class="btn btn-success" href="{$link}">&pound;{$rate|string_format:"%0.2f"}</button></td>
</tr>

每个 tr 还引入了自己的 js:

$('#rid_{$roomRef}').click(function() {
window.location.href = $(this).attr('href');
});

我想做的是添加一个 Google Analytics 跟踪链接,如下所示:

ga(‘send’, ‘event’, ‘Supplier’, ‘Click’, $(this).attr('href'));

就在窗口事件之前,但我在控制台中收到错误:

Uncaught SyntaxError: 
Unexpected token ILLEGAL jquery-2.1.1.min.js:2
n.extend.globalEval jquery-2.1.1.min.js:2
n.fn.extend.domManip jquery-2.1.1.min.js:3
n.fn.extend.append jquery-2.1.1.min.js:3
(anonymous function) jquery-2.1.1.min.js:3
n.access jquery-2.1.1.min.js:2
n.fn.extend.html jquery-2.1.1.min.js:3
$.ajax.success (index):306j jquery-2.1.1.min.js:2
k.fireWith jquery-2.1.1.min.js:2
x jquery-2.1.1.min.js:4
(anonymous function) jquery-2.1.1.min.js:4

对这里发生的事情有什么想法吗?

最佳答案

您的 GA 代码包含大引号。请注意发送/事件周围的引号与 $(this).attr('href')

之间的区别

ga('发送', '事件', ' vendor ', '点击', $(this).attr('href'));

关于javascript - 在动态加载的脚本中访问 google ga var,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25175022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com