Adventures with R - Facebook Ads (Part 2)

We covered the very high level of automating Facebook Ads via R in Part 1

Before we get started in Part 2, it is essential to download R Studio. There are other R development environments around but R Studio is the best environment that I have come across. Needless to say, you need Base R also. This post does not get into the basics of R (Idea for another post!)

Once you have R Studio in place, it is essential to get the fbRads package. Hat tip to Gergely Daroczi. His package is an excellent package, well documented, well supported and most importantly, fast !!! 


The next requirement is to create a Facebook App and create an oAuth token. 

The package link within GitHub covers the creation of the token but I have modified some of the steps as per my findings

Creating a Facebook App & connect with OAuth token

To be able to use this package, you will have to create a Facebook App and authorize it to manage your Facebook ads. Basic steps to create an app with Development access level letting you manage up to 5 Facebook ad accounts:
  1. Create new application at https://developers.facebook.com/apps with "basic setup".
  2. Fill in a unique Display Name (eg "app_testing_foobar_42"), set the category to eg "Business" and provide your e-mail address. Click on "Create App ID" & pass the captcha test.
  3. In "Settings/Basic", click "Add Platform" add create "Website" platform with the URL of http://localhost:1410/ and "localhost" as the "App Domain". Click "Save Changes".
  4. Add a new "Facebook Login" product, and then set http://localhost:1410/ as the "Valid OAuth redirect URIs". Click "Save Changes".
  5. Also add and configure the "Marketing API" product.

My findings
1. Try to use the same Facebook credentials for your developer app and your business manager login. It makes life easy. 

2. Under the Settings --> Advanced, there is a tab for "Advertising Accounts". Go to your Facebook Business Manager login and grab the main account id and add it here. Again, it is not a required step but it made the data transfer go smoothly

3. You will three additional products under your App.
  • Facebook Login : Use the default settings but under the "Valid OAuth redirect URLs", make sure you add the http://localhost:1410 as per Gergely instruction number 3. This is a critical step. I did not have it set up during my initial testing and had to go back to this step.
  • Analytics : Default settings
  • Marketing API 
    • You need to create a "Sandbox Ad account ; add the main page you want to track here. 
    • Select Token Permissions : you need read_insights and ads_read (recommended, not required)
    • Under settings, add the Ad account you want to track insights for

4. Never expire a Facebook token. You are going to need a never expiring Facebook token as it will expire after sixty days under the default setting. I found this excellent thread from Stack Overflow : https://stackoverflow.com/questions/17426018/generate-never-expire-access-token-for-facebook-page  

Follow the instructions to create a never expiring Facebook token.  
Facebook Graph API explorer is at https://developers.facebook.com/tools/explorer/

Hit the drop down under the "Application" on the upper right hand side and select your new app to follow the instructions for the never expiring Facebook token. 

We are now ready for Part 3.. 

Comments

Vomail said…
I think facebook ads services are explained in such amazing details with step by step settings. Got to know about the excellent teams for our help. Will discuss the package and tools to be used for guaranteed results. Can go for additional factors on our website to make it more presentable for customers.
Pranav Baruwala said…
Thank you for sharing informative blog. really, its nice blog.
What are facebook business manager

Popular posts from this blog

Balkanization of Pakistan

Film Reviews on IndiaFM

Outsourcing - the new wave !!