Welcome to Idea R | Branding - Web Agency - Digital Strategies
Switch to the mobile layout

      Idea R - Do your competitors are always ahead? - Raise your voice with web marketing!
  • HomeHome
  • About UsAbout Us
  • ContactsContacts

Blog

Take a software geek from the 80s, add a new generation graphic designer and dilute with a longtime marketing strategist. Shake vigorously and you'll get the Idea R's blog.

Change language... italiano
Go to the blog summaryGo to the blog summary

You may be interested in

How to dramatically increase social media LIKEs to your web site

How to dramatically increase social media LIKEs to your web site

Here's a free download that I created some time ago. It's a good tool for increasing engagement, but use with caution.

Internal campaigns with Google Analytics and .NET AdRotator

Do you have banners that point to the same site they are contained in? Be careful on how you setup Google Analytics...

Last published

[FREE download] Keywords Mixer: long tail keywords made easy

[FREE download] Keywords Mixer: long tail keywords made easy

There's a basic implementation inside Google AdWords Editor, but this tool will give you more control over permutations and long tail keywords.

Case study: advertising B2B maintenance

How is it difficult to advertise maintenance services in B2B? Let's explore this case study and discover secrets and most common mistakes.

Most popular

Lazy loading and the SEO problem, solved!

Lazy loading and the SEO problem, solved!

The best SEO solution to index your dynamically loaded contents, no more compromises!

Milano Design Week 2017, Design Districts

Ventura Lambrate and Tortona, here are the best creations that we discovered in the 2 districts of the Fuorisalone Milan Design Week 2017.

Editor's pick

Case study: branding and marketing for a magician

Case study: branding and marketing for a magician

Singular case study in the world of illusionism. See how we have created a brand and a web marketing campaign with exceptional results.
Mental marketing secret #1: the fake compromise

Mental marketing secret #1: the fake compromise

Can mentalism influence marketing? As a marketing professional and a long term magician, I will reveal you some tricks.
newsletter

Stay informed on digital strategies

Take a look at the last published articles
RSS feed

Tracking Facebook likes with Google Analytics, the real solution!

Published on 10/28/2012
Last update 3/28/2013
Categories: Web Analytics
Tracking Facebook likes with Google Analytics, the real solution!

Social interaction of your customers are very important to analyze their impact on your conversions.
Reading the official Google Analytics developers guide, the solution seems to be the usage of the following code:

FB.Event.subscribe('edge.create', function(targetUrl)
{
    _gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
});

Unfortunately this code doesn't work if you are correctly loading the Facebook SDK asynchronously, that's because may be the the SDK is still loading when you subscribe to the event.

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function()
    {
        // init the FB JS SDK
        FB.init(
        {
            appId : 'YOUR_APP_ID',
            channelUrl : '//WWW.YOUR_DOMAIN.COM',
            status : true,
            cookie : true,
            xfbml : true
        });

        // Add event subscripion here
        FB.Event.subscribe('edge.create', function (targetUrl)
        {
            _gaq.push(['_trackSocial','facebook', 'like', targetUrl]);
        });
    };

    // Load the SDK's source Asynchronously
    (function(d)
    {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));
</script>

If you want to add the event handler programmatically, the correct solution is to use the window.fbAsyncInit event to append the like event subscription to the Facebook SDK initialization.
In the following code I used jQuery to append the event subscription after DOM initialization.

$ (function ()
{
    var exsistingFbAsyncInit = window.fbAsyncInit;
    if (exsistingFbAsyncInit == null)
        window.fbAsyncInit = function ()
        {
            FB.Event.subscribe('edge.create', function (targetUrl)
            {
                _gaq.push(['_trackSocial','facebook', 'like', targetUrl]);
            });
        };
    else
        window.fbAsyncInit = function ()
        {
            exsistingFbAsyncInit();
            FB.Event.subscribe('edge.create', function (targetUrl)
            {
                _gaq.push(['_trackSocial','facebook', 'like', targetUrl]);
            });
        };
})
;

You are the reader number 6,071.

Comments

Creative Commons License

Photographies, videos, graphics and texts by Idea R are licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.

Previous article

Previous article

How to dramatically increase social media LIKEs to your web site

Next article

Case study: IED Open Day, building a font by hand... literally

Next article
  • Visual Communication, Art DirectionVisual Communication, Art Direction
  • Apps, Cloud, Mobile, Software DesignApps, Cloud, Mobile, Software Design
  • Digital StrategiesDigital Strategies
  • BlogBlog
Touching finger
RSS feed
Blog

Scroll to top