AdTech Analytics Guide

This guide will explain the importance of scalable infrastructure and choosing proper metrics when building out an AdTech platform. In addition, it will provide code examples that utilize Keen’s core features of Data Collection, Data Analysis, and Data Visualization to create a real-time and robust AdTech analytics dashboard, for your teams and customers.

AdRoll’s AdTech Dashboard

Key AdTech Metrics

To get you started, here are six key metrics used by leading advertising providers such as Facebook and Google:

  • Impressions: the number of people who have seen an ad, with a breakdown between Unique Impressions and Total Impressions.

  • Exposure: the average number of times an ad is served per person.

  • Engagement Rate: the number of people who have “engaged” as a percentage of all ad views. For most ads, an engagement is typically a click-through to the advertiser’s site, but can be a video play or other interaction.

  • Conversion Rate: the percentage of people that convert on a desired outcome, such as becoming a paying customer, as a result of an engagement.

  • Relevance Score: a score between 1 and 10 that indicates an ad’s effectiveness and relevance to an audience, calculated by combining other metrics such as Conversion and Engagement Rates.

  • Revenue: total value of all purchases made as a result of an engagement with an ad or campaign.

Using the right data model, you can produce these metrics with only three events:

  • Ad Views: runs once on ad load.
  • Engagement: runs each time a user engages with an ad.
  • Purchases: runs once after a purchase is completed on a client’s site.

These two events also support standard metrics like User Locations and Referral Sources if such information is needed.

Now that you’re familiar with what to track, you’re ready to learn how to track them!

Data Collection

By using Keen’s Javascript SDK, a few open source libraries, and proper data modeling, it’s easy to track Ad View and Engagement events.

General Setup

$(document).ready(function() {

    // Configure an instance for your project
    var client = new Keen({
      projectId: "YOUR_PROJECT_ID",
      writeKey: "YOUR_WRITE_KEY"
    });

    // Anonymized User Data retrieved by custom ad platform code
    var user_data = getUserData();

    // Ad Data
    var ad_data = {
        id: $("#ad").attr("data-id"),
        title: $("#ad").attr("data-title"),
        referrer: document.referrer,
        ip_address: "${keen.ip}", // https://keen.io/docs/api/?javascript#dynamic-placeholders
        user_agent: "${keen.user_agent}"
    }
});

Ad Views

This event would be run on ad load, which for most scenarios would also be on page load.

client.addEvent("ad_views", {
  user: user_data,
  ad: ad_data
});

Engagements

For tracking clicks, which are a type of engagement, you can use jQuery or your preferred framework to run the following event when an ad is clicked:

$("#ad").click(function(event) {
    client.addEvent("engagements", {
        user: user_data,
        ad: ad_data,
        type: "click"
    });
});

Purchases

To correctly track Revenue, you need to associate purchases with an ad or campaign. You can easily create that relationship by recording a purchase in a purchases collection, like this:

client.addEvent("purchases", {
  user: getUserData(),
  product_id: $("#product").attr("data-id"),
  price: $("#product").attr("data-price"),
  ad: getAdData(),
  campaign: getCampaignData()
});

Since your clients will need to run this code on their own site, you may need to provide preconfigured and standalone code snippets that can be inserted into a client’s site, which is a common resource that providers like Facebook and Google offer.

This functionality is best achieved with a script hosted on your site that contains the above Keen event. This gives you control over what code is loaded and the end user only needs to provide the proper purchase details to your custom function that wraps Keen’s client code.


The above code is all you need to properly track the needed events; however, you may want to enrich certain attributes using Keen’s Data Enrichment tool. For the purpose of this tutorial, it is assumed that the data will be enriched.

Data Analysis & Visualization

To note: the following examples contain queries with a static timeframe of the last 24 hours and are filtered by a specific ad, but in a production dashboard, the timeframe and scope of the data can be queried with dynamic parameters, as documented here.

Impressions

Obtaining both unique and total impressions for a client’s ad requires two simple queries:

// Definition of a reusable "filters" array
var filters = [
    {
      "property_name": "ad.id",
      "operator": "eq",
      "property_value": 1
    }
];

var totalImpressions = new Keen.Query("count", {
  event_collection: "ad_views",
  timeframe: "this_24_hours",
  filters: filters
});

var uniqueImpressions = new Keen.Query("count_unique", {
  event_collection: "ad_views",
  timeframe: "this_24_hours",
  filters: filters,
  target_property: "user.uuid" // from getUserData() when storing event
});


// Render Total Impressions Metric
client.draw(totalImpressions, document.getElementById("total-impressions-metric"), {
  chartType: "metric",
  title: "Total Impressions"
});

