skip to Main Content

When we create a Custom Conversion with FB Graph API, we can define the event name param. I’m trying to find how can I get first my Custom Events, and then select some custom event to parse to event name.
How can I do it?
Take a look at Custom Conversions docs: https://developers.facebook.com/docs/marketing-api/reference/custom-conversion/v17.0

2

Answers


  1. Chosen as BEST ANSWER

    My own solution: I used the Ads Pixel Stats endpoint, that you can see here: https://developers.facebook.com/docs/marketing-api/reference/ads-pixel/stats/v17.0

    Basically, I made a request to /{ads-pixel-id}/stats endpoint by passing the aggregation param with event_total_counts value:

    https://graph.facebook.com/v17.0/{ads-pixel-id}/stats?aggregation=event_total_counts

    That will returns a list of active events (custom and standard) for the pixel with a count of occurrences. Do you can also parse another params, as you can see in the documentation above.


  2. To retrieve your Custom Conversions and select specific events to parse the event name, you can use the Facebook Marketing API. Here’s how you can do it using Python and the requests library:

    1. Get Your Custom Conversions:

    First, you need to make a GET request to retrieve your Custom Conversions. You will need to provide your Access Token and Ad Account ID in the request URL.

    import requests

    access_token = 'YOUR_ACCESS_TOKEN'
    ad_account_id = 'YOUR_AD_ACCOUNT_ID'
    
    url = f'https://graph.facebook.com/v17.0/{ad_account_id}/customconversions'
    params = {
        'access_token': access_token
    }
    
    response = requests.get(url, params=params)
    custom_conversions = response.json()
    

    This will give you a list of your Custom Conversions, including the event names associated with each conversion.

    1. Select Specific Custom Event and Parse Event Name:

    Now that you have the list of Custom Conversions, you can select a specific conversion and parse the event name. Let’s say you want to select the first Custom Conversion:

    if ‘data’ in custom_conversions and len(custom_conversions[‘data’]) >
    0:
    selected_conversion = custom_conversions[‘data’][0]
    event_name = selected_conversion.get(‘event_name’, ”)
    print(f’Selected Event Name: {event_name}’) else:
    print(‘No Custom Conversions found.’)

    In this example, event_name contains the name of the selected Custom Conversion event.

    Make sure to handle errors and edge cases appropriately in your code, and also consider pagination if you have a large number of Custom Conversions.

    Please note that you need to have the necessary permissions and a valid Access Token to access your Custom Conversions data through the Facebook Marketing API.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search