开发者

Social tracking in Google Analytics

开发者 https://www.devze.com 2023-04-01 16:09 出处:网络
I\'m using this example script, provided by Google inside a rails app (so it\'s compiled by Rails into a single JS file with all my other scripts):

I'm using this example script, provided by Google inside a rails app (so it's compiled by Rails into a single JS file with all my other scripts):

_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', 'facebo开发者_JS百科ok', '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) {}
};

Then, this code to load my Facebook like button:

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

But while Google tracks the +1 button, it's not tracking any Facebook like events and I really don't know enough about JS to figure out what's wrong. I see the note about the iFrame method, but don't think that's how my code is loading -- maybe I'm wrong?


Try adding this script before the button:

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

right after

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号