// Render Unique Impressions Metric
client.draw(uniqueImpressions, document.getElementById("unique-impressions-metric"), {
  chartType: "metric",
  title: "Unique Impressions"
});

The two Keen Queries, totalImpressions and uniqueImpressions, are run when passed into client.draw, which renders a styled Metric item for each metric like this:

Screen Shot 2016-02-15 at 3.21.20 PM.png

You can learn more about rendering custom Metric items here.

Exposure

To calculate a campaign’s exposure, the previous queries, totalImpressions and uniqueImpressions, can be combined using Keen’s Multi-Analysis functionality, like so:


var exposure = new Keen.Query("multi_analysis", {
    event_collection: "ad_views",
    analyses: {
        totalImpressions: {
          analysis_type: "count"
        },
        uniqueImpressionsf: {
          analysis_type: "count_unique"
          target_property: "user.uuid"
        }
    },
    timeframe: "this_24_hours",
    filters: filters // defined in previous code block
});
// Send query
client.run(exposure, function(err, response){
    calculateExposure(response.result);
});

Here’s a sample response that shows what the exposure query returns from Keen’s API:

{
  "result": {
    "totalImpressions" : 1500,
    "uniqueImpressions" : 1400
  }
}

As you can see, the response is structured for easy manipulation by calculateExposure(), making this code a simple division problem:

calculateExposure() divides totalImpressions by uniqueImpressions, so a totalImpressions of 1500 and a uniqueImpressions of 1400 would produce an exposure of 1.07, which represents the average number of times an ad was served to a user.

Engagement Percentage

Funnels are a great way to visualize what percentage of people engage with an ad. Keen has built in support for funnels, so making one is simple:

var funnel = new Keen.Query("funnel", {
  steps: [
    {
     "event_collection": "ad_views",
     "actor_property": "user.uuid",
     "timeframe": "this_24_hours",
     "filters": filters // defined in a previous code block
    },
    {
     "event_collection": "engagements",
     "actor_property": "user.uuid",
     "timeframe": "this_24_hours",
     "filters": filters // defined in a previous code block
    }
  ]
});

var getEngagementPercentage = function(steps){
    return steps[1] / steps[0];
}

client.run(funnel, function(err, response){
     $("#engagementPercentage").text("Engagement Percentage: " + (getEngagementPercentage(response.result) * 100)  + "%");
});

The above code constructs a Funnel Query using the ad_views and engagements collections.

As explained in more detail here, user.uid is stored in each collection and acts as an actor ID. It’s important to remember that each collection needs a unique ID that represents the same actor across all the steps.

Lastly, when the query runs, it returns an array of numbers that shows how many actors progressed to each step. Then the values are turned into a percentage and displayed on a dashboard.

Conversion Percentage

You can calculate the Conversion Percentage in the same way you find the Engagement Percentage. Just make sure to replace the engagements collection with a collection that tracks conversion events.

Relevance Score

Now that you’re able to query for Impressions, Exposure, Engagement Rate and Conversion Rate, you can take those metrics and calculate your very own Relevance Score.

To do so, take the numerical results of your previous queries and run the following code:

calculateRelevanceScore(totalImpressions, uniqueImpressions, exposure, engagementRate, conversionRate);

This will return a score between 1 and 10.

But how does the function know what score to return? Well, that’s up to you to figure out!

As mentioned above, not even Google or Facebook have released their entire scoring system, but it is known that the metrics you’ve learned to track make up a big part of the score. Knowing that, you should be in a good position to make a solid scoring system.

Revenue

To calculate total revenue that an ad or campaign has generated, you will need to run a query for the purchases event:

var query = new Keen.Query("sum", {
    event_collection: "purchases",
    filters: [
        {
            operator: "exists",
            property_name: "ad.id",
            property_value: true
        },
        {
            operator: "eq",
            property_name: "ad.id",
            property_value: 1
        }
    ],
    target_property: "price",
    timeframe: "previous_14_days",
    timezone: "UTC"
  });

// Render Total Revenue Metric
client.draw(totalRevenue, document.getElementById("total-revenue-metric"), {
  chartType: "metric",
  title: "Total Revenue"
});

When the totalRevenue query is run, it selects all the purchases with an ad.id property, indicating the purchase was the result of an engagement. Then, it further filters by a specific ad.id property, which, in this case, is 1. Finally, the query returns and renders the sum of all price properties using Keen’s visualization method client.draw.


Lastly, if you wish to calculate costs like “cost per engagement” for an ad, multiply the engagements count by what you charge per engagement. Simple, right?

What’s Next?

Sign up for a free account to get started. If you’d like to learn more about how to get the most out of your ad tech data, reach out to Schedule a free data consultation with our data team.