लेबल

लेबल की मदद से अपने कैंपेन, विज्ञापन ग्रुप, विज्ञापन, और कीवर्ड को कैटगरी में बांटा जा सकता है. साथ ही, इन कैटगरी का इस्तेमाल करके, अपने वर्कफ़्लो को कई तरीकों से आसान बनाया जा सकता है.

इस गाइड में, ये काम करने के लिए ज़रूरी चरणों के बारे में बताया गया है:

  • प्रोग्राम के ज़रिए लेबल बनाना LabelService.
  • अपने कैंपेन को लेबल असाइन करने के लिए CampaignLabelService अनुरोधों का इस्तेमाल करना.
  • GoogleAdsServiceक्वेरी का इस्तेमाल करके, लेबल के हिसाब से रिपोर्ट के नतीजे पाना और उन्हें फ़िल्टर करना.

इस गाइड में कैंपेन पर फ़ोकस किया गया है. हालांकि, विज्ञापन ग्रुप, विज्ञापन, और कीवर्ड के लिए भी इसी तरीके का इस्तेमाल किया जा सकता है. इस एपीआई में CustomerLabelService भी शामिल है. इसकी मदद से, मैनेजर खाते, चाइल्ड खातों को लेबल असाइन कर सकते हैं.

इस्तेमाल के उदाहरण

लेबल इस्तेमाल करने की सामान्य स्थितियों में ये शामिल हैं:

  • आपके खाते में ऐसे कैंपेन हैं जिन्हें साल के कुछ खास समय में ही चालू किया जाता है. आपको इन कैंपेन को रिपोर्ट में शामिल या बाहर रखना है.
  • आपने अपने विज्ञापन ग्रुप में कीवर्ड का नया सेट जोड़ा है और आपको अपने विज्ञापन ग्रुप में मौजूद अन्य कीवर्ड के मुकाबले, इनके आंकड़े देखने हैं.
  • आपके Google Ads खाते के उपयोगकर्ता, कैंपेन के सबसेट को मैनेज करते हैं. आपको हर उपयोगकर्ता के लिए कैंपेन के सेट की पहचान करनी है.
  • आपके ऐप्लिकेशन को कुछ ऑब्जेक्ट की स्थिति मार्क करनी है.

लेबल बनाएं

`Label` ऑब्जेक्ट का इस्तेमाल करके लेबल बनाएं. इसके लिए, इसका text_label फ़ील्ड सेट करें:

  1. TextLabel इंस्टेंस बनाएं जिसमें बैकग्राउंड का रंग और जानकारी हो.
  2. एक Label इंस्टेंस बनाएं और इसके text_label फ़ील्ड को TextLabel असाइन करें.
  3. Label को LabelOperation (create) में रैप करें और इसे LabelService.MutateLabels पर भेजें.

बनाए गए लेबल का आईडी नोट करें, ताकि इसे बाद की क्वेरी में इस्तेमाल किया जा सके. आईडी, MutateLabelsResponse में दिखाए गए MutateLabelResult के resource_name फ़ील्ड में एम्बेड होता है.

लेबल आईडी और संसाधन के नाम पाने के लिए, GoogleAdsService Search या SearchStream अनुरोध का इस्तेमाल भी किया जा सकता है.

लेबल असाइन करें

अपने कैंपेन, ग्राहकों, विज्ञापन ग्रुप, शर्तों या विज्ञापनों को लेबल असाइन किए जा सकते हैं. इसके लिए, संबंधित सेवा में Mutate कार्रवाई का इस्तेमाल करें.

उदाहरण के लिए, किसी कैंपेन को लेबल असाइन करने के लिए, एक या उससे ज़्यादा CampaignLabelOperation ऑब्जेक्ट को CampaignLabelService.MutateCampaignLabels पर पास करें. हर CampaignLabelOperation में एक CampaignLabel इंस्टेंस शामिल होता है. इसके लिए, इन फ़ील्ड में संसाधन के पूरे नाम की ज़रूरत होती है:

  • label: किसी लेबल का संसाधन नाम. उदाहरण के लिए, customers/{customer_id}/labels/{label_id}.
  • campaign: किसी कैंपेन का संसाधन नाम. उदाहरण के लिए, customers/{customer_id}/campaigns/{campaign_id}).

हर लेबल-कैंपेन पेयर के लिए, CampaignLabel इंस्टेंस बनाएं. इसे create कार्रवाई के साथ CampaignLabelOperation में रैप करें और इसे CampaignLabelService.MutateCampaignLabels पर भेजें.

कैंपेन में लेबल जोड़ना

