2012-03-01 66 views
1

我在安装了Thesis的Wordpress上使用Podpress运行Podcast。目前,Podpress拥有自己的内部统计系统,用于跟踪播放和下载,但我希望通过在听众点击下载/播放/媒体文件时添加一些Google事件跟踪来扩展它。下面,我包括我们的系统生成的新条目的HTML代码的例子:我有一些jQuery的代码,某种人帮我较早在此板上将标题附加到谷歌事件跟踪代码

<div class="teasers_box"> 

      <div id="post-2855" class="post-2855 post type-post status-publish format-standard hentry category-episodes teaser"> 

<h2 class="entry-title"><a title="Permanent link to Show Title" rel="bookmark" href="http://www.test.com/2012/02/22/show-title/">Show Title</a></h2> 
<abbr title="2012-02-22" class="teaser_date published">February 22, 2012</abbr> 

<div class="format_teaser entry-content"> 
<p>Show Description</p> 
<div class="podPress_content podPress_content_audio_mp3"> 
<div style="display:block;" class="podpress_playerspace podpress_playerspace_audio_mp3 podpress_mp3player"></div> 

<div class="podPress_downloadlinks podPress_downloadlinks_audio_mp3"><a class="podpress_downloadimglink podpress_downloadimglink_audio_mp3" title="Download: Show Title" target="new" href="http://www.test.com/podpress_trac/web/2855/0/2012_02_22_showtitle.mp3"><img alt="" class="podPress_imgicon podpress_imgicon_audio_mp3" src="http://www.test.com/wp-content/plugins/podpress/images/audio_mp3_button.png"></a> <span class="podpress_mediafile_title podpress_mediafile_title_audio_mp3">Show Title</span> <span class="podpress_mediafile_dursize podpress_mediafile_dursize_audio_mp3">[ 39:21 ]</span> <a class="podpress_downloadlink podpress_downloadlink_audio_mp3" target="new" href="">Download</a></div></div> 
</div> 

。我一直在修补它,试图找出我想要的。现在,这里是我有:

$('a.podpress_downloadlink_audio_mp3').click(function(e) { 
    e.preventDefault(); 
     var $a = $(this); 
     // $a is the anchor that was clicked. you can access attributes or its text to populate the _gaq.push call below. e.g. var text = $a.text(); 

    var title = $a.closest('entry-title').text(); 
    _gaq.push(['_trackEvent', 'Podcasts', 'Download', title]); 
    }); 

基本上,我的问题是,我需要进行排序回通过DIV为了拿起播客节目的标题(在这个例子中,它只是“展标题“),我可以将其传递给Google Analytics。我试图使用.closest()技术来做到这一点,但我认为我错误地使用了它。虽然我想介入并实际修改Podpress插件背后的PHP,但我担心更新会擦除我的代码,并迫使我在某个时候重新执行该代码。编写脚本可以更轻松地将该功能捕捉到顶部。

任何意见关于如何获得这个称号将不胜感激。我目前的努力似乎失败了。

在此先感谢!

回答

1

我知道你的意思模块在不改变PHP是什么,你总是想避免这种可能的情况下。

不知道你的HTML将如何看待与多个播客节点,你可以试试这个 - http://jsfiddle.net/CcdDA/

var title = $a.parents('.format_teaser').siblings().prev('h2.entry-title').text(); 

为我工作。希望能帮助到你!

+0

美丽!非常感谢! – ndisdabest 2012-03-01 02:14:27

0

你错过.

var title = $a.closest('.entry-title').text(); // `.entry-title` 
+0

好找。但是,如果我把“警报(标题)”,“在那里,我没有看到任何东西出现。我是否正确引用它,因为它位于链接上方的h2标记中? – ndisdabest 2012-03-01 01:25:49