googleads/google-ads-php v13 广告系列如何通过api设置定义转化目标。
针对你的问题结合chatgpt知识库请参考以下内容:
要通过 Google Ads API 设置和定义转化目标,您需要完成以下步骤:
在 Google Ads 广告管理界面中创建新的转化操作。有多种方式可用于跟踪转换,如转化跟踪代码、导入等。
访问 Google Ads 广告管理界面上的“工具”菜单,打开“转化操作” 页面,获取转化标记代码或 ID 值。
在 Google Ads API 中设置转化操作:
a) 创建 ConversionActionServiceClient 实例:
use Google\Ads\GoogleAds\V6\Services\ConversionActionServiceClient;
$conversionActionServiceClient = new ConversionActionServiceClient();
b) 在 ConversionActionServiceClient 的 createConversionAction 方法中指定一个 ConversionActionInfo 对象表示转化操作,并调用 execute 方法执行:
use Google\Ads\GoogleAds\V6\Resources\ConversionAction;
use Google\Ads\GoogleAds\V6\Resources\TagSnippet;
use Google\Ads\GoogleAds\V6\Resources\ValueSettings;
$conversionAction = new ConversionAction([
'name' => 'Example Conversion',
'type' => ConversionActionType::UPLOAD,
'category' => ConversionActionCategory::DEFAULT_CATEGORY,
'value_settings' => new ValueSettings([
'default_value' => new Money([
'micro_amount' => 1000000, // $1.00
'currency_code' => 'USD'
])
]),
'status' => ConversionActionStatus::ENABLED,
'tag_snippets' => [
new TagSnippet([
'type' => TagSnippetType::HTML,
'page_format' => TagSnippetPageFormat::UNIVERSAL,
'global_site_tag' => $siteTag, // replace with your site tag
])
]
]);
$response = $conversionActionServiceClient->createConversionAction(
$customerId,
$conversionAction
);
printf("Created conversion action '%s'.\n", $response->getResourceName());
在上面的示例代码中,ConversionActionInfo 对象包含转化操作的名称、类型、值信息、运行状态和标记片段。customerId 和 siteTag 参数需要从您的 Google Ads API 项目中获取。
a) 创建 ConversionsServiceClient 实例:
use Google\Ads\GoogleAds\V6\Services\ConversionsServiceClient;
$conversionServiceClient = new ConversionsServiceClient();
b) 在 ConversionsServiceClient 的 uploadConversions 方法中指定 ConversionActionInfo 对象和相应的 ConversionUpload 构建指令,然后调用 execute 方法执行:
use Google\Ads\GoogleAds\V6\Resources\ClickConversion;
use Google\Ads\GoogleAds\V6\Common\GclidDateTimePair;
use Google\Ads\GoogleAds\V6\Common\AttributionModelType;
use Google\Ads\GoogleAds\V6\Common\ConversionDateTimeRange;
use Google\Ads\GoogleAds\V6\Common\ConversionTrackerUrlTemplate;
use Google\Ads\GoogleAds\V6\Common\ConversionValueRule;
use Google\Ads\GoogleAds\V6\Common\CustomAttribute;
use Google\Ads\GoogleAds\V6\Common\UserData;
$clickConversion = new ClickConversion([
'conversion_action' => $conversionActionResourceName,
'gclid' => $gclid,
'conversion_date_time' => $dateTimeString,
'attribution_model' => AttributionModelType::EXTERNAL,
'conversion_value' => $conversionValue,
'currency_code' => 'USD',
'custom_variables' => $customVariables, // if any
'order_id' => $orderId, // optional for third-party app attribution
'external_attribution_data' => $externalAttributionData, // optional
'user_agent' => $userAgent, // optional for native mobile apps
'http_referer' => $refererUrl, // optional for web apps
'discounts' => $discounts, // optional
'xsi_type' => 'AdwordsConversion',
'conversion_tracking_urls' => [
new ConversionTrackerUrlTemplate([
'url_template' => $urlTemplate, // if any
])
],
'value_rule' => new ConversionValueRule([
'trigger_type' => TriggerType::INCLUDE_ANY_VALUE,
'default_value' => new CustomAttribute([
'string_value' => '0',
]),
]),
]);
$conversionUpload = new ConversionUpload([
'click_conversions' => [$clickConversion]
]);
$response = $conversionServiceClient->uploadConversions(
$customerId,
$conversionUpload
);
printf("Uploaded %d conversion(s):\n", $response->getResults()->count());
foreach ($response->getResults() as $convertedClick) {
printf("\t'%s'\n", $convertedClick->getResourceName());
}
在上面的示例代码中,使用 ClickConversion 对象和 ConversionUpload 构建指令,其中包含转化操作 ID、点击 ID、转化点时间、转化价值等必需信息。
通过以上步骤,您可以轻松设置和定义转换目标,以便更好地跟踪广告系列活动的转化效果。