weixin_39479608 2023-05-07 19:44 采纳率: 0%
浏览 10

googleads/google-ads-php v13 广告系列如何通过api设置定义转化目标

googleads/google-ads-php v13 广告系列如何通过api设置定义转化目标。

  • 写回答

1条回答 默认 最新

  • 你的兔子 2023-05-08 15:03
    关注

    针对你的问题结合chatgpt知识库请参考以下内容:
    要通过 Google Ads API 设置和定义转化目标,您需要完成以下步骤:

    1. 在 Google Ads 广告管理界面中创建新的转化操作。有多种方式可用于跟踪转换,如转化跟踪代码、导入等。

    2. 访问 Google Ads 广告管理界面上的“工具”菜单,打开“转化操作” 页面,获取转化标记代码或 ID 值。

    3. 在 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 项目中获取。

    1. 创建转化追踪器并将其与广告系列相关联:

    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、转化点时间、转化价值等必需信息。

    通过以上步骤,您可以轻松设置和定义转换目标,以便更好地跟踪广告系列活动的转化效果。

    评论

报告相同问题?

问题事件

  • 创建了问题 5月7日

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)