Benvenuti da Idea R | Vicenza - Romano di Lombardia (Bergamo)

Blog

Prendere uno smanettone del software degli anni 80, aggiungere un graphic designer di nuova generazione e allungare il tutto con uno studioso di strategie di marketing. Agitare energicamente e si ottiene il blog Idea R.

Internal campaigns with Google Analytics and .NET AdRotator

Pubblicato il 7/17/2012
Categorie: Web Analytics
Internal campaigns with Google Analytics and .NET AdRotator

Questo articolo è disponibile anche in italiano.

An internal campaign banner is one that points to the same site it is contained in, for example you may advertise for one of your products while the user is looking at another one.
For banners hosted in external sites the best way to collect statistics is to use UTM (Urchen Tracking Module) query parameters: Google Analytics can automatically collect and group this type of data.
On the other side, the UTM approach is not good for internal campaigns, because when mixed with external ones, it compromises the analysis: try to imagine what happens if a user clicks on an external banner, then in an internal one and finally she makes a conversion. Which is the cause and which is the effect?

For internal campaigns the best way to collect data is the event tracking feature of Google Analytics. Event tracking was created to analyze many types of user actions, also the ones that are not directly related to a page visit, for example downloading a file, listening an MP3, showing a video, etc.

To enable event tracking when a user clicks on our banner we add the following code the the link:

onclick="gaq.push(['_trackEvent', 'MyCampaignName', 'MyBannerName', this.href]);"

When using ASP.NET AdRotator control, all advertising data is contained in a XML file, but apparently there's no way to assign a JavaScript event to a link. We can do this in two ways, by jQuery on the client side or by C# on the server side.
In this case I prefer the server side because I'm rotating the advertisements (you can use jQuery if your AdRotator contains only one advertisement) and I can add more information to the statistics while rendering the control. To accomplish this we'll use the AdRotator custom properties, that is we'll add a custom field named CampaignName to the XML file.

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
    <Ad>
        <ImageUrl>~/images/MyFirstBannerImage.jpg</ImageUrl>
        <NavigateUrl>~/MyFirstPage.aspx</NavigateUrl>
        <CampaignName>My first campaign</CampaignName>
    </Ad>
    <Ad>
        <ImageUrl>~/images/MySecondBannerImage.jpg</ImageUrl>
        <NavigateUrl>~/MySecondPage.aspx</NavigateUrl>
        <CampaignName>My second campaign</CampaignName>
    </Ad>
...

To conclude will generate the JavaScript when the control fires the AdCreated event:

 private void m_MyAdRotator_AdCreated(object sender, AdCreatedEventArgs e)
{
    ((AdRotator)sender).Attributes.Add("onclick",
        String.Format("_gaq.push(['_trackEvent', '{0}', 'MyBanner', this.href]);",
        e.AdProperties["CampaignName"]));
}

That's all, now in your Google Analytics profile you can analyze internal and external campaigns without messing all your data.

Has this article been useful to you?

Help us to spread it over the network using StumbleUpon.
Just press the button here below!

Sei il lettore numero 16,175.

Commenti

Articolo precedente

Articolo precedente

How to include CSS files programmatically in ASP.NET

Articolo successivo

TechEd Europe 2012: rapporto su Windows 8 da Amsterdam

Articolo successivo