我正在使用以下代码向导航菜单链接添加 Google Analytics 跟踪事件:
(function ($) {
"use strict";
$(function () {
$("body").on('click', '.menu-item a', function () {
var trackingCode = $(this).next(".ga-tracking");
if (trackingCode.length > 0) {
var t1 = trackingCode.data("tracking-1"),
t2 = trackingCode.data("tracking-2"),
t3 = trackingCode.data("tracking-3"),
t4 = trackingCode.data("tracking-4"),
params = "'" + t1 + "','" + t2 + "','" + t3 + "'";
_gaq.push([params]);
}
});
});
}(jQuery));
您可以在此处看到它的工作原理:http: //paulwp.com/blog/ 要触发代码,请单击顶部黑条中的博客链接。
这是我得到的错误:
_gaq.push processing "'_trackEvent','Store_Outbound','Link_Click'" for args: "[]":
Called method "'_trackEvent','Store_Outbound','Link_Click'" threw exception.TypeError: Cannot call method 'apply' of undefined
而它应该给出这样的东西:
_gaq.push processing "_trackEvent" for args: "[Store_Outbound,Link_Click]":
猜猜这是我用导致问题的变量构建参数的方式