定制文字广告

您可以通过广告定制工具、倒计时IF 函数定制标准广告和加大型文字广告。与使用广告参数相比,广告定制工具更为灵活。

广告定制工具是基于 Feed 的解决方案,用于在您的广告中插入动态信息。您可以为特定的广告系列、广告组和/或关键字设置含定位选项的 Feed,然后制作引用 Feed 所含信息的广告,使 Feed 中的值在广告投放时显示。

您可以在广告中插入字符串、价格、数字,甚至是截至特定日期或时间的倒计时。

广告定制工具

广告定制工具常被用于在特定日期范围内以促销价格宣传某件商品。在此情形中,您需要为 Feed 设置三个属性:一个字符串属性代表商品名称,另一个字符串属性代表价格,还有一个日期属性代表促销结束日期。然后将它们填充到 Feed 项中的相应位置。

设置广告时,您应引用该 Feed 项以及它的名称属性和促销价格属性:AdWords 会自动在广告中填充来自该 Feed 项的名称和价格。

要使用该 Feed 项的结束日期,您应通过函数添加日期属性,让 AdWords 在广告中显示以结束日期为终点的倒计时。制作广告时,您应引用该 Feed 项以及它的名称属性、促销价格属性和结束日期属性:AdWords 会自动在广告中填充来自该 Feed 项的名称、价格和结束日期。

下次促销时,只需更新该 Feed 项的价格和结束日期属性值,即可重复利用此广告,而不必每次都制作新广告。

下面各部分将说明上述使用情形所涉及的所有阶段,包括如何:

  • 设置 Feed 及其属性
  • 使用您希望在广告中展示的值创建 Feed 项
  • 将 Feed 项定位到具体广告系列、广告组或关键字
  • 在广告中使用 Feed
  • 添加倒计时
  • 添加 IF 函数

设置 Feed

第一步,创建包含了您定制广告所需全部属性的 Feed。

下面这个 Feed 有三个属性;其中两个为 STRING 类型,一个为 DATE_TIME 类型:

Java

AdCustomizerFeed customizerFeed = new AdCustomizerFeed();
customizerFeed.setFeedName(feedName);

AdCustomizerFeedAttribute nameAttribute = new AdCustomizerFeedAttribute();
nameAttribute.setName("Name");
nameAttribute.setType(AdCustomizerFeedAttributeType.STRING);

AdCustomizerFeedAttribute priceAttribute = new AdCustomizerFeedAttribute();
priceAttribute.setName("Price");
priceAttribute.setType(AdCustomizerFeedAttributeType.STRING);

AdCustomizerFeedAttribute dateAttribute = new AdCustomizerFeedAttribute();
dateAttribute.setName("Date");
dateAttribute.setType(AdCustomizerFeedAttributeType.DATE_TIME);

customizerFeed.setFeedAttributes(
    new AdCustomizerFeedAttribute[] {nameAttribute, priceAttribute, dateAttribute});

C#

AdCustomizerFeed feed = new AdCustomizerFeed() {
  feedName = feedName,
  feedAttributes = new AdCustomizerFeedAttribute[] {
    new AdCustomizerFeedAttribute() {
      name = "Name",
      type = AdCustomizerFeedAttributeType.STRING
    },
    new AdCustomizerFeedAttribute() {
      name = "Price",
      type = AdCustomizerFeedAttributeType.PRICE
    },
    new AdCustomizerFeedAttribute() {
      name = "Date",
      type = AdCustomizerFeedAttributeType.DATE_TIME
    },
  }
};

Python

customizer_feed = {
    'feedName': feed_name,
    'feedAttributes': [
        {'type': 'STRING', 'name': 'Name'},
        {'type': 'STRING', 'name': 'Price'},
        {'type': 'DATE_TIME', 'name': 'Date'}
    ]
}

PHP

$nameAttribute = new AdCustomizerFeedAttribute();
$nameAttribute->setName('Name');
$nameAttribute->setType(AdCustomizerFeedAttributeType::STRING);

$priceAttribute = new AdCustomizerFeedAttribute();
$priceAttribute->setName('Price');
$priceAttribute->setType(AdCustomizerFeedAttributeType::STRING);

$dateAttribute = new AdCustomizerFeedAttribute();
$dateAttribute->setName('Date');
$dateAttribute->setType(AdCustomizerFeedAttributeType::DATE_TIME);

