Google Analytics _trackEvent 不适用于 XHTML? [英] Google Analytics _trackEvent doesn't work with XHTML?

查看:27
本文介绍了Google Analytics _trackEvent 不适用于 XHTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成 XHTML 内容的 php 文件,我使用

I have a php file generating XHTML content and I use

<?php header('Content-type: application/xhtml+xml');?>

在页面顶部这样做.但是,当存在该标签时,我的谷歌分析事件跟踪绝对拒绝工作.如果我删除该标签,事件跟踪将再次开始.我根本没有更改跟踪代码,只是删除了将页面定义为 XHTML 的那个 php 标记.

at the top of the page to do so. However, my google analytics event tracking absolutely refuses to work when that tag is present. If I remove that tag, event tracking begins to fire again. I am not altering the tracking code at all, just removing that one php tag defining the page as XHTML.

<a href="some-file.zip" onClick="_gaq.push(['_trackEvent', 'Item', 'Download', 'file-name']);">Download File</a>

我需要以这种方式定义页面,以便 Safari 和 Firefox 3.6 将正确呈现我在那里的 SVG 图像,因此除非有其他方法可以使 Safari 和 Firefox 3.6 呈现 SVG 图像,否则删除它不是一个选项.

I need the page to be defined that way so Safari and Firefox 3.6 will correctly render the SVG images I have on there, so removing it isn't an option unless there's some other way to make Safari and Firefox 3.6 render SVG images.

我正在通过使用 Firebug 跟踪所有内容进行调试.

I'm debugging by tracking everything with Firebug.

推荐答案

您是否尝试过从内联锚元素中删除 javascript 并创建一个封装在 CDATA 标记中的侦听器?

Have you tried removing the javascript from the inline anchor element and creating a listener which is wrapped in a CDATA tag?

示例:

<a id="my_anchor" href="someZip.zip">Click me</a>

<script type="text/javascript">
/* <![CDATA[ */

// Ensure scope for _gaq ....

// Jquery syntax..
$('#my_anchor').click(function()
{
  _gaq.push(['_trackEvent', 'Item', 'Download', 'file-name']);
});

/* ]]> */
</script>

这篇关于Google Analytics _trackEvent 不适用于 XHTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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