How to Leverage Facebook Data for Advanced Analysis in Dundas BI

January 13, 2020 Razi Iqbal

 

The advent of social networking has significantly transformed the shape of businesses as it provides global outreach that was never possible before. In this era of smart devices, people can stay up-to-date about their businesses no matter how mobile their activities are. This blend of social networking and smart devices has exponentially enhanced the possibilities of reaching out to and engaging with customers in an unprecedented manner.

With over 2.45 billion monthly active users, Facebook undoubtedly outshines other social networking platforms and provides a compelling reason for businesses to promote themselves using this platform. The sheer volume of data that Facebook generates can help businesses unearth unbelievable insights about how customers and prospects are interacting with them and offer ways to optimize and grow. No matter the size of the business – small, medium or large – Facebook has the potential to benefit it.

With Dundas BI – Dundas’ fully open, end-to-end business intelligence (BI), data analytics, and dashboarding software – you’re provided an excellent way of analyzing the massive amounts of data generated by Facebook.

For example, an organization that uses a Facebook page as a Marketing strategy for generating brand awareness might be interested in seeing how many new followers they have, or how many engaged users they have. Dundas BI can fetch this information from their corporate Facebook page (e.g., posts, likes, comments) and many other components that can then be used for creating dashboards for at-a-glance monitoring.

Having this information readily available on a dashboard can give a Marketing or Campaign Manager an overview of how well their Facebook page is doing to drive engagement.

This blog provides a high-level overview of Dundas BI’s flexibility and how to use various Python libraries to fetch crucial data from your corporate Facebook page. Once the data is available in Dundas BI, I’ll show you how to create a dashboard that presents the information you desire in a sleek and efficient manner.

 

Getting the Access Token from Facebook

To access your data from Facebook, an access token is required. In order to get that, Facebook requires a developer account that can be created through the Facebook Developers page. Once a developer account is set up, the next step would be to create an App in Facebook. This can be done through MyApp > Create App.

I have already created an App named, “DundasBIApp” on Facebook (see Fig. 1 below).

Fig. 1. Facebook App in Developer console

The next step would be to get a Page Access Token through the Graph API Explorer (Tools > Graph API Explorer) for the specific Facebook page you would like to extract data from. Please note that Facebook might require you to have admin access, depending on which page you’re fetching information from. I have admin access to the Dundas Data Visualization Facebook page and have accessed the token for it.

Fig. 2 below illustrates the selection of the page:

Fig. 2. Page Access Token for Dundas Data Visualization Facebook Page

The page access token might require special permissions for accessing certain information (e.g., to fetch email addresses, email permissions are required that can be selected from the Permissions section of the Graph API Explorer). Once all required permissions and token information have been set, click the “Get Access Token” button to get the required access token.

To learn more about Access Tokens, please refer to this link.

The Graph API Explorer provides a mechanism to get JSON for selected attributes of the page or profile. For the purpose of this blog, I have requested a limited quantity of information be fetched from the Dundas Data Visualization Facebook page to avoid fetching large amounts of data.

Below is the query I used for requesting information from Graph API Explorer:

DundasDataVisualization?fields=name, country_page_likes, events, new_like_count, visitor_posts.limit(10), videos, posts.limit(10), emails, location

A screenshot of the sample JSON response returned by the requested query above is shown below:

Fig. 3. Sample JSON response generated by Facebook App

 

Using the Python Data Generation Transform in Dundas BI

Once the JSON response is generated by the Facebook App, your focus would be to consume this information in a meaningful manner using Python. Dundas BI provides a Python Data Generation Transform for this exact purpose.

In order to do this, a Data Cube with a Python Data Generation Transform is created in Dundas BI as shown in the screenshot below:

Fig. 4. Dundas BI Data Cube

As illustrated in Fig. 4, I have used Calculated Element Transforms to further clean up and format the data, which is one of the ways Dundas BI can help when specific formatting or conversion is required for the data.