$customizerFeed = new AdCustomizerFeed();
$customizerFeed->setFeedName($feedName);
$customizerFeed->setFeedAttributes(
    [$nameAttribute, $priceAttribute, $dateAttribute]
);

Perl

my $name_attribute =
  Google::Ads::AdWords::v201802::AdCustomizerFeedAttribute->new({
    type => "STRING",
    name => "Name"
  });
my $price_attribute =
  Google::Ads::AdWords::v201802::AdCustomizerFeedAttribute->new({
    type => "STRING",
    name => "Price"
  });
my $date_attribute =
  Google::Ads::AdWords::v201802::AdCustomizerFeedAttribute->new({
    type => "DATE_TIME",
    name => "Date"
  });
my $ad_customizer_feed = Google::Ads::AdWords::v201802::AdCustomizerFeed->new(
  {
    feedName       => $feed_name,
    feedAttributes => [$name_attribute, $price_attribute, $date_attribute]});

Ruby

feed = {
  :feed_name => feed_name,
  :feed_attributes => [
    {:name => 'Name', :type => 'STRING'},
    {:name => 'Price', :type => 'PRICE'},
    {:name => 'Date', :type => 'DATE_TIME'}
  ]
}

VB.NET

Using adCustomizerFeedService As AdCustomizerFeedService = DirectCast(user.GetService(
    AdWordsService.v201802.AdCustomizerFeedService), AdCustomizerFeedService)

  Dim feed As New AdCustomizerFeed()
  feed.feedName = feedName

  Dim attribute1 As New AdCustomizerFeedAttribute
  attribute1.name = "Name"
  attribute1.type = AdCustomizerFeedAttributeType.STRING

  Dim attribute2 As New AdCustomizerFeedAttribute
  attribute2.name = "Price"
  attribute2.type = AdCustomizerFeedAttributeType.PRICE

  Dim attribute3 As New AdCustomizerFeedAttribute
  attribute3.name = "Date"
  attribute3.type = AdCustomizerFeedAttributeType.DATE_TIME

  feed.feedAttributes = New AdCustomizerFeedAttribute() {
  attribute1, attribute2, attribute3
}

记下此 Feed 及其属性的 ID,在设置此 Feed 项时需要这些信息。您可以直接从 mutate 调用结果中提取这些属性。

Java

AdCustomizerFeedOperation feedOperation = new AdCustomizerFeedOperation();
feedOperation.setOperand(customizerFeed);
feedOperation.setOperator(Operator.ADD);

AdCustomizerFeed addedFeed = adCustomizerFeedService.mutate(
    new AdCustomizerFeedOperation[] {feedOperation}).getValue()[0];

System.out.printf(
    "Created ad customizer feed with ID %d, name '%s' and attributes:%n",
    addedFeed.getFeedId(), addedFeed.getFeedName());
for (AdCustomizerFeedAttribute feedAttribute : addedFeed.getFeedAttributes()) {
  System.out.printf(
      "  ID: %d, name: '%s', type: %s%n",
      feedAttribute.getId(), feedAttribute.getName(), feedAttribute.getType());
}

C#

AdCustomizerFeedOperation feedOperation = new AdCustomizerFeedOperation();
feedOperation.operand = feed;
feedOperation.@operator = (Operator.ADD);

AdCustomizerFeed addedFeed = adCustomizerFeedService.mutate(
    new AdCustomizerFeedOperation[] { feedOperation }).value[0];

Console.WriteLine("Created ad customizer feed with ID = {0} and name = '{1}' and " +
    "attributes: ", addedFeed.feedId, addedFeed.feedName);

foreach (AdCustomizerFeedAttribute feedAttribute in addedFeed.feedAttributes) {
  Console.WriteLine("  ID: {0}, name: '{1}', type: {2}",
      feedAttribute.id, feedAttribute.name, feedAttribute.type);
}

Python

feed_service_operation = {
    'operator': 'ADD',
    'operand': customizer_feed
}

response = ad_customizer_feed_service.mutate([feed_service_operation])

if response and 'value' in response:
  feed = response['value'][0]
  feed_data = {
      'feedId': feed['feedId'],
      'nameId': feed['feedAttributes'][0]['id'],
      'priceId': feed['feedAttributes'][1]['id'],
      'dateId': feed['feedAttributes'][2]['id']
  }
  print ('Feed with name "%s" and ID %s was added with:\n'
         '\tName attribute ID %s and price attribute ID %s and date attribute'
         'ID %s') % (feed['feedName'], feed['feedId'], feed_data['nameId'],
                     feed_data['priceId'], feed_data['dateId'])

