在哪里以MVC形式调用_gaq.push谷歌分析
Where to call _gaq.push Google Analyticss in MVC form?
我在Razor视图中使用Html.BeginForm有一个MVC表单,在我的提交按钮中,我在onclick事件中添加了Google Analytics的代码,如下所示:
onclick="_gaq.push(['_trackEvent', 'MyStuff', 'AperturaForm', 'VeinteMasLed']);"
但我的问题是,如果表单提交但出现错误,那么即使表单失败,也会触发click事件并进行推送。所以我的问题是,我必须在像@using (Html.BeginForm("20mil", "Product", null, FormMethod.Post, new { @class = "small", onsubmit = "_gaq.push(['_trackEvent', 'MyStuff', 'AperturaForm', 'VeinteMasLed']);" }))
这样的onsubmit表单事件中执行这个_gaq.push吗?
我的选择是什么?
我想你可以在onclick事件中使用一个默认按钮,然后调用这样的函数:
$.ajax({url: '@Url.Action("myAction", "myController")',
data: { field1 : $('#txtExample').val() },
type: 'POST',
success: function (data) {
if (data.actionCompleted) {
_gaq.push(['_trackEvent', 'MyStuff', 'AperturaForm', 'VeinteMasLed']);
}
else {
alert('Error');
}
}
});
相关文章:
- NodeJS API调用中Array中的Push和Pull元素
- Push方法显示错误
- Array.push导致程序出错
- Firebase“;未捕获的类型错误:myDataRef.push不是函数;
- $$hashKey在Angular中push()新对象时未生成新值
- 带array.push()的双方括号---JavaScript
- 使用$http的angular js中的JSON数据-data.push()
- 为什么push方法没有'在这种情况下不起作用:[].推
- Flexbox导致adsense错误:;adsbygoogle.push()错误:没有可用宽度为0的插槽大小;
- 为什么这个 .push 不起作用?(JavaScript)
- 检测未绑定的本机函数,如“Array.push”
- Javascript:如何对属性变量(例如var.hello.push)执行数组方法?太习惯AS3了
- 向 Firebase “push” 方法添加时间戳
- TypeError: matrix[y].push 在尝试使用 javascript 创建 2D 数组时不是一个函数
- dataLayer.push() 返回值含义
- Javascript:push 不是数组的函数
- JavaScript:为什么 array.push() 附加两个对象而不是一个对象
- 带有jquery .push的Javascript全局数组在备用函数中返回空数组
- Javascript/jQuery - “无法调用未定义的方法'push'”,而它是定义的
- 将变量作为字符串参数传递给gaq.push