Create Facebook Custom Audience for website Traffic

这一生的挚爱 提交于 2019-12-11 11:52:28

问题


I'm trying to create custom audience for web-traffic using the marketing API (Facebook Ads SDK 2.5).

This is what I tried.

$audience = new CustomAudience(null, 'act_'.$account_id);
$aud_data = array(
  CustomAudienceFields::NAME => $name,
  CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::CUSTOM,
  CustomAudienceFields::RULE => array('event' => array('i_contains' => 'ViewContent','i_contains' => $name ) ),
  CustomAudienceFields::PIXEL_ID => $pixelId,
  CustomAUdienceFields::DESCRIPTION => '',
  CustomAudienceFields::RETENTION_DAYS => 180,
  CustomAudienceFields::PREFILL => True
);

I'm getting a success message & I can see the audience on Ads Manager too. But, the problem is, when I try edit those audience, I'm getting this error.

Can't Edit Audience
This audience can't be edited because it was created using settings that are no longer available. You can still use this audience for your ads. To make changes or updates, create a new audience.

What am I doing wrong?


回答1:


If anyone has the same question, here's the answer.

The CustomAudienceFields::RULE should be a JSON string not an array (at least, that is what worked for me.)

So, putting it together..

$audience = new CustomAudience(null, 'act_'.$account_id);
$aud_data = array(
  CustomAudienceFields::NAME => $name,
  CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::CUSTOM,
  CustomAudienceFields::RULE => '{"and": [{"event": {"i_contains": "ViewContent"}},{"content_name": {"i_contains": "'.$name.'"}}]}',
  CustomAudienceFields::PIXEL_ID => $pixelId,
  CustomAUdienceFields::DESCRIPTION => '',
  CustomAudienceFields::RETENTION_DAYS => 180,
  CustomAudienceFields::PREFILL => True
);

This should work.



来源:https://stackoverflow.com/questions/37289544/create-facebook-custom-audience-for-website-traffic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!