Google Analytics中的社交跟踪

时间:2011-09-01 12:52:50

标签: javascript google-analytics facebook-like

我正在使用这个示例脚本,由Google在rails应用程序中提供(所以它由Rails编译成一个包含所有其他脚本的JS文件):

_ga.trackSocial = function(opt_pageUrl, opt_trackerName) {
  _ga.trackFacebook(opt_pageUrl, opt_trackerName);
  _ga.trackTwitter(opt_pageUrl, opt_trackerName);
};


/**
 * Tracks Facebook likes, unlikes and sends by suscribing to the Facebook
 * JSAPI event model. Note: This will not track facebook buttons using the
 * iFrame method.
 * @param {string} opt_pageUrl An optional URL to associate the social
 *     tracking with a particular page.
 * @param {string} opt_trackerName An optional name for the tracker object.
 */
_ga.trackFacebook = function(opt_pageUrl, opt_trackerName) {
  var trackerName = _ga.buildTrackerName_(opt_trackerName);
  try {
    if (FB && FB.Event && FB.Event.subscribe) {
      FB.Event.subscribe('edge.create', function(targetUrl) {
        _gaq.push([trackerName + '_trackSocial', 'facebook', 'like',
            targetUrl, opt_pageUrl]);
      });
      FB.Event.subscribe('edge.remove', function(targetUrl) {
        _gaq.push([trackerName + '_trackSocial', 'facebook', 'unlike',
            targetUrl, opt_pageUrl]);
      });
      FB.Event.subscribe('message.send', function(targetUrl) {
        _gaq.push([trackerName + '_trackSocial', 'facebook', 'send',
            targetUrl, opt_pageUrl]);
      });
    }
  } catch (e) {}
};

然后,这个代码加载我的Facebook就像按钮:

<div id="fb-root" class="fb_like"></div>
<script src="http://connect.facebook.net/en_US/all.js#appId=...&amp;xfbml=1"></script>
<fb:like href="http://somethingunderthewater.com" send="true" layout="standard" colorscheme="light" width="400" show_faces="false" font="trebuchet ms"></fb:like>

但是,虽然谷歌跟踪+1按钮,但它并没有跟踪任何类似Facebook的事件,我真的不太了解JS以找出错误。我看到关于iFrame方法的注释,但不要认为我的代码是如何加载的 - 也许我错了?

1 个答案:

答案 0 :(得分:1)

尝试在按钮前添加此脚本:

  <script type="text/javascript">_ga.trackFacebook();</script>

之后

   <script src="http://connect.facebook.net/en_US/all.js#appId=...&amp;xfbml=1"></script>