यहां एक कोड का उदाहरण दिया गया है. इसमें दिखाया गया है कि कैंपेन की सूची में कैंपेन का लेबल कैसे जोड़ा जाता है:

Java

private void runExample(
    GoogleAdsClient googleAdsClient, long customerId, List<Long> campaignIds, Long labelId) {
  // Gets the resource name of the label to be added across all given campaigns.
  String labelResourceName = ResourceNames.label(customerId, labelId);

  List<CampaignLabelOperation> operations = new ArrayList<>(campaignIds.size());
  // Creates a campaign label operation for each campaign.
  for (Long campaignId : campaignIds) {
    // Gets the resource name of the given campaign.
    String campaignResourceName = ResourceNames.campaign(customerId, campaignId);
    // Creates the campaign label.
    CampaignLabel campaignLabel =
        CampaignLabel.newBuilder()
            .setCampaign(campaignResourceName)
            .setLabel(labelResourceName)
            .build();

    operations.add(CampaignLabelOperation.newBuilder().setCreate(campaignLabel).build());
  }

  try (CampaignLabelServiceClient campaignLabelServiceClient =
      googleAdsClient.getLatestVersion().createCampaignLabelServiceClient()) {
    MutateCampaignLabelsResponse response =
        campaignLabelServiceClient.mutateCampaignLabels(Long.toString(customerId), operations);
    System.out.printf("Added %d campaign labels:%n", response.getResultsCount());
    for (MutateCampaignLabelResult result : response.getResultsList()) {
      System.out.println(result.getResourceName());
    }
  }
}
      

C#

public void Run(GoogleAdsClient client, long customerId, long[] campaignIds, long labelId)
{
    // Get the CampaignLabelServiceClient.
    CampaignLabelServiceClient campaignLabelService =
        client.GetService(Services.V25.CampaignLabelService);

    // Gets the resource name of the label to be added across all given campaigns.
    string labelResourceName = ResourceNames.Label(customerId, labelId);

    List<CampaignLabelOperation> operations = new List<CampaignLabelOperation>();
    // Creates a campaign label operation for each campaign.
    foreach (long campaignId in campaignIds)
    {
        // Gets the resource name of the given campaign.
        string campaignResourceName = ResourceNames.Campaign(customerId, campaignId);
        // Creates the campaign label.
        CampaignLabel campaignLabel = new CampaignLabel()
        {
            Campaign = campaignResourceName,
            Label = labelResourceName
        };

        operations.Add(new CampaignLabelOperation()
        {
            Create = campaignLabel
        });
    }

    // Send the operation in a mutate request.
    try
    {
        MutateCampaignLabelsResponse response =
            campaignLabelService.MutateCampaignLabels(customerId.ToString(), operations);
        Console.WriteLine($"Added {response.Results} campaign labels:");

        foreach (MutateCampaignLabelResult result in response.Results)
        {
            Console.WriteLine(result.ResourceName);
        }
    }
    catch (GoogleAdsException e)
    {
        Console.WriteLine("Failure:");
        Console.WriteLine($"Message: {e.Message}");
        Console.WriteLine($"Failure: {e.Failure}");
        Console.WriteLine($"Request ID: {e.RequestId}");
        throw;
    }
}
      

PHP

    public static function runExample(
        GoogleAdsClient $googleAdsClient,
        int $customerId,
        array $campaignIds,
        int $labelId
    ) {
        // Gets the resource name of the label to be added across all given campaigns.
        $labelResourceName = ResourceNames::forLabel($customerId, $labelId);

        // Creates a campaign label operation for each campaign.
        $operations = [];
        foreach ($campaignIds as $campaignId) {
            // Creates the campaign label.
            $campaignLabel = new CampaignLabel(
                [
                'campaign' => ResourceNames::forCampaign($customerId, $campaignId),
                'label' => $labelResourceName
                ]
            );
            $campaignLabelOperation = new CampaignLabelOperation();
            $campaignLabelOperation->setCreate($campaignLabel);
            $operations[] = $campaignLabelOperation;
        }

        // Issues a mutate request to add the labels to the campaigns.
        $campaignLabelServiceClient = $googleAdsClient->getCampaignLabelServiceClient();
        $response = $campaignLabelServiceClient->mutateCampaignLabels(
            MutateCampaignLabelsRequest::build($customerId, $operations)
        );

        printf("Added %d campaign labels:%s", $response->getResults()->count(), PHP_EOL);

        foreach ($response->getResults() as $addedCampaignLabel) {
            /**
 * @var CampaignLabel $addedCampaignLabel
*/
            printf(
                "New campaign label added with resource name: '%s'.%s",
                $addedCampaignLabel->getResourceName(),
                PHP_EOL
            );
        }
    }
      

