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

      Idea R - Plan your visual communication at 360°

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

Tracciare i like di Facebook con Google Analytics, la vera soluzione!

Published on 10/28/2012
Last update 3/28/2013
Categories: Web Analytics
Tracciare i like di Facebook con Google Analytics, la vera soluzione!

This article is available in English too.

Le interazioni sociale dei vostri clienti sono molto importanti per analizzare il loro impatto nelle vostre conversioni.
Leggendo la guida ufficiale degli sviluppatori di Google Analytics, la soluzione sembrerebbe essere quella di usare il codice seguente:

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

Se invece si vuole aggiungere l'event handler a runtime, la soluzione corretta è quella di usare l'evento window.fbAsyncInit per aggiungere in coda all'inizializzazione dell'SDK la sottoscrizione all'evento "mi piace".
Nel codice seguente ho usato jQuery per sottoscrivere l'evento dopo l'inizializzazione del DOM.

$ (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]);
            });
        };
})
;

Ovviamente, se stai usando l'Infrared CMS, questo è un problema di cui non devi preoccuparti.

You are the reader number 10,896.

Comments

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

Scroll to top