javascriptgoogle-cloud-firestoregeolocationfacebook-nodejs-business-sdk

Facebook ad sdk returning 'Incorrect Location Format'


I'm using the node.js facebook sdk facebook-nodejs-business-sdk in a firebase function to update Ad Sets targeting parameter with the custom_locations and have tried many different ways to update it, but none have worked. I've used the object TargetingGeoLocationCustomLocation from the API and also tried adding the location as an object directly. I've also tried sending the latitude/longitude as a string, a float, a parseFloat string and none seem to have any effect. If I try it with no custom_locations, it goes through, so I don't think its anything to do with the setup of the API. Here's the last code I've attempted:

const adsSdk = require('facebook-nodejs-business-sdk');
const targeting = adset.targeting // Pulling a targeting object from the request
const customLoc = adsSdk.TargetingGeoLocationCustomLocation = {
                  radius: 1,
                  latitude: parseFloat(37.32798355),
                  longitude: parseFloat(-73.01982712),
                  distance_unit: 'mile'
                }
                const geoLocations = {
                  location_types: ['recent'],
                  custom_locations: [
                    customLoc
                  ]
                }
                targeting.geo_locations = geoLocations
                const accessToken = req.body.fbAuth;
                const api = adsSdk.FacebookAdsApi.init(accessToken);
                const AdSet = adsSdk.AdSet;
                
                new AdSet(doc.id, {
                  targeting: targeting
                })
                .update()
                .then( response => console.log('fb response', response) )
                .catch( error => console.log('error', error) )

I feel like I've tried everything and would really appreciate any advice or suggestions


Solution

  • From your code, it seems that nothing is wrong maybe post what you have on customLocations too in order to see which area's are you targeting since I know that you need to have a certain minimal people in your targeting zones.

    If your targeting audience is too small, for example a specific interest in a too small or little populated area, you cannot create the targeting.

    I would suggest you to try using other interests to broaden the audience and see if it still returns the same error. You can find in the documentation that some audience types require at least 20 people or more.