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

Internal campaigns with Google Analytics and .NET AdRotator

Published on 7/17/2012
Categories: Web Analytics
Internal campaigns with Google Analytics and .NET AdRotator

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!

You are the reader number 8,150.

Comments

Previous article

Previous article

How to include CSS files programmatically in ASP.NET

Next article

TechEd Europe 2012: Windows 8 report from Amsterdam

Next article

Scroll to top