0

This is my first stackoverflow question. yay.

Ok. I am attempting to splittest or a/b test copy for a featured facebook like button by using google analytics:

_gaq.push(['_trackEvent', 'facebook', 'click', 'amazing copy that hypnotizes user into clicking like']);

All fine and dandy so far.

To reign in the like/unlikes I found this snippet:

<script type="text/javascript">
<!--
    FB.Event.subscribe('edge.create', function(href, widget) { _gaq.push(['_trackEvent', 'facebook', 'click', 'amazing copy that hypnotizes user into clicking like']); });
    FB.Event.subscribe('edge.remove', function(href, widget) { _gaq.push(['_trackEvent', 'facebook', 'click', 'amazing copy that hypnotizes user into clicking like']); });
-->
</script>

Ok, everyone is with me so far? Now this (in theory) will give me like and unlikes for the featured experimental like button, but it will ALSO send data on other like buttons on the page, correct?

The question is: How do I isolate the edge.create callback (or whatever) to only fire when the desired like-button is clicked? Is there parrameters or arguments I can pass to the fb.event.subscribe that will check if the 'liked' url is the desired facebook page, maybe? or maybe if the liked url differs from the domain?

I am a total newb with js, jquery, and anything beyond basic php, html, or css. please help! :P

Aldwoni
  • 1,168
  • 10
  • 24

2 Answers2

0

This is the actual documentation for FB.Event.subscribe.

I don't know where you got your snippet but the doc says it only returns 1 parameter in the callback.

FB.Event.subscribe('edge.create', function(response) {
        alert('You liked the URL: ' + response);
});

If you want to separate like buttons, the answer is not in what you pass to the function, but what you receive from the callback.

After you receive the data in response, that is where you do the separate action you want with each URL to be liked. That 'data' in response is the URL that the user liked.

In that way of thinking, then you should:

FB.Event.subscribe('edge.create', function(response) {
    if(response == "FULL-URL-YOU-WANT-SEPARATED"){
        _gaq.push(['_trackEvent', 'facebook', 'click', 'amazing separate copy that hypnotizes user into clicking its own like button']);
    }
});

If you want to detect if that URL is any link from a specific domain, you might wanna get the URL's domain and check if response startsWith it.

EDIT:

Try this and see if theres a pop-up box, only when your own like button is clicked.

FB.Event.subscribe('edge.create', function(response) {
    if(response == "https://www.facebook.com/mysticpoliticsradio"){
        alert("Your like button has been clicked.");
        _gaq.push(['_trackEvent', 'facebook', 'click', 'amazing separate copy that hypnotizes user into clicking its own like button']);
    }
});
Community
  • 1
  • 1
dragonjet
  • 1,006
  • 7
  • 16
  • thanks for the answer. I am certain I don't understand :) Here is where I got the snippet [link]http://www.napkyn.com/blog/2011/07/06/track-facebook-like-google-analytics/[/link] The link being liked would be facebook/mysticpoliticsradio - what would that snippet look like? Do I need to do the startswith stuffs? I would only be liking the root domain of my site or the fb page. I appreciate the answer and hope you are patient enough to explain a bit more ;) – everetttucker May 17 '12 at 02:07
  • http://www.napkyn.com/blog/2011/07/06/track-facebook-like-google-analytics/ <-- the above posted link redirected to a linkedin google analytic post. weird. – everetttucker May 17 '12 at 02:09
  • That post is almost one year ago, there should be changes to the Facebook API in that length of time. Check the edit on my answer. – dragonjet May 18 '12 at 21:13
0

Use it like

function(response,widget) {
    if(widget.dom.id == "your fb_button_id"){
        alert("Your like button has been clicked.");
        _gaq.push(['_trackEvent', 'facebook', 'click', 'amazing separate copy that hypnotizes user into clicking its own like button']);
    }
}

add your fb button like this

<div class="fb-like" data-send="false" data-layout="box_count" id="fb_button_id"></div>
Sergey K.
  • 24,894
  • 13
  • 106
  • 174
hitesh
  • 1