Below is the script used in our Python Data Generation Transform to consume the JSON response:

       import requests
       import pandas
       token = "**Use Token from Graph API Explorer Here**"
       def req_facebook(req):
           r = requests.get("https://graph.facebook.com/v5.0/" + req , {'access_token' : token})
           return r
 
       r = req_facebook("DundasDataVisualization?fields=name,country_page_likes,events,new_like_count,visitor_posts.limit(10),videos,posts.limit(10),emails,location")
       results = r.json()
 
       dictName = { k:v for k,v in results.items() if 'name' in k }
       dictCountryPageLikes = { k:v for k,v in results.items() if 'country_page_likes' in k }
       dictEvents = {'events': len(results['events']['data'])}
       dictNewLikes = { k:v for k,v in results.items() if 'new_like_count' in k }
       dictVisitorPosts = {'visitor_posts': len(results['visitor_posts']['data'])}
       dictVideos = {'videos': len(results['videos']['data'])}
       dictOwnPosts = {'own_posts': len(results['posts']['data'])}
       dictEmail = { k:v for k,v in results.items() if 'email' in k }
       dictAddress = { k:v for k,v in results.items() if 'location' in k }
 
       dundasDict = {}
       dundasDict.update(dictName)
       dundasDict.update(dictCountryPageLikes)
       dundasDict.update(dictEvents)
       dundasDict.update(dictNewLikes)
       dundasDict.update(dictVisitorPosts)
       dundasDict.update(dictVideos)
       dundasDict.update(dictOwnPosts)
       dundasDict.update(dictEmail)
       dundasDict.update(dictAddress)
 
       dataFrame = pandas.io.json.json_normalize(dundasDict)
       return dataFrame
 
                    

Returning a Data Frame from the Python Data Generation Transform would help Dundas BI in recognizing the key value pairs in the Process Result Transform as illustrated in the screenshot below:

Fig. 5. Data Preview in DBI Data Cube

 

Designing the Dashboard in Dundas BI

Now that Dundas BI has recognized the data, it arranges it in the form of measures and dimensions based on their data types as shown in the figure below:

Fig. 6. DBI arranges the data in the form of Measures and Dimensions

Once the data is available in Dundas BI, we can design a dashboard to provide the required information at-a-glance. Below is a 500 x 450 px dashboard I’ve created that includes a Data Image, Data Labels, Labels, and Rectangle Components:

Fig. 7. Dashboard Layout – 1

Once the layout of the dashboard is complete, it is just a matter of dragging and dropping the measures and dimensions to their appropriate places. To start with, I have placed the Title, Address and Email components on their corresponding Data Labels as shown in the figure below:

Fig. 8. Dashboard Layout – 2

After completing the top part of the dashboard, the next step is to place the measures on their corresponding tiles. In order to place the measures, each tile should have a Data Label as well. I have added Data Labels to each of the tiles from Dundas BI’s Data Visualization dropdown and have then populated the Data Labels with their corresponding measures as shown in the figure below:

Fig. 9. Dashboard Layout – 3

The final step is to populate the Data Image with the display picture of our corporate Facebook page. In order to do that, simply fill the image path property of the Data Image with the URL of the display picture, which is in the following format:

https://graph.facebook.com/v5.0/<Page_ID>/picture

 

The Final Dashboard

After updating all the individual items on the dashboard, the final result will look like the following:

Fig. 10. Final Dashboard

 

As mentioned earlier in the blog, the data retrieved from the Facebook App was intentionally kept to a minimum to avoid delays in fetching large amounts of data (e.g., own posts and visitor’s posts are limited to 10 posts only).

Dundas BI provides multiple ways of interacting with social networking platforms like Facebook, Twitter, and LinkedIn. The method provided in this blog is just one way of achieving that. One of the other ways of achieving the same would be to build custom extensions.

To learn more about custom extensions in Dundas BI, I highly recommend reading this Support document.

About the Author

Razi Iqbal

Razi Iqbal is a Technical Trainer at Dundas Data Visualization. He has several years of experience in computing and data analysis and has trained many professionals and students in these areas. His keen interest lies in analyzing data generated from IoT devices and presenting them in a meaningful manner. He has numerous research articles published in reputed journals, magazines, and books.

Follow on Linkedin More Content by Razi Iqbal
Previous Blog
Three Trends That Will Drive Enterprise Analytics in 2020
Three Trends That Will Drive Enterprise Analytics in 2020

Companies are swimming in ever-growing oceans of data and are looking for ways to make better use of it. He...

Next Blog
From Table Relationships to Slicer Comparisons, Experience Dundas BI Version 7
From Table Relationships to Slicer Comparisons, Experience Dundas BI Version 7

We highlight 3 brand new features in Dundas BI version 7 that focus on providing even more flexibility to w...

×

Request a Live Demo of Dundas BI

First Name
Last Name
Company Name
Phone Number
Country
I consent to receive commercial electronic messages from Dundas regarding products, services, updates and other information about Dundas. You can withdraw your consent at any time.
I Agree
Thank you!
Error - something went wrong!