duanjue2576 2011-06-10 23:34
浏览 38
已采纳

Google Analytics _trackEvent不适用于XHTML?

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条回答 默认 最新

  • doujiurong7210 2011-06-10 23:47
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答