× Joomla Facebook Connect support forum

Topic-icon Adding Google Analytics Facebook Like Tracking Code

Active Subscriptions:

None
14 years 10 months ago #11909 by Ivan
Would it be a good idea to add the google analytics tracking code for facebook likes in the system plugin?

I came across this article where they use:
www.socialmediaexaminer.com/how-to-track...th-google-analytics/


They are using:
_ga.trackFacebook();


I however am using the Facebook recommend and outputting it in a module in this way
echo  "";
    
The topic has been locked.
Support Specialist
14 years 10 months ago #11917 by alzander
Our forum strips out a lot of text, so I don't know exactly what you were looking for. However, the _ga.trackFacebook(); code looks like it can be placed anywhere on the page. I wouldn't put it in the asynchronous call to the Facebook at all, but would simply include it in the header, or even just in the body of the document in any script tag.
I'd say that ideally, it would actually go in the same area as the Google Analytics code to make sure that library has properly loaded first, but I haven't tested what you're trying to do at all, so can't really say the best course.

Hope this helps,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 7 months ago #14660 by mtk

alzander wrote: Our forum strips out a lot of text, so I don't know exactly what you were looking for. However, the _ga.trackFacebook(); code looks like it can be placed anywhere on the page. I wouldn't put it in the asynchronous call to the Facebook at all, but would simply include it in the header, or even just in the body of the document in any script tag.
I'd say that ideally, it would actually go in the same area as the Google Analytics code to make sure that library has properly loaded first, but I haven't tested what you're trying to do at all, so can't really say the best course.

Hope this helps,
Alex

on the tutorial they recoomend putting it just inside the <fb:like> tag, but looking at the source code of their page, they just place it at the page's header (which is logically good since it's just JS).

in my case, I don't see any tracking being done, and I have clicked LIKE several time (and other users have LIKEd pages too).
The topic has been locked.
Support Specialist
14 years 7 months ago #14666 by alzander
We still haven't done any testing with this. Can you post (or PM) your page with the code inserted, and we'll see what we can do?

The code definitely shouldn't be added 'within' the fb:like tag, as that would cause a mess of problems. That is what they say, but even if you look at their code snippets, the ga.trackFacebook call is outside (right before) the fb:like opening tag.

As for the code working itself, if you put it in the head, it would have to be after the ga_social_tracking.js inclusion. If that's still not working, if you have Notifications setup in JFBConnect for new comments and likes, try disabling that (temporarily) and see if that lets the Like's start showing. Both use the same notification system, which should be fine, but it's our best suggestion to try changing to see if it helps.

Let us know how it goes, and we'll be looking into something like this in a future release as well.

Alex
The topic has been locked.
Active Subscriptions:

None
14 years 7 months ago #14670 by mtk

alzander wrote: We still haven't done any testing with this. Can you post (or PM) your page with the code inserted, and we'll see what we can do?

www.joomla.co.il (it's in Hebrew, but look on the right, below the login)
I have other websites with similar problems but they are of my clients so we'll leave them from now... :)

alzander wrote: The code definitely shouldn't be added 'within' the fb:like tag, as that would cause a mess of problems. That is what they say, but even if you look at their code snippets, the ga.trackFacebook call is outside (right before) the fb:like opening tag.

yeah, I said they are not adding the code in the fb:like tag.
and no, the JS before the fb:like tag, is the fb:like script, not the tracking...

alzander wrote: As for the code working itself, if you put it in the head, it would have to be after the ga_social_tracking.js inclusion. If that's still not working, if you have Notifications setup in JFBConnect for new comments and likes, try disabling that (temporarily) and see if that lets the Like's start showing. Both use the same notification system, which should be fine, but it's our best suggestion to try changing to see if it helps.

the code is after the ga_social_tracking.js, simply like this:
        <script type="text/javascript">

                var _gaq = _gaq || [];
                _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
                _gaq.push(['_trackPageview']);

                (function() {
                        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                })();

        </script>

        <!-- Google Analytics Social Button Tracking -->
        <script src="https://s3.amazonaws.com/ha_js/ga_social_tracking.js"></script>
        <script type="text/javascript">_ga.trackFacebook();</script>
...

</head>

alzander wrote: Let us know how it goes, and we'll be looking into something like this in a future release as well.

Alex

As suggested, I've disabled the notification on the above website, so if you click LIKE we would be able to test it... :)
The topic has been locked.
Active Subscriptions:

None
14 years 7 months ago #14697 by mtk
24hours later, still no tracking in Analytics... :(
The topic has been locked.
Support Specialist
14 years 7 months ago #14702 by alzander
mtk,
I just clicked on the Like in the sidebar for the home page. It increased the count, so check if the Analytics saw it as well. May take a day or so, as you know.

Also, on the left hand side of the page, you have a Like button for what looks to be your Facebook Page at www.facebook.com/JoomlaIsrael However, when I click the Like, I get an error that I don't have permission to see that page. I can't even visit the FB Page directly. Can you check that your Page is marked as public and not in admin/development mode?

Hope that helps,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 7 months ago #14703 by mtk
sorry, the FB page was limited to Israel (don't remember why).

could you try again?
The topic has been locked.
Support Specialist
14 years 7 months ago #14717 by alzander
Clicked.

Not sure if the Analytics code, as shown on your page, will work as it's possible the Facebook Javascript library won't be fully loaded by the time your code tries to 'attach' to it.

If so, a possible fix is to leave the inclusion of the Amazon javascript file where it is, and place the _ga.trackFacebook() code in the JFBCSystem plugin. To do so, edit the /plugins/system/jfbcsystem.php . Around line 161, you'll see:
FB.init({appId: '{$appId}', status: true, cookie: true, xfbml: true, oauth: true, channelUrl: '{$channelurl}'});{$subs}{$resizeCode}
Add the _ga call to the next line, like so:
FB.init({appId: '{$appId}', status: true, cookie: true, xfbml: true, oauth: true, channelUrl: '{$channelurl}'});{$subs}{$resizeCode}
_ga.trackFacebook();

Let us know how that goes!
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 7 months ago #14718 by mtk

alzander wrote: Clicked.

Not sure if the Analytics code, as shown on your page, will work as it's possible the Facebook Javascript library won't be fully loaded by the time your code tries to 'attach' to it.

just curios: is it a speed issue?
I can put the file locally and it will load a lot faster...
The topic has been locked.