Python

def main(
    client: GoogleAdsClient,
    customer_id: str,
    label_id: str,
    campaign_ids: List[str],
) -> None:
    """This code example adds a campaign label to a list of campaigns.

    Args:
        client: An initialized GoogleAdsClient instance.
        customer_id: A client customer ID str.
        label_id: The ID of the label to attach to campaigns.
        campaign_ids: A list of campaign IDs to which the label will be added.
    """

    # Get an instance of CampaignLabelService client.
    campaign_label_service: CampaignLabelServiceClient = client.get_service(
        "CampaignLabelService"
    )
    campaign_service: CampaignServiceClient = client.get_service(
        "CampaignService"
    )
    label_service: LabelServiceClient = client.get_service("LabelService")

    # Build the resource name of the label to be added across the campaigns.
    label_resource_name: str = label_service.label_path(customer_id, label_id)

    operations: List[Any] = []

    for campaign_id in campaign_ids:
        campaign_resource_name: str = campaign_service.campaign_path(
            customer_id, campaign_id
        )
        campaign_label_operation: Any = client.get_type(
            "CampaignLabelOperation"
        )

        campaign_label: CampaignLabel = campaign_label_operation.create
        campaign_label.campaign = campaign_resource_name
        campaign_label.label = label_resource_name
        operations.append(campaign_label_operation)

    response: MutateCampaignLabelsResponse = (
        campaign_label_service.mutate_campaign_labels(
            customer_id=customer_id, operations=operations
        )
    )
    print(f"Added {len(response.results)} campaign labels:")
    for result in response.results:
        print(result.resource_name)
      

Ruby

def add_campaign_label(customer_id, label_id, campaign_ids)
  # GoogleAdsClient will read a config file from
  # ENV['HOME']/google_ads_config.rb when called without parameters
  client = Google::Ads::GoogleAds::GoogleAdsClient.new

  label_resource_name = client.path.label(customer_id, label_id)

  labels = campaign_ids.map { |campaign_id|
    client.resource.campaign_label do |label|
      campaign_resource_name = client.path.campaign(customer_id, campaign_id)
      label.campaign = campaign_resource_name
      label.label = label_resource_name
    end
  }

  ops = labels.map { |label|
    client.operation.create_resource.campaign_label(label)
  }

  response = client.service.campaign_label.mutate_campaign_labels(
    customer_id: customer_id,
    operations: ops,
  )
  response.results.each do |result|
    puts("Created campaign label with id: #{result.resource_name}")
  end
end
      

Perl

sub add_campaign_labels {
  my ($api_client, $customer_id, $campaign_ids, $label_id) = @_;

  my $label_resource_name =
    Google::Ads::GoogleAds::V25::Utils::ResourceNames::label($customer_id,
    $label_id);

  my $campaign_label_operations = [];

  # Create a campaign label operation for each campaign.
  foreach my $campaign_id (@$campaign_ids) {
    # Create a campaign label.
    my $campaign_label =
      Google::Ads::GoogleAds::V25::Resources::CampaignLabel->new({
        campaign => Google::Ads::GoogleAds::V25::Utils::ResourceNames::campaign(
          $customer_id, $campaign_id
        ),
        label => $label_resource_name
      });

    # Create a campaign label operation.
    my $campaign_label_operation =
      Google::Ads::GoogleAds::V25::Services::CampaignLabelService::CampaignLabelOperation
      ->new({
        create => $campaign_label
      });

    push @$campaign_label_operations, $campaign_label_operation;
  }

  # Add the campaign labels to the campaigns.
  my $campaign_labels_response = $api_client->CampaignLabelService()->mutate({
    customerId => $customer_id,
    operations => $campaign_label_operations
  });

  my $campaign_label_results = $campaign_labels_response->{results};
  printf "Added %d campaign labels:\n", scalar @$campaign_label_results;

  foreach my $campaign_label_result (@$campaign_label_results) {
    printf "Created campaign label '%s'.\n",
      $campaign_label_result->{resourceName};
  }

  return 1;
}
      

curl

ग्राहकों को लेबल असाइन करना

मैनेजर खातों के लिए, अपने क्लाइंट खातों को कैटगरी में बांटने के लिए, ग्राहकों को लेबल असाइन करना एक सामान्य काम है. यह काम CustomerLabelService का इस्तेमाल करके किया जाता है. मैनेजर खाते से बनाए गए लेबल का मालिकाना हक उसी मैनेजर खाते के पास होता है. ये लेबल सिर्फ़ तब दिखते हैं, जब मालिकाना हक वाले मैनेजर खाते के तौर पर पुष्टि की गई हो.