PHP

$feedOperation = new AdCustomizerFeedOperation();
$feedOperation->setOperand($customizerFeed);
$feedOperation->setOperator(Operator::ADD);
$operations = [$feedOperation];

$result = $adCustomizerFeedService->mutate($operations);
$addedFeed = $result->getValue()[0];

printf(
    "Created ad customizer feed with ID %d, name '%s' and attributes:\n",
    $addedFeed->getFeedId(),
    $addedFeed->getFeedName()
);
if (empty($addedFeed)) {
    print "  No attributes\n";
} else {
    foreach ($addedFeed->getFeedAttributes() as $feedAttribute) {
        printf(
            "  ID: %d, name: '%s', type: %s\n",
            $feedAttribute->getId(),
            $feedAttribute->getName(),
            $feedAttribute->getType()
        );
    }
}

Perl

my $operation = Google::Ads::AdWords::v201802::AdCustomizerFeedOperation->new(
  {
    operator => "ADD",
    operand  => $ad_customizer_feed
  });

my $feed_result =
  $client->AdCustomizerFeedService()->mutate({operations => [$operation]});

my $added_feed = $feed_result->get_value(0);

printf(
  "Created ad customizer feed with ID %d, and name '%s' and attributes:\n",
  $added_feed->get_feedId(),
  $added_feed->get_feedName());
foreach my $feed_attribute ($added_feed->get_feedAttributes()) {
  printf "  ID: %d, name: '%s', type: '%s'\n",
    $feed_attribute->get_id(), $feed_attribute->get_name(),
    $feed_attribute->get_type();
}

Ruby

operation = {:operand => feed, :operator => 'ADD'}
added_feed = ad_customizer_srv.mutate([operation])[:value].first()
puts "Created ad customizer feed with ID = %d and name = '%s'." %
    [added_feed[:feed_id], added_feed[:feed_name]]
added_feed[:feed_attributes].each do |feed_attribute|
  puts "  ID: %d, name: '%s', type: %s" %
      [feed_attribute[:id], feed_attribute[:name], feed_attribute[:type]]
end

VB.NET

Dim feedOperation As New AdCustomizerFeedOperation()
feedOperation.operand = feed
feedOperation.operator = [Operator].ADD

Dim addedFeed As AdCustomizerFeed = adCustomizerFeedService.mutate(
  New AdCustomizerFeedOperation() {feedOperation}).value(0)

Console.WriteLine("Created ad customizer feed with ID = {0} and name = '{1}'.",
                addedFeed.feedId, addedFeed.feedName)

返回的属性会按您在创建 Feed 时指定的顺序显示。

创建已定位的 FeedItem

创建一个 FeedItem,以使用该 FeedItemcampaignTargetingadGroupTargetingkeywordTargetinggeoTargeting 属性来限定只将 Feed 应用到特定的广告系列、广告组、关键字或地理位置。

您可以使用在上一步创建 Feed 时获取的 ID 添加 Feed 项。下面的代码示例将每个 Feed 项的值传递给一个辅助函数。

Java

DateTime now = new DateTime();

DateTime marsDate = new DateTime(now.getYear(), now.getMonthOfYear(), 1, 0, 0);
feedItemOperations.add(createFeedItemAddOperation("Mars", "$1234.56",
    marsDate.toString("yyyyMMdd HHmmss"), adGroupIds.get(0), adCustomizerFeed));

DateTime venusDate = new DateTime(now.getYear(), now.getMonthOfYear(), 15, 0, 0);
feedItemOperations.add(createFeedItemAddOperation("Venus", "$1450.00",
    venusDate.toString("yyyyMMdd HHmmss"), adGroupIds.get(1), adCustomizerFeed));

C#

DateTime marsDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
feedItemOperations.Add(CreateFeedItemAddOperation(adCustomizerFeed, "Mars", "$1234.56",
    marsDate.ToString("yyyyMMdd HHmmss"), adGroupIds[0]));

DateTime venusDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 15);
feedItemOperations.Add(CreateFeedItemAddOperation(adCustomizerFeed, "Venus", "$1450.00",
    venusDate.ToString("yyyyMMdd HHmmss"), adGroupIds[1]));

Python

