Create optimized Facebook Ads targeted at the right audience. With Profiles API and Segments, you can make a list of visitors who already access your website or are registered on your website and then send optimized Facebook Ads to them.

What’s the difference between this integration and Writing Job Results into Facebook Custom Audience?

Using Facebook Custom Audience requires user identifier information, for example, email or phone number. Profiles API integration enables you to send a segment to Facebook Custom Audience without such parameters. Instead, you use Facebook Pixel.


Prerequisites

  • Basic knowledge of Treasure Data

  • Account of Facebook Business Account

Integrating TD Profiles API with Facebook using Pixel IDs

  1. Navigate to Audience Studio > Profiles API Tokens.


  2. Click New Token.

  3. Complete the fields to configure the API token, including specifying a key column and the segments of customers to which you want to apply a personalization. Choose a key column, which is required to lookup a segment. In this example, td_global_id is selected. And, register a segment that you want to use with Profiles API. If the key you selected is associated with a segment, Profiles API returns the segment ID.


  4. Save your token.

Get Facebook Pixel ID

Your Facebook Pixel ID is retrieved on your Facebook Business Account.
Refer to https://www.facebook.com/business/help/952192354843755

Setup Javascript on your website

Facebook Javascript Tag

Integrate Facebook Javascript Tag with your website. In the script, replace “YOUR_PIXEL_ID” with your pixel ID.

See more detail: https://developers.facebook.com/docs/facebook-pixel/implementation

Treasure Data Javascript SDK

We provide two versions of Javascript SDK. The version you use affect the response format of the fetchUserSegment function, which is used for this procedure. We recommend that you use Javascript SDK version 2.

Case v1.9.x

The fetchUserSegments function returns associated segment ids when a visitor accesses your website. Adding the segment ids into the fbq function with trackCustom parameter will send them to Facebook.

The parameters in the fbq function require; (1): Event Name (any), (2): Column name on Facebook (any), (3): Segment ID from the fetchUserSegment function

<script type="text/javascript">
var td = new Treasure({
  ...
});

var successCallback = function (key, segments) {
  // send to FB
  fbq('trackCustom','event_tracking',{'td_segment_id': segments.join(',')});  // fbq('trackCustom','(1)',{'(2)': (3)});
};

td.fetchUserSegments({
  audienceToken: [token1, token2],
  keys: {some_key: 'value'}
}, successCallback);
</script>

Case v2.x.x

Because JS SDK v2 or later returns a difference response format from v1.9 or earlier, you must extract only segment ids from the fetchUserSegments function in an additional logic step. Then, you add the segment ids into the fbq function using the trackCustom parameter to send the ids to Facebook.

The parameters in fbq function requires; (1): Event Name (any), (2): Column name on Facebook (any), (3): Segment ID from the fetchUserSegment function

<script type="text/javascript">
var td = new Treasure({
  ...
});
 
function sendSegmentId2Fb(seg) {
  var segIdAll = [];
  for (var i = 0; i < seg.length; i++) {
    segIdAll = segIdAll.concat(seg[i].values);
  };
  var segId = segIdAll.filter(function (x,i,self) {return self.indexOf(x) === i;});
 
  // send to FB
  fbq('trackCustom','event_tracking',{'td_segment_id': segId.join(',')});  // fbq('trackCustom','(1)',{'(2)': (3)});
};
 
var successCallback = function(values) {
  sendSegmentId2Fb(values);
};
 
td.fetchUserSegments({
  audienceToken: [token1, token2],
  keys: {some_key: 'value'}
}, successCallback);
</script>

Confirm integration Status

After the Javascript integration is triggered, you can see the status of data integration on Facebook Business Account page.

  1. Go to the Pixels in Events Manager section


  2. Choose a pixel you integrated


  3. Click Activity Menu, and then see the tracking target name you called using the fbq function


Create Custom Audience

After the data is stored on the Facebook side, you can create a custom audience by using the data.

  1. Go to Event Managers and click Pixels.


  2. Select your pixel.


  3. Click Create Custom Audience.


  4. Choose conditions for which you want to send ads

    1. Select an event name

    2. Select a condition (Ex. td_segment_id contains <segment id>)

    3. Set your custom audience name.


  5. Finally, you can see the status of your custom audience.



  • No labels