Google Analytics _trackEvent doesn't work with XHTML?

[亡魂溺海] 提交于 2019-12-13 05:16:43

问题


I have a php file generating XHTML content and I use

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

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>

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.

Edit: I'm debugging by tracking everything with Firebug.


回答1:


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

Example:

<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>


来源:https://stackoverflow.com/questions/6630697/event-tracking-not-working-yet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!