now = datetime.now()
mars_date = datetime(now.year, now.month, 1, 0, 0)
venus_date = datetime(now.year, now.month, 15, 0, 0)
time_format = '%Y%m%d %H%M%S'

feed_item_operations = [
    CreateFeedItemAddOperation(
        'Mars', '$1234.56', mars_date.strftime(time_format), adgroup_ids[0],
        ad_customizer_feed),
    CreateFeedItemAddOperation(
        'Venus', '$1450.00', venus_date.strftime(time_format),
        adgroup_ids[1], ad_customizer_feed)
]

PHP

$marsDate = mktime(0, 0, 0, date('m'), 1, date('Y'));
$venusDate = mktime(0, 0, 0, date('m'), 15, date('Y'));

// Create multiple feed item operations and add them to the operations list.
$operations[] = self::createFeedItemAddOperation(
    'Mars',
    '$1234.56',
    date('Ymd His', $marsDate),
    $adGroupIds[0],
    $adCustomizerFeed
);
$operations[] = self::createFeedItemAddOperation(
    'Venus',
    '$1450.00',
    date('Ymd His', $venusDate),
    $adGroupIds[1],
    $adCustomizerFeed
);

Perl

push @operations,
  create_feed_item_add_operation($ad_customizer_feed,
  "Mars", "\$1234.56", "20140601 000000",
  $ad_group_ids->[0]);
push @operations,
  create_feed_item_add_operation($ad_customizer_feed,
  "Venus", "\$1450.00", "20140615 120000",
  $ad_group_ids->[1]);

Ruby

# Now adding feed items -- the values we'd like to place.
now_date = Date.today()

items_data = [
  {
    :name => 'Mars',
    :price => '$1234.56',
    :date => now_date.strftime('%Y%m01 000000'),
    :ad_group_id => ad_group_ids[0]
  },
  {
    :name => 'Venus',
    :price => '$1450.00',
    :date => now_date.strftime('%Y%m15 000000'),
    :ad_group_id => ad_group_ids[1]
   }
]

VB.NET

Dim marsDate As New DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)
feedItemOperations.Add(CreateFeedItemAddOperation(adCustomizerFeed, "Mars", "$1234.56",
  marsDate.ToString("yyyyMMdd HHmmss"), adGroupIds(0)))

Dim venusDate As New DateTime(DateTime.Now.Year, DateTime.Now.Month, 15)
feedItemOperations.Add(CreateFeedItemAddOperation(adCustomizerFeed, "Venus", "$1450.00",
  venusDate.ToString("yyyyMMdd HHmmss"), adGroupIds(1)))

辅助函数使用提供的值设置 Feed 项:

Java

FeedItem feedItem = new FeedItem();
feedItem.setFeedId(adCustomizerFeed.getFeedId());

List<FeedItemAttributeValue> attributeValues = new ArrayList<>();

// FeedAttributes appear in the same order as they were created - Name, Price, Date.
// See the createCustomizerFeed method for details.
FeedItemAttributeValue nameAttributeValue = new FeedItemAttributeValue();
nameAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(0).getId());
nameAttributeValue.setStringValue(name);
attributeValues.add(nameAttributeValue);

FeedItemAttributeValue priceAttributeValue = new FeedItemAttributeValue();
priceAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(1).getId());
priceAttributeValue.setStringValue(price);
attributeValues.add(priceAttributeValue);

FeedItemAttributeValue dateAttributeValue = new FeedItemAttributeValue();
dateAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(2).getId());
dateAttributeValue.setStringValue(date);
attributeValues.add(dateAttributeValue);

feedItem.setAttributeValues(
    attributeValues.toArray(new FeedItemAttributeValue[attributeValues.size()]));

feedItem.setAdGroupTargeting(new FeedItemAdGroupTargeting(adGroupId));

C#

FeedItem feedItem = new FeedItem() {
  feedId = adCustomizerFeed.feedId,

  // FeedAttributes appear in the same order as they were created
  // - Name, Price, Date. See CreateCustomizerFeed method for details.
  attributeValues = new FeedItemAttributeValue[] {
    new FeedItemAttributeValue() {
      feedAttributeId = adCustomizerFeed.feedAttributes[0].id,
      stringValue = name
    },

    new FeedItemAttributeValue() {
      feedAttributeId = adCustomizerFeed.feedAttributes[1].id,
      stringValue = price
    },

    new FeedItemAttributeValue() {
      feedAttributeId = adCustomizerFeed.feedAttributes[2].id,
      stringValue = date
    }
  },

  adGroupTargeting = new FeedItemAdGroupTargeting() {
    TargetingAdGroupId = adGroupId
  }
};

