Integrating Facebook Ads

Background

The system is pivoted onto three things:

  • Ad account - via which Ads are created, run and analysed. Represent via Ad Account Id
  • User - whose access token is used by App to manage ads on his behalf ; Ensure that this user has admin/advertiser role in the Ad account and developer or Admin Role in the FB App.
  • FB App - to allow others to access ad account via APIs on behalf of user using his/her access token

1.png

 

Create an App 

Go to https://developers.facebook.com/apps/ and click on Add a new App

mceclip1.png

Add a display name and the email ID which is associated with your Facebook Business Account. Click on Create App ID

You will be redirected to Add a Product page. Scroll in the list and find Marketing API. Click on Set Up.

mceclip3.png

A dashboard will open with Marketing API added in Product Section. 

Screenshot_2019-10-29_at_6.59.00_PM.png

Click on Tools under Marketing API. 

 

From the list, choose ads_management ; ads_read . Click on Get Token

7.png

Make sure to copy the token and save it as you won't be able to retrieve it later. 

 

Link your App to your Ad Account

In the Marketing API, go to Settings

Screenshot_2019-10-29_at_6.59.00_PM.png

Select your Ad-account Id in the dropdown present in Business Manager heading.

mceclip4.png

 

Getting Ad Account ID 

Go to https://developers.facebook.com/ to add an ad account. 

On the top right hand side, click on mceclip6.png

Business Settings page will open. On the left menu, under Accounts, click on Ad Accounts.

mceclip0.png

One more pane will open with Ad accounts heading. Click on Add button next to it. 

Add will show 3 options. Click on the first one - Add an ad account

 

It will open a new pop-up: Add an ad account.  Enter your Ad account ID and click on Add an ad account button on the bottom right of this pop-up. 

mceclip1.png

To know your Ad Account ID, go to https://business.facebook.com/home. If you have multiple business accounts select the one you wish to use. On the Home screen, you should be able to see Ad Accounts section. The ID is present right beneath the Account name. 

 

Now you need to share two things with us:

  • Ad Account Id
  • Access token

 

Post Setup

Once the basic setup is done, you can start creating the audience (For initial few days, you should only send around 1k-2k request per day with a request per minute rate of 300)

 To create Connector Campaign, please ensure that:

  • You have Ad Account Id & Access Token

 

Create Blank Audience

You can use any API tools (like Postman) to create a blank audience on Facebook. You need to have account id and access token with you.

You need to post to URL: https://graph.facebook.com/v5.0/act_12345678912345678/customaudiences where 12345678912345678 is your Ad Account Id. Replace it before hitting the URL. Here is a sample snapshot of the API request that can be made via Postman

Additionally, put the following keys in the BODY

name: MOE_SampleAudience

subtype: CUSTOM

description: any_audiencedescription 

access_token: EAAHZCclz4YJABAEHvW2f4WWpoRfuQsYEEXS7ZBG4Nmg2jfXdWpqt69LR5VjrJRwy9ZBpvYs19uIhT4SjZAixeEUIA7UESQeTNXMSGJLkxLjZCI1In7mqdZBVd8PT4UdV8jkUQFoWoyqUUwDu5PUDk46sxjCI8gBCRcqesVieHKZBCZB7CZCiVmFtq

customer_file_source: USER_PROVIDED_ONLY

mceclip0.png

Once API request is successful, you will get an audience id like 6095029787986 or 6073172490567 or any similar values in API response.

21.png

 

Add User to FB Audience

Allows you to add users blank FB Audience created above. You would need to create a connector campaign to add users to your FB audience as per steps mentioned below:

Step 1

Choose your targeting criteria and addition type - batch or triggered 

Step 2

Webhook URL:

https://graph.facebook.com/v5.0/6073172490567/users  where 6073172490567 is the blank audience Id, generated in the step above.

22.png

Request Type:

POST

Headers: 

Content-Type - application/json

23.png

Body:

Use the body type as JSON. In JSON Body, we will use two K-V pairs:

Key 1:

Key Name: access_token
Key Value: Access token that you saved above

Key 2:

Key Name:  payload 

Key Value: { "schema": "MOBILE_ADVERTISER_ID",      "data": [ "04b4c1ac-8d3c-451d-8d8e-c3fff2e89274"      ] }

In place of 04b4c1ac-8d3c-451d-8d8e-c3fff2e89274, choose the attribute having Google Advertiser Id or IDFA for your customers. You can find the attribute using @ .

Currently we support matching only by Mobile Advertiser Id.

24.png

Step 3

To save making duplicate calls, use attribute using Google Advertiser Id as De-dup key.

 25.png 

Limit your requests to 100-500 requests per minute (rpm) as Facebook throttles high throughput for new integrations.

26.png

Note: To remove (Delete) users from FB audience once they have achieved the conversion goal, create another Connector Campaign as mentioned below.

DELETE User from FB Audience

Allows you to remove users that have been added to FB Audience. To delete, create another Connector Campaign as per the steps below.

Step 1

Choose your targeting criteria and deletion send type - at once or triggered

Step 2

 Webhook URL

https://graph.facebook.com/v3.1/6073172490567/users  where 6073172490567 is the audience Id from which the user has to be deleted

27.png

Request Type

DELETE

BODY

Use the body type as JSON Data. In Json, we use two Key-Value pairs as mentioned below. 

Key 1:

Key Name: access_token
Key Value: Access token that you saved here

Key 2:

Key Name:  payload 

Key Value: { "schema": "MOBILE_ADVERTISER_ID",      "data": [ "04b4c1ac-8d3c-451d-8d8e-c3fff2e89274"      ] }

In place of 04b4c1ac-8d3c-451d-8d8e-c3fff2e89274, choose the attribute having Google Advertiser Id or IDFA for your customers. You can find the attribute using @ .

 28.png

Step 3

To save making duplicate calls, use attribute using Google Advertiser Id as De-dup key.

29.png

Limit your requests to 100-500 requests per minute (rpm) as Facebook throttles high throughput for new integrations.

30.png

Was this article helpful?
3 out of 3 found this helpful