हर CustomerLabelOperation में एक CustomerLabel इंस्टेंस शामिल होता है. ग्राहक-लेबल के बीच संबंध बनाते समय, इन बातों का ध्यान रखें:

  • label: यह फ़ील्ड ज़रूरी है. इसमें मैनेजर खाते के मालिकाना हक वाले लेबल का संसाधन नाम होना चाहिए. जैसे, customers/{MANAGER_ID}/labels/{LABEL_ID}.
  • customer: यह फ़ील्ड सिर्फ़ आउटपुट के लिए है. इसे अनुरोध में सेट नहीं किया जाना चाहिए. जिस ग्राहक को लेबल किया जा रहा है उसकी पहचान, MutateCustomerLabelsRequest पाथ में मौजूद customer_id से होती है.

लेबल का इस्तेमाल करके ऑब्जेक्ट पाना

अपने कैंपेन को लेबल असाइन करने के बाद, आईडी के हिसाब से ऑब्जेक्ट पाने के लिए, लेबल वाले फ़ील्ड का इस्तेमाल किया जा सकता है.

GAQL की सही क्वेरी, GoogleAdsService या SearchSearchStream अनुरोध में पास करें. उदाहरण के लिए, यहां दी गई क्वेरी, तीन लेबल आईडी में से किसी एक से जुड़े हर कैंपेन का आईडी, नाम, और लेबल दिखाती है:

SELECT
  campaign.id,
  campaign.name,
  label.id,
  label.name
FROM campaign_label
WHERE label.id IN (123456, 789012, 345678)

सिर्फ़ लेबल आईडी के हिसाब से फ़िल्टर किया जा सकता है, लेबल के नाम के हिसाब से नहीं. लेबल के नाम से लेबल आईडी पाने के लिए, यह क्वेरी इस्तेमाल करें:

SELECT
  label.id,
  label.name
FROM label
WHERE label.name = "LABEL_NAME"

किसी ग्राहक पर लागू किए गए लेबल पाना

मैनेजर खाते के तहत आने वाले खातों का क्रम पाने के लिए, चाइल्ड ग्राहक खाते पर लागू किए गए लेबल की सूची पाई जा सकती है. इसके लिए, applied_labels फ़ील्ड का अनुरोध करें CustomerClient ऑब्जेक्ट से. इस फ़ील्ड से सिर्फ़ वे लेबल मिलते हैं जिनका मालिकाना हक, एपीआई कॉल करने वाले ग्राहक के पास होता है.

रिपोर्ट में लेबल का इस्तेमाल करना

अपनी रिपोर्ट को ज़्यादा काम का बनाने के लिए, लेबल का इस्तेमाल करें.

लेबल की रिपोर्टिंग

लेबल की रिपोर्ट के संसाधन से, किसी खाते में तय किए गए लेबल के बारे में जानकारी मिलती है. जानकारी में नाम, आईडी, संसाधन का नाम, स्थिति, बैकग्राउंड का रंग, और जानकारी शामिल होती है. साथ ही, इसमें ग्राहक का वह संसाधन भी शामिल होता है जो लेबल के मालिक को दिखाता है.

मेट्रिक वाली रिपोर्ट

विज्ञापन ग्रुप और कैंपेन की रिपोर्ट के व्यू में, labels फ़ील्ड शामिल होता है. रिपोर्टिंग सेवा, लेबल के संसाधन के नाम को customers/{customer_id}/labels/{label_id} फ़ॉर्मैट में दिखाती है. उदाहरण के लिए, संसाधन का नाम customers/123456789/labels/012345 आईडी 123456789 वाले खाते में, आईडी 012345 वाले लेबल को दिखाता है.

बिना मेट्रिक वाली रिपोर्ट

संसाधनों और लेबल के बीच संबंध ढूंढने के लिए, रिपोर्ट के इन संसाधनों का इस्तेमाल किया जा सकता है:

रिपोर्ट के इन नतीजों को फ़िल्टर करने के लिए, label.id फ़ील्ड की तुलना, किसी भी संख्या की तुलना करने वाले ऑपरेटर या BETWEEN, IS NULL, IS NOT NULL, IN, या NOT IN ऑपरेटर का इस्तेमाल करके की जा सकती है.

इस उदाहरण में, किसी खास लेबल आईडी वाले सभी कैंपेन पाए जा सकते हैं:

SELECT
  campaign.id,
  campaign.name,
  label.id,
  label.name
FROM campaign_label
WHERE label.id = LABEL_ID
ORDER BY campaign.id