OnClick - 未捕获的语法错误:无效或意外的令牌 [英] OnClick - Uncaught SyntaxError: Invalid or unexpected token

查看:80
本文介绍了OnClick - 未捕获的语法错误:无效或意外的令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将 OnClick 事件发送回 Google(通用)分析.

I'm having trouble getting an OnClick event to send back to Google(Universal) Analytics.

这是有问题的行:

<a href= "link-to-asset-goes-here" onclick="ga(‘send’, ‘event’, ‘Button’, ‘Click’, ‘AllVisits_Free’, {‘NonInteraction’: 1});">

当我使用 Chrome 开发工具进行检查时,我看到以下错误:未捕获的语法错误:无效或意外的令牌"

When I inspect with Chrome Dev tools, I'm seeing this error: "Uncaught SyntaxError: Invalid or unexpected token"

在查看其他问题时,我发现了这个:java - OnClick 错误

When looking through other questions, I found this one:java - OnClick error

那么它可能只是转义所有字符串吗?像这样:

Could it possibly be just escaping all the strings then? Like so:

<a href= "link-to-asset-goes-here" onclick="ga(\‘send’\, \‘event’\, \‘Button’\, \‘Click’\, \‘AllVisits_Free’\, {\‘NonInteraction’\: 1});">

这会导致代码的 NonInteraction 部分出现任何问题吗?

Would that cause any issues with the NonInteraction part of the code?

不幸的是,我无法进行现场测试,每次都必须将每个代码修订版发送给客户端,否则我可以更轻松地测试不同的代码变体.

Unfortunately I don't have access to test this live, and have to send each code revision over to the client each time, or I could just test different variations of code a lot easier.

仅供参考,我们使用的是最新版本的 GA(通用)分析跟踪代码.在 GA 中查看实时报告时,它正在注册我在页面上,但单击链接时未触发事件.

And just for reference, we're using the newest version of GA(Universal) analytics tracking code. When looking at the Real Time reports in GA, it's registering that I'm on the page, but events are not firing when clicking the link.

谢谢!

推荐答案

如果它是您使用的确切代码格式,那么尝试使用直引号而不是智能引号:

If that it the exact code format you are using, then try using straight quotes rather than the smart quotes:

<a href= "link-to-asset-goes-here" onclick="ga('send', 'event', 'Button', 'Click', 'AllVisits_Free', {'NonInteraction': 1});">

....一些带有智能引号的东西在 JavaScript 中表现不佳.

....Something with smart quotes not playing well with JavaScript.

这篇关于OnClick - 未捕获的语法错误:无效或意外的令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