Python

feed_item = {
    'feedId': ad_customizer_feed['feedId'],
    'adGroupTargeting': {
        'TargetingAdGroupId': adgroup_id
    },
    'attributeValues': [
        {
            'feedAttributeId': ad_customizer_feed['feedAttributes'][0]['id'],
            'stringValue': name
        },
        {
            'feedAttributeId': ad_customizer_feed['feedAttributes'][1]['id'],
            'stringValue': price
        },
        {
            'feedAttributeId': ad_customizer_feed['feedAttributes'][2]['id'],
            'stringValue': date
        }
    ]
}

operation = {
    'operator': 'ADD',
    'operand': feed_item
}

PHP

$nameAttributeValue = new FeedItemAttributeValue();
$nameAttributeValue->setFeedAttributeId(
    $adCustomizerFeed->getFeedAttributes()[0]->getId()
);
$nameAttributeValue->setStringValue($name);

$priceAttributeValue = new FeedItemAttributeValue();
$priceAttributeValue->setFeedAttributeId(
    $adCustomizerFeed->getFeedAttributes()[1]->getId()
);
$priceAttributeValue->setStringValue($price);

$dateAttributeValue = new FeedItemAttributeValue();
$dateAttributeValue->setFeedAttributeId(
    $adCustomizerFeed->getFeedAttributes()[2]->getId()
);
$dateAttributeValue->setStringValue($date);

$item = new FeedItem();
$item->setFeedId($adCustomizerFeed->getFeedId());
$item->setAttributeValues(
    [$nameAttributeValue, $priceAttributeValue, $dateAttributeValue]
);

$adGroupTargeting = new FeedItemAdGroupTargeting();
$adGroupTargeting->setTargetingAdGroupId($adGroupId);
$item->setAdGroupTargeting($adGroupTargeting);

Perl

my ($ad_customizer_feed, $name, $price, $date, $ad_group_id) = @_;

my $name_attribute_value =
  Google::Ads::AdWords::v201802::FeedItemAttributeValue->new({
    feedAttributeId =>
      $ad_customizer_feed->get_feedAttributes()->[0]->get_id(),
    stringValue => $name
  });
my $price_attribute_value =
  Google::Ads::AdWords::v201802::FeedItemAttributeValue->new({
    feedAttributeId =>
      $ad_customizer_feed->get_feedAttributes()->[1]->get_id(),
    stringValue => $price
  });
my $date_attribute_value =
  Google::Ads::AdWords::v201802::FeedItemAttributeValue->new({
    feedAttributeId =>
      $ad_customizer_feed->get_feedAttributes()->[2]->get_id(),
    stringValue => $date
  });

my $feed_item = Google::Ads::AdWords::v201802::FeedItem->new({
    feedId => $ad_customizer_feed->get_feedId(),
    attributeValues =>
      [$name_attribute_value, $price_attribute_value, $date_attribute_value],
    adGroupTargeting =>
      Google::Ads::AdWords::v201802::FeedItemAdGroupTargeting->new(
      {TargetingAdGroupId => $ad_group_id})});

Ruby

feed_items = items_data.map do |item|
  {
    :feed_id => feed_data[:feed_id],
    :attribute_values => [
      {
        :feed_attribute_id => feed_data[:name_id],
        :string_value => item[:name]
      },
      {
        :feed_attribute_id => feed_data[:price_id],
        :string_value => item[:price]
      },
      {
        :feed_attribute_id => feed_data[:date_id],
        :string_value => item[:date]
      }
    ],
    :ad_group_targeting => {
      :targeting_ad_group_id => item[:ad_group_id]
    }
  }
end

VB.NET

Dim feedItem As New FeedItem
feedItem.feedId = adCustomizerFeed.feedId
Dim attributeValues As New List(Of FeedItemAttributeValue)

' FeedAttributes appear in the same order as they were created
' - Name, Price, Date. See CreateCustomizerFeed method for details.
Dim nameAttributeValue As New FeedItemAttributeValue
nameAttributeValue.feedAttributeId = adCustomizerFeed.feedAttributes(0).id
nameAttributeValue.stringValue = nameValue
attributeValues.Add(nameAttributeValue)

