Using PowerMetrics to track Twitter data
In this article we learn how to create a Twitter PowerMetric to track different things like followers, likes, following, and the number of tweets with one or multiple twitter handles.
Note: this article assume you would have the basic knowledge of creating a PowerMetric.
For the first example, let’s start with a basic PowerMetric that measures the number of followers for 1 specific handle. To do this, you can take advantage of one of our pre-built PowerMetric templates. To understand what is behind this pre-build PowerMetric see the steps below.
- Datasource Query: you can use this query and replace twitterHandle1 with your own twitter handle:
- For the model creating, you select followers from the underlying datasource.
This gives you a PowerMetric that tracks followers for one twitter handle.
Please note that in this PowerMetric, you will have 1 day worth of data initially, however the history grows over time. In the above example, we started the PowerMetric on Aug 1st, 2019.
Above is a great first PowerMetric to try out the basics but what if you have multiple twitter handles you want to track followers for?
Fortunately, the twitter API allows us the option of passing multiple screen names or twitter handles into one single request. So in this 2nd example let’s create a PowerMetric that shows followers for multiple handles.
The steps for creation of datasource, model and PowerMetric.
- For datasource query you can use below example, you may replace twitterHandle1, twitterHandle2, etc with your own twitter handles.
- Note: A comma separated list of screen names, up to 100 are allowed in a single request.
- The output data is coming in Json format. It has a node for each handle. In our example there are 5 handles.
- Model Creation (Steps for each column’s formula) :
1- Screen Name column:
Now you can see the followers for several twitter handles in one PowerMetric view as shown below.
Now, let’s take it one step further and create a PowerMetric where there are multiple handles and multiple twitter entities tracked like followers, following, likes and tweets.
The datasource query is exactly the same as with the previous example
- To reiterate, The data source query you can use would looks like this:
- Each node has data for each handle and you can see there are multiple entities:
- To create the model, we will have 3 columns to track the Screen Name for each twitter handle, the Category (followers, following, likes and tweets) and the Value for each Category.
- Column 1(Screen name formula):
Repeating each ScreenName 4 times. As we are tracking 4 metrics here (Tweets, Followers, Following and Likes)
- Col 2 (Value formula):
Use Array() to combine the different entity values into one column.
- Then Col 3 (Categories formula)
Simply repeat each category name, e.g. followers, for the count of the unique twitter handles in the data source.
Once your model is ready to go, you can create your powerful PowerMetric that allows you to see multiple different handles and measures. Below is a dashboard built using this PowerMetric example.
Hope that helps!