*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

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/adwords-api/7497c251-54a6-41f7-b430-71d5b82ff6c8n%40googlegroups.com.
  • As... dhrutish ramoliya
    • ... 'Google Ads API Forum Advisor' via Google Ads API and AdWords API Forum

Reply via email to