Dim priceAttributeValue As New FeedItemAttributeValue
priceAttributeValue.feedAttributeId = adCustomizerFeed.feedAttributes(1).id
priceAttributeValue.stringValue = priceValue
attributeValues.Add(priceAttributeValue)

Dim dateAttributeValue As New FeedItemAttributeValue
dateAttributeValue.feedAttributeId = adCustomizerFeed.feedAttributes(2).id
dateAttributeValue.stringValue = dateValue
attributeValues.Add(dateAttributeValue)

feedItem.attributeValues = attributeValues.ToArray

feedItem.adGroupTargeting = New FeedItemAdGroupTargeting
feedItem.adGroupTargeting.TargetingAdGroupId = adGroupId

系统只会为在 targeting_ad_group_id 中指定的广告组提取此 Feed 项。该广告组中的广告都将使用这些 Feed 项来实现动态替换。

如果有多个 Feed 项符合指定环境,系统会根据某种算法自动挑选一个。此算法可能会因时间而异。如果您希望更准确地控制使用每个 Feed 项的具体环境,请务必要使用相关 Feed 项内的特定定位方式。

在广告中使用 Feed

设置 Feed 后,即可从系统中的任何广告中引用该 Feed。

设置广告时,您要按名称(而非 ID)来引用 Feed 及其属性。这与其他步骤不同,在其他步骤中,您要使用系统生成的 ID。

要插入 Feed 中的定制值,应采用语法 {=FeedName.AttributeName}。如果您想指定默认值,则语法应该是 {=FeedName.AttributeName:default value}。以上面的 Feed 为例,如果要以字符串格式插入某个对象的价格(默认为 10 美元),应使用 {=AdCustomizerFeed.Price:$10}

Java

ExpandedTextAd textAd = new ExpandedTextAd();
textAd.setHeadlinePart1(String.format("Luxury Cruise to {=%s.Name}", feedName));
textAd.setHeadlinePart2(String.format("Only {=%s.Price}", feedName));
textAd.setDescription(String.format("Offer ends in {=countdown(%s.Date)}!", feedName));
textAd.setFinalUrls(new String[] {"http://www.example.com"});

C#

ExpandedTextAd expandedTextAd = new ExpandedTextAd() {
  headlinePart1 = string.Format("Luxury Cruise to {{={0}.Name}}", feedName),
  headlinePart2 = string.Format("Only {{={0}.Price}}", feedName),
  description = string.Format("Offer ends in {{=countdown({0}.Date)}}!", feedName),
  finalUrls = new string[] { "http://www.example.com" }
};

Python

expanded_text_ad = {
    'xsi_type': 'ExpandedTextAd',
    'headlinePart1': 'Luxury Cruise to {=%s.Name}' % feed_name,
    'headlinePart2': 'Only {=%s.Price}' % feed_name,
    'description': 'Offer ends in {=countdown(%s.Date)}!' % feed_name,
    'finalUrls': ['http://www.example.com'],
}

PHP

// Create an expanded text ad that uses ad customization.
$expandedTextAd = new ExpandedTextAd();
$expandedTextAd->setHeadlinePart1(
    sprintf('Luxury Cruise to {=%s.Name}', $feedName)
);
$expandedTextAd->setHeadlinePart2(
    sprintf('Only {=%s.Price}', $feedName)
);
$expandedTextAd->setDescription(
    sprintf('Offer ends in {=countdown(%s.Date)}!', $feedName)
);
$expandedTextAd->setFinalUrls(['http://www.example.com']);

Perl

my $text_ad = Google::Ads::AdWords::v201802::ExpandedTextAd->new({
    headlinePart1 => sprintf("Luxury Cruise to {=%s.Name}", $feed_name),
    headlinePart2 => sprintf("Only {=%s.Price}",            $feed_name),
    description =>
      sprintf("Offer ends in {=countdown(%s.Date)}!", $feed_name),
    finalUrls => ['http://www.example.com']});

Ruby

# All set! We can now create ads with customizations.
expanded_text_ad = {
  :xsi_type => 'ExpandedTextAd',
  :headline_part1 => 'Luxury Cruise to {=%s.Name}' % feed_name,
  :headline_part2 => 'Only {=%s.Price}' % feed_name,
  :description => 'Offer ends in {=countdown(%s.Date)}!' % feed_name,
  :final_urls => ['http://www.example.com']
}

VB.NET

