Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// FB curl example
// curl \
// -F 'pixel_id=<PIXEL_ID>' \
// -F 'name=My New Website Custom Audience' \
// -F 'subtype=WEBSITE' \
// -F 'retention_days=15' \
// -F 'rule={"url":{"i_contains":"shoes"}}' \
// -F 'prefill=1' \
// -F 'access_token=<ACCESS_TOKEN>' \
// https://graph.facebook.com/v2.7/act_<AD_ACCOUNT_ID>/customaudiences
(function(){
var req = new XMLHttpRequest();
var pathparts = window.location.pathname.split('/');
var endpath = pathparts[pathparts.length-1];
var kvps = [
{"pixel_id" : "<PIXEL_ID>"}
, {"name" : endpath}
, {"subtype" : "WEBSITE"}
, {"retention_days" : "15"}
, {"rule" : "{\"url\":{\"i_contains\":\"" + endpath + "\"}}"}
, {"prefill" : "1"}
, {"access_token" : "<ACCESS_TOKEN>"}
];
var toStrings = function(obj) {
return Object.keys(obj).map(function (key) {
return key + '=' + obj[key];
});
}
var toQuery = function(pv, cv, ci, arr) {
return pv + '&' + cv
}
var post = kvps.map(toStrings).reduce(toQuery);
req.open("POST", "https://graph.facebook.com/v2.7/act_<AD_ACCOUNT_ID>/customaudiences", true);
req.onreadystatechange = function () {
if (req.readyState != 4 || req.status != 200) return;
console.log("unable to post");
};
req.send(post);
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.