facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.32k stars 645 forks source link

Where do I get the placement and site_source_name values in the SDK? #671

Open edpruuv opened 5 months ago

edpruuv commented 5 months ago

Given this url tag placement={{placement}} site_source_name={{site_source_name}}

Where do I get these values using the SDK?

Which specific field in the following to they belong?

Campaign.Field AdSet.Field Ad.Field

I tried the following:

`

CAMPAIGN_FIELDS = [ Campaign.Field.account_id, Campaign.Field.id, Campaign.Field.name, Campaign.Field.budget_remaining, Campaign.Field.objective, ] connection = AdAccount(customer_id)

params = {

        "breakdowns": [
            "impression_device",
            "publisher_platform",
            "device_platforms",
            "platform_position",
        ],
    }

campaigns = connection.get_campaigns(fields=fields, params=params)

`

But all I get is this output:

{ "account_id": "1**705********1241", "budget_remaining": "0", "id": "120208422448000423", "name": "Creative and Audience Test", "objective": "OUTCOME_LEADS" }

Should I go for the Adset or Ad level?

Please help!

Just1B commented 5 months ago

Hi @edpruuv 👋

When you run, your example below -> you are requesting the endpoint {ad-account-id}/campaigns

https://developers.facebook.com/docs/marketing-api/reference/ad-campaign-group/#fields

connection = AdAccount(customer_id)

campaigns = connection.get_campaigns(fields=fields, params=params)

I think you misunderstood the breakdowns parts witch is related to the insights

🛑 All breakdowns are not always compatible with each others ( combining breakdowns )


# {ad-account-id}/insights

account = AdAccount("act_" + self.account_id)

insights = account.get_insights(
    fields= [ "account_id", .... , "clicks", "impressions", "spend" ... ]
    params={
        "use_unified_attribution_setting": True,
        "breakdowns": [
            "publisher_platform",
            "platform_position",
            "impression_device",
        ],
        "level": "ad",
        "time_increment": 1,
        "time_range": {
            "since": XYZ,
            "until": XYZ,
        },
    },
    is_async=True,
)

insights.api_get()
edpruuv commented 5 months ago

Thanks a ton @Just1B !

I will try this now. This is my first time working with facebook marketing api.

Your comment is greatly appreciated! I'll give a feedback once I tried it out.

Cheers!

edpruuv commented 5 months ago

I got the folowing insight data @Just1B

insight_data = {'ad_id': '2386******17828250422', 'ad_name': 'A***', 'adset_id': '238622**', 'campaign_id': '238**21**260422', 'clicks': '0', 'cpm': '0', 'ctr': '0', 'date_start': '2024-06-07', 'date_stop': '2024-06-07', 'impression_device': 'iphone', 'impressions': '1', 'platform_position': 'search', 'publisher_platform': 'facebook', 'spend': '0'}

My next(and main) question is what breakdown parameter should I pass to get the value of these dynamic variables in the url tag:

{{placement}}

{{site_source_name}}

image

Specifications for URL dynamic parameters link: https://www.facebook.com/business/help/2360940870872492

What am I missing here?

P.S. You're response is greatly appreciated

Just1B commented 5 months ago

i think you can get them on the adcreative

https://developers.facebook.com/docs/instagram/ads-api/guides/get-ad-insights/

Capture d’écran 2024-06-07 à 12 04 23

https://developers.facebook.com/docs/marketing-api/reference/ad-creative#fields

Capture d’écran 2024-06-07 à 12 07 26

edpruuv commented 5 months ago

We already have url_tags but the dynamic url parameters are not being replaced automatically

utm_source=facebook&utm_medium={{site_source_name}}&utm_campaign={{placement}}&utm_content={{ad.id}}

That's why I need to find where I can get the site_source_name and placement value

Please advice.

Thank you

image

fernando-heitor commented 1 month ago

Hey @edpruuv how's it going?

Were you able to find any solution to this problem? I'm facing the same issue that you mentioned