Dim expandedTextAd As New ExpandedTextAd
expandedTextAd.headlinePart1 = String.Format("Luxury Cruise to {{={0}.Name}}", feedName)
expandedTextAd.headlinePart2 = String.Format("Only {{={0}.Price}}", feedName)
expandedTextAd.description = String.Format("Offer ends in {{=countdown({0}.Date)}}!",
                                         feedName)
expandedTextAd.finalUrls = New String() {"http://www.example.com"}

如果通过 AdGroupAdService 添加此广告,在投放时引用了 AdCustomizerFeed 的地方都会填充该 Feed 中与当前广告组匹配的 Feed 项的匹配数据。如果找不到匹配项,广告就不会投放。

API 会对引用了广告定制工具的广告进行验证:如果没有指定名称的 Feed 映射到广告占位符类型,或者 Feed 中不存在使用指定名称的属性,广告就会被拒。

如果您在有广告引用 Feed 时更改 Feed 的名称,广告会自动更新以引用新的 Feed 名称。如果您在有广告引用 Feed 时删除 Feed,则这些广告都不会再投放。

使用定制工具的广告与其他广告一样要接受审批。Feed 项和广告可能会分别被拒批,但是只要两者之一遭拒批,都会导致广告无法投放。在极少数情况下,如果 Feed 项和广告单独使用没问题,但组合在一起就违规,系统也会拒批广告,禁止其投放。

添加倒计时

COUNTDOWN 函数可让您动态地更改显示日期字段的方式,使其显示剩余时间(天数、小时数)。

例如,上述广告示例的 description 设置为 'Offer ends in {=COUNTDOWN(AdCustomizerFeed.Date)}!' 这样,广告投放时就会根据剩余时间显示“Offer ends in 5 days!”或“Offer ends in 4 hours!”。

在倒计时中指定的日期过去后,如果不再次更新此日期,广告就不会再投放。

倒计时函数有三个参数,但只有第一个是必需的:

  • timestamp:您要对其进行倒计时的日期。这个值可以引用 Feed 属性,也可以是具体的日期。
  • language:倒计时显示时使用的本地化语言。如果不指定,将使用默认值“en-US”。
  • days_before:距离此广告可以开始投放的 timestamp 还剩几天。例如,如果现在距离指定时间还有 6 天,但这个字段设为 5,广告将不会投放。如果未指定,则系统不会添加任何限制。

例如,您可以使用 {=COUNTDOWN(AdCustomizerFeed.Date, 'es', 3)} 来将语言改为西班牙语,并限定广告在指定日期 3 天前才开始在搜索结果中展示。

COUNTDOWN 函数会根据查询用户所在的时区对活动进行倒计时。COUNTDOWN 的变体版本 GLOBAL_COUNTDOWN 会根据您帐号所设的时区倒计至特定时间。GLOBAL_COUNTDOWN 使用与 COUNTDOWN 相同的参数。

添加 IF 函数

借助 IF 函数,您可以根据搜索用户和他们搜索时使用的设备在广告中插入定制消息,而无需使用 Feed。默认文字是可选的。

维度 条件 语法 示例
设备 移动设备 {=IF(device=mobile,text to insert):optional default text} {=IF(device=mobile,"Quick, Easy, Mobile Booking"):"Best price guarantee"}
受众群体 帐号中任何有效的用户列表名称(如果列表名称与广告客户帐号中的多个列表相符,我们会随机选择一个) {=IF(audience IN (userlist1,userlist2),text to insert):optional default text} {=IF(audience IN (returning visitors,cart abandoners),30%):25%}

代码示例

以各种受支持的编程语言撰写的代码示例可帮助您开始添加广告定制工具:

广告参数

利用广告参数,您可以动态更新广告中的数字信息,而无需重新将广告送交审核和批准。这与关键字插入类似,在显示时更新广告内的标记。广告参数借助 AdParamService 通过 API 进行管理。

广告参数由 AdParam 对象表示。要使 AdParam 正常工作,它必须:

  • 针对该次展示的 KeywordAdGroupparamIndex 而指定。
  • 在应用了所有广告参数后,不会使广告的任何文本字段的长度超过行长度的上限。
  • 成为展示在 Google 搜索网络上的广告的一部分。

如果在插入期间出现问题,则会为广告参数显示默认值。

代码示例

以各种受支持的编程语言撰写的代码示例可帮助您开始管理广告参数:

发送以下问题的反馈:

此网页
AdWords API
AdWords API
需要帮助?请访问我们的支持页面