लेबल

लेबल की सहायता से आप अपने अभियानों, विज्ञापन समूहों, विज्ञापनों और कीवर्ड को वर्गीकृत कर सकते हैं और उन श्रेणियों का उपयोग करके अपने वर्कफ़्लो को कई तरीकों से आसान बना सकते हैं.

इस गाइड में, यहां दिए गए काम करने के तरीके बताए गए हैं:

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

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

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

लेबल का इस्तेमाल आम तौर पर, इन स्थितियों में किया जाता है:

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

लेबल बनाएं

TextLabel ऑब्जेक्ट वाले लेबल बनाएं:

  1. TextLabel इंस्टेंस बनाएं.
  2. इस TextLabel के लिए बैकग्राउंड का रंग सेट करें.
  3. ब्यौरे वाले फ़ील्ड का इस्तेमाल करके, इस TextLabel के लिए टेक्स्ट डालें.
  4. TextLabel को LabelOperation में रैप करें और इसे LabelService.MutateLabels को भेजें.

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

आईडी फिर से पाने के लिए, LabelService.GetLabel अनुरोध या GoogleAdsService Search या SearchStream का अनुरोध भी किया जा सकता है.

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

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

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

  • label: लेबल का आईडी
  • campaign: कैंपेन का आईडी

हर लेबल-कैंपेन के पेयर के लिए, एक CampaignLabel इंस्टेंस बनाएं. इसे create कार्रवाई के साथ CampaignLabelOperation में रैप करें और CampaignService.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.V16.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, customer_id, label_id, campaign_ids):
    """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 = client.get_service("CampaignLabelService")
    campaign_service = client.get_service("CampaignService")
    label_service = client.get_service("LabelService")

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

    operations = []

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

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

    response = 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::V16::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::V16::Resources::CampaignLabel->new({
        campaign => Google::Ads::GoogleAds::V16::Utils::ResourceNames::campaign(
          $customer_id, $campaign_id
        ),
        label => $label_resource_name
      });

    # Create a campaign label operation.
    my $campaign_label_operation =
      Google::Ads::GoogleAds::V16::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;
}
      

चीज़ों के लेबल का इस्तेमाल करके उन्हें वापस पाना

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

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

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"

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

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

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

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

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

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

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

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

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

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

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

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