Tips & Tricks #1 - Using Google Analytics to build KPIs
I decided that this year I would make a New Year's resolution to start building better KPIs with Klipfolio Dashboard web and mobile. As an added bonus, I thought I would share my work and progress on the KlipBlog and in a new section in our Knowledge Base. I've got lots of great KPIs (key performance indicators) planned for the coming months, so make sure to check back regularly to see what's new.
This week I want to delve into Google Analytics - a topic I am certain we will revisit again (and often) in the future - and see how you can use it build web analytics KPIs in Klipfolio Dashboard. Another important aspect of working with Google Analytics is working with the XML data source to assign data to the Klip.
The topics covered in these tips and tricks articles are designed for intermediate or advanced users. Don't worry if you are still getting the hang of Klipfolio Dashboard web and mobile - I'll provide you with all the resources you need to get up to speed at the beginning of each article and when we encounter tricky parts.
Important how to articles
Preview of the Web Analytic KPI
Building an automated web analytics dashboard
Google Analytics is one of the quintessential tools in the repertoire of the online marketers, especially for users looking to design a web analytics dashboard. Many users are probably already familiar with the Google Analytics reporting UI, which provides lots of great data on site visitors, traffic sources, and site content. Well, in order to plug that data into Klipfolio Dashboard you need to use the Data Feed Query Explorer to craft a query URL.
I guess that isn't entirely true, as you can export that data into CSV format and then plug it into your dashboard directly from your computer. But by doing this you will be missing out on an incredibly cool and important feature: automatic updates. By exporting the Analytics data using the Data Feed Query Explorer, you can use and reuse the query URL to get regular updates of your data. Then, whenever your data is updated, any Klips on your dashboard using that data will be automatically updated as well. That means once you are done building this KPI (assuming you are following along), then you won't need to update it ever again. Very cool, indeed!
Using the Data Feed Query Explorer can be tricky for users accustomed to the UI of the Google Analytics reporter, but it is an essential tool for crafting your URL. This is a topic that I plan to revisit in the future in more detail, but for now, I simply want to introduce the fields that are relevant to this particular KPI.
- Data Feed URI - As you build your query, this URL in this field will change to represent that query. You will copy and paste this link into Klipfolio Dashboard once you are done crafting the query.
- ids field - This is where you select which of your manage sites you want to retrieve your Analytics data.
- Dimensions field - A Dimension is best thought of as a type or category of data. For instance, a dimension is a ga:visitorType such as New or Returning (versus a metric such as # of visitors).
- Metrics field - A Metric is best though of as the count or metric associated with a dimension. For instance, a metric is the number of vistors (versus a dimension such as visitorType).
- Date Field - The start and end-date determines the time period that the data is retrieved. However, it is important to note that once in Klipfolio Dashboard, you can modify these dates to provide up-to-date information (this will be explained below).
Crafting the URL
Using the Data Feed Query Explorer you will craft your URL to query the data you want from Google Analytics. Following these instructions, you will retrieve the following information: date of visit, total visitors, new visits, percentage of visits that are unique. Before starting these steps, refer to the Google Analytics how to article.
To craft the URL query
- Select the website to monitor from the ids field.
- Select the ga:date dimension from the dimensions field.
- Select the ga:visitors, ga:newVisits, and ga:percentNewVisits from the metrics field.
- Select appropriate start and end dates from dates field.
Note: The dates are going to be modified in Klipfolio Dashboard.
- Click the Get Date button.
- Confirm that the data retrieved is correct.
- Copy the URL from the Data Feed URI field.
Note: You will be pasting this URL into Klipfolio Dashboard in a few moments, so don't lose it off your clipboard.
Refining the date parameters
Remember what I said about the automating the data retrieval so all your Klips using that data source will be automatically updated? Refining the date parameters is the critical step in setting this up, as it will allow you to change the data set from a historic metric to a moving or rolling metric (check out this article to learn more about time frames and comparative metrics). By modifying the date parameters of the URL, you will be able to retrieve fresh data from your Google Analytics at a predetermined refresh rate. Again, if you find yourself lost in the progression of these steps, please refer to the Google Analytics how to article.
To refine the date parameters
- Paste the query URL into Klipfolio Dashboard.
- Select the start-date field in the URL.
Note: It is formatted as YYYYMMDD.
- Change the start-date to this exact phrase {date.last30Days}.
- Select the end-date field in the URL.
Note: It is formatted as YYYYMMDD.
- Change the end-date to this exact phrase {date.today}.
- Click the Get Resource button.
- Move on to the Edit Klip Workspace.
If you followed these instructions precisely, then the data source will now return a rolling metric that will always display the last 30 days worth of data up to the current date. If you are getting an error when you click the Get Resource, make sure to check the URL for any typos you may have accidently inserted.
Working with XML to assign data to your Klip
When you use the Google Analytics explorer, the data will be exported as an XML document. XML simplifies the distribution of data and makes working with large data sets easy - that is once you get the hang of XML. I recommend that you check out the how to article on XML for more information on how to work with this data format.
Once you have your URL plugged into Klipfolio Dashboard and have created a data source, then you can begin assigning that data to a Klip. In this example, I am going to use a Table Klip because I want to see my numbers as they coincide with each day in the reporting period (see preview above).
I want to start with first column of the table, the one that will display the dates in the reporting period. This is the most challenging step in completing this Klip, because we need to change the date format so that rather than reading a string of numbers such as 20111112, it will read as Dec 12, 2011. Follow these steps closely to get set up the date formatting.
To change the date formatting
- Select the value node from the dxp:dimension parent node.
- Click the Function Wrap button on the formula bar.
- Select the Date and Time function category.
- Select the DATE function.
Note: This will return a numeric epoch date, which will then be returned as a formatted date at steps 11-14.
- Click the Format link in the formula editor.
- Click the Insert Literal string button on the formula bar.
- Type yyyyMMdd in the text field.
- Click the Apply button.
Note: This will return an epoch date or a string of numbers. Don't worry, this will be addressed in the following steps.
- Click directly on the DATE text in the formula editor.
- Click the Function Wrap button on the formula bar.
- Select the DATEVALUE function (from the Date and Time category).
- Select the Properties tab in the Properties Editor.
- Change the Format As to Date/Time.
- Select the MMM dd, yyyy option from the Date Format menu.
The date is properly formatted and will appear in descending order with the last date of the reporting period at the top of the table.
The next step is to start assigning the actual numbers to the remaining three columns. Each of the metrics we will use (ga:visitors, ga:newVisits, and ga:percentNewVisits) are assigned to columns in precisely the same way, so I will only detail these steps once, and then you can reapply them as necessary. I will start with the ga:visitors metrics.
To assign XML metrics to the Klip
- Select the @ value metric below the ga:visitors node.
Note: This will be a numerical value and each node associated with that path will be assigned to the table as an array, eg, in ordered rows in a single column.
- Click the lock icon beside the dxp:metric path at the top of the Properties Editor.
This will tell Klipfolio Dashboard to only assign information associated with that specific node, eg., the one that contains the ga:visitors metric. Otherwise, each metric associated with @ value will be assigned to that column.
Repeat these steps for the remaining columns, looking instead for the ga:newVisits and ga:percentNewVisits specific @ value. Don't forget to lock the path down to return the metrics that are relevant to your query.
Conclusion
Once you've finished adding all the metrics to the Table Klip, you can save the Klip and add it to your Dashboard. As I stated earlier, the cool thing about this Klip is that it will automatically update to provide you with latest set of data. As well, you can use the same techniques for working with XML to create any number of Klips using this data source now that it is formatted and saved in your Library. A Sparkline or Bar chart Klip immediately comes to mind.
That's it for now, but I'll be back again soon with some more tips and tricks!
Got an idea for a future Tips and Tricks article? Then share your idea in one of these great places: