Assistance Needed: Conversion Goals Not Applying to Campaigns via Google Ads API

66 views
Skip to first unread message

dhrutish ramoliya

unread,
Mar 6, 2025, 7:12:15 AM3/6/25
to Google Ads API and AdWords API Forum

Hello Google Ads API Support Team,

I am currently facing an issue with setting up Conversion Goals for my Google Ads campaigns via the API. While I am able to create campaigns successfully and associate conversion goals, the selected goals are not applying properly. I would appreciate your assistance in identifying where I might be going wrong and how I can fix this.

🔹 Issue Details:

  1. Conversion Goals in Use: Below is the list of conversion goals that I am currently implementing in my API requests:
    [
        { "category": "BEGIN_CHECKOUT", "origin": "GOOGLE_HOSTED", "biddable": true, "objectives": ["LEADS", "WEBSITE_TRAFFIC", "SALES"] },
        { "category": "CONTACT", "origin": "GOOGLE_HOSTED", "biddable": false, "objectives": ["LEADS", "WEBSITE_TRAFFIC", "SALES"] },
        { "category": "ENGAGEMENT", "origin": "GOOGLE_HOSTED", "biddable": false, "objectives": ["LEADS", "WEBSITE_TRAFFIC", "SALES"] },
        { "category": "GET_DIRECTIONS", "origin": "GOOGLE_HOSTED", "biddable": false, "objectives": ["LEADS", "WEBSITE_TRAFFIC", "SALES"] },      
        { "category": "PAGE_VIEW", "origin": "GOOGLE_HOSTED", "biddable": false, "objectives": ["LEADS", "WEBSITE_TRAFFIC", "SALES"] },
        { "category": "SIGNUP", "origin": "GOOGLE_HOSTED", "biddable": false, "objectives": ["LEADS", "WEBSITE_TRAFFIC", "SALES"] },
        { "category": "PURCHASE", "origin": "WEBSITE", "biddable": false, "objectives": ["LEADS", "WEBSITE_TRAFFIC", "SALES"] },
        { "category": "STORE_SALE", "origin": "STORE", "biddable": false, "objectives": ["LEADS", "WEBSITE_TRAFFIC", "SALES"] },  
        { "category": "STORE_VISIT", "origin": "STORE", "biddable": false, "objectives": ["LEADS", "WEBSITE_TRAFFIC", "SALES"] }
    ]

    2. Implementation Code Snippet: I am applying conversion goals using the following function:

    private function applyConversionGoals($googleAdsClient, $customerId, $campaignResourceName, $conversionGoals)
    {
        if (empty($conversionGoals)) {
            Log::warning("⚠️ No conversion goals provided for campaign: " . $campaignResourceName);
            return;
        }

        Log::info("🔍 Processing Conversion Goals: " . json_encode($conversionGoals));

        // Extract the campaign ID from the resource name
        $parts = explode('/', $campaignResourceName);
        $campaignId = end($parts);

        // Fetch existing conversion goals
        $query = sprintf(
            "SELECT
                campaign_conversion_goal.resource_name,
                campaign_conversion_goal.category,
                campaign_conversion_goal.origin,
                campaign_conversion_goal.biddable
            FROM campaign_conversion_goal
            WHERE campaign_conversion_goal.campaign = 'customers/%s/campaigns/%s'",
            $customerId,
            $campaignId
        );

        $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
        $searchRequest = new SearchGoogleAdsRequest([
            'customer_id' => $customerId,
            'query' => $query
        ]);

        $stream = $googleAdsServiceClient->search($searchRequest);
        $existingGoals = [];

        foreach ($stream->iterateAllElements() as $googleAdsRow) {
            $goal = $googleAdsRow->getCampaignConversionGoal();
            $existingGoals[$goal->getCategory()][$goal->getOrigin()] = [
                'resource_name' => $goal->getResourceName(),
                'biddable' => $goal->getBiddable()
            ];
        }

        Log::info("✅ Existing Conversion Goals: " . json_encode($existingGoals));

        $operations = [];
        $conversionOrigins = [
            'WEBSITE' => ConversionOrigin::WEBSITE,
            'GOOGLE_HOSTED' => ConversionOrigin::GOOGLE_HOSTED,
            'STORE' => ConversionOrigin::STORE,
            'YOUTUBE_HOSTED' => ConversionOrigin::YOUTUBE_HOSTED
        ];

        foreach ($conversionGoals as $goal) {
            if (!isset($goal['category']) || !isset($goal['origin'])) {
                Log::error("🚨 Missing category or origin in goal: " . json_encode($goal));
                continue;
            }

            $categoryKey = strtoupper($goal['category']);
            $originKey = strtoupper($goal['origin']);

            try {
                $categoryValue = constant("\Google\Ads\GoogleAds\V18\Enums\ConversionActionCategoryEnum\ConversionActionCategory::$categoryKey");
                $originValue = $conversionOrigins[$originKey] ?? null;

                if (!$originValue) {
                    Log::error("🚨 Invalid conversion origin: {$originKey}");
                    continue;
                }
            } catch (UnexpectedValueException $e) {
                Log::error("🚨 Invalid conversion category: " . json_encode($goal));
                continue;
            }

            $biddable = isset($goal['biddable']) ? filter_var($goal['biddable'], FILTER_VALIDATE_BOOLEAN) : false;

            if (!isset($existingGoals[$categoryValue][$originValue])) {
                Log::error("🚨 No exact match found for Conversion Goal: {$categoryKey} with origin: {$originKey}. Skipping.");
                continue;
            }

            $resourceName = $existingGoals[$categoryValue][$originValue]['resource_name'];

            try {
                $conversionGoal = new CampaignConversionGoal([
                    'resource_name' => $resourceName,
                    'biddable' => $biddable,
                ]);

                $operation = new CampaignConversionGoalOperation();
                $operation->setUpdate($conversionGoal);
                $operation->setUpdateMask(\Google\Ads\GoogleAds\Util\FieldMasks::allSetFieldsOf($conversionGoal));

                $operations[] = $operation;
            } catch (\Throwable $th) {
                Log::error("🔴 Error updating conversion goal for {$categoryKey}: " . $th->getMessage());
                throw new Exception($th->getMessage());
            }
        }

        if (empty($operations)) {
            Log::warning("⚠️ No valid Conversion Goal operations created for campaign: " . $campaignResourceName);
            return;
        }

        try {
            $mutateRequest = new MutateCampaignConversionGoalsRequest([
                'customer_id' => $customerId,
                'operations' => $operations,
            ]);

            $campaignConversionGoalServiceClient = $googleAdsClient->getCampaignConversionGoalServiceClient();
            $response = $campaignConversionGoalServiceClient->mutateCampaignConversionGoals($mutateRequest);

            Log::info("✅ Conversion Goals Updated Successfully: " . json_encode($response->getResults()));
        } catch (\Throwable $th) {
            Log::error("🚨 Google Ads API Error in Conversion Goals: " . $th->getMessage());
        }
    }


Issue Summary:
  • I am able to set up campaign-specific conversion goals, but when I select specific goals, they are not being applied properly.
  • Question: Am I using the correct conversion goal categories and origins?
  • What I need help with:
    1. Verifying whether my selected conversion goals align correctly with the campaign objectives.
    2. Understanding if there are API restrictions or best practices that I might be missing.
    3. Diagnosing why the goals are not being successfully applied even though the API call executes without errors.

Expected Behavior:
  - Selected conversion goals should be applied to the campaign
  - Conversion goals are not applied even when the request is successful
Actual Behavior:
  - API should return the campaign with updated goals
  - API response shows goals, but they are not reflected in the campaign

I would really appreciate your detailed guidance on this! Thank you in advance for your time and help. 😊🙏

Additional Information:
  • API Version: Google Ads API v18
  • Backend Framework: Laravel
  • Implementation Method: Google Ads PHP SDK
  • Campaign Type: Search Ads Campaigns

Google Ads API Forum Advisor

unread,
Mar 6, 2025, 11:04:41 AM3/6/25
to dhrutish...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for contacting the Google Ads API support team.

> Verifying whether my selected conversion goals align correctly with the campaign objectives.

Google Ads automatically creates CustomerConversionGoal objects. You can set the biddable attribute for each goal to determine whether it should be an account-default goal. Set biddable to true if Google Ads should optimize for conversion actions based on the goal's category and origin. Otherwise, set it to false. The values true and false correspond to the "Use as an account-default goal" and "Do not use as an account-default goal" options in the conversion action settings, respectively. I would recommend you to refer to this guide for more detailed information.

> Understanding if there are API restrictions or best practices that I might be missing.

There is no specific API restrictions on setting campaign - level conversion goals other than setting the 'biddable' field.

> Diagnosing why the goals are not being successfully applied even though the API call executes without errors.

I would recommend you to refer to Conversion goals documentation for complete goal management workflow.

 

Thanks,
 
Google Logo Google Ads API Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-03-06 16:03:35Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH6k9:ref" (ADR-00291977)



Reply all
Reply to author
Forward
0 new messages