> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Performance Max 广告活动

> 使用您的文字和图片创建 Google Ads Performance Max 广告活动

> [!WARNING]
>
> **请先设置转化跟踪。** Performance Max 会根据您的转化来决定在哪里展示广告以及出价多少。Ayrshare 不会阻止没有转化跟踪的活动，但在您的 Google Ads 账户中设置转化跟踪之前，Google 可能会限制其支出。Ayrshare 不会替您进行设置。当账户没有转化跟踪时，创建响应中会包含一条说明此情况的 `warnings` 条目。

通过一个请求创建 Google Ads Performance Max 活动。您发送文字和图片 URL，Google 会将它们组合成在搜索、YouTube、展示广告网络、Discover、Gmail 和地图上投放的广告。Ayrshare 会一并创建预算、活动、一个素材资源组及其所有素材资源。如果 Google 拒绝其中任何部分，则不会创建任何内容。

该请求使用通用的 [广告活动](https://www.ayrshare.com/docs/apis/ads/campaigns.md) 结构。读取和更改活动、数据分析以及错误的处理方式与 [Google 搜索广告活动](https://www.ayrshare.com/docs/apis/ads/google/search-campaigns.md) 相同。本页介绍不同之处。

<ul>
  <li>Google 广告需按账户单独开通。请联系我们以启用该功能。</li>
  <li>除非您发送 `status: "active"`，否则新活动以 `paused` 状态开始。</li>
  <li>预算按天计算，使用广告账户的币种，并且绝不会与其他活动共享。</li>
  <li>其他币种的支出会按 Open Exchange Rates 提供的当日汇率换算为美元进行结算。使用无法换算的币种的账户会在创建任何内容之前返回 `code: 101`。</li>
  <li>不支持视频。Google 可能会根据您的图片制作视频。</li>
</ul>

## 请求头参数

**Authorization** `string` *required*

[API Key](https://www.ayrshare.com/docs/apis/overview.md#authorization) of the Primary Profile.

Format: `Authorization: Bearer API_KEY`
**Profile-Key** `string`

[Profile Key](https://www.ayrshare.com/docs/apis/overview.md#profile-key-format) of a User Profile.

Format: `Profile-Key: PROFILE_KEY`

**Idempotency-Key** `string` *required*

每创建一个新活动，请发送一个新的唯一值，例如 UUID。使用相同的键重复请求会返回首次的响应。如果创建请求在 Ayrshare 将活动发送给 Google 之前失败（例如图片尺寸不正确），该键会被释放，因此您可以修正请求后使用相同的键重试。

## 请求体参数

**type** `string` *required*

`performanceMax`.

**bidding** `object` *required*

Performance Max 仅接受以下策略。其他任何值都会返回 `code: 101`。

<ul>
  <li>`maximizeConversions`：在预算内获得尽可能多的转化。</li>
  <li>`targetCpa` 搭配 `targetCpa`：同上，并以该单次转化费用为目标。</li>
  <li>`maximizeConversionValue`：在预算内获得尽可能高的转化价值。</li>
  <li>`targetRoas` 搭配 `targetRoas`：同上，并以该广告支出回报率为目标，例如 `3.5` 表示 350%。</li>
</ul>

**euPoliticalAdvertising** `boolean` *required*

Google 要求每个活动都提供此声明。

**targeting.locations** `string[]`

Google 地理位置 ID，例如 `2840` 表示美国。省略此字段则定位所有地区。

**platformOptions.google** `object` *required*

**属性**

**finalUrl** `string` *required*

广告打开的 `http` 或 `https` 页面。

**assets** `object` *required*

您的文字和图片。每个列表中的各项必须互不相同。

**属性**

**headlines** `string[]` *required*

3 到 15 个，每个最多 30 个字符。

**longHeadlines** `string[]` *required*

1 到 5 个，每个最多 90 个字符。

**descriptions** `string[]` *required*

2 到 5 条，每条最多 90 个字符。至少有一条不得超过 60 个字符。

**businessName** `string` *required*

一个商家名称，最多 25 个字符。

**marketingImages** `string[]` *required*

1 到 20 个横向图片 URL：1.91:1，至少 600×314。

**squareMarketingImages** `string[]` *required*

1 到 20 个方形图片 URL：1:1，至少 300×300。

**logos** `string[]` *required*

1 到 5 个方形徽标 URL：1:1，至少 128×128。

**landscapeLogos** `string[]`

最多 4 个横向徽标 URL：4:1，至少 512×128。Google 最多接受徽标和横向徽标合计 5 个。

### 图片

Ayrshare 会从每个图片的 URL 下载图片，并在向 Google 发送任何内容之前对其进行检查：

<ul>
  <li>GIF、JPG 或 PNG 格式，每张最大 5120 KB。</li>
  <li>不小于上述最小尺寸，并符合其字段的宽高比（误差在 1% 以内）。</li>
  <li>所有图片合计最大 45 MB。</li>
  <li>URL 必须是公开的。私有地址会被拒绝。</li>
</ul>

未通过检查的图片会返回 `code: 101` 并指出该图片，例如 `platformOptions.google.assets.logos[0]: the image is 100x100; use at least 128x128.`

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11" \
-X POST https://api.ayrshare.com/api/ads/google/campaigns \
-d '{
  "accountId": "123-456-7890",
  "name": "Fall sale PMax",
  "type": "performanceMax",
  "budget": { "amount": 40, "type": "daily" },
  "bidding": { "strategy": "maximizeConversions" },
  "targeting": { "locations": ["2840"] },
  "euPoliticalAdvertising": false,
  "platformOptions": {
    "google": {
      "finalUrl": "https://example.com/fall-sale",
      "assets": {
        "headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
        "longHeadlines": ["Every running shoe 30% off this week only"],
        "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
        "businessName": "Acme Shoes",
        "marketingImages": ["https://example.com/images/fall-1200x628.png"],
        "squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
        "logos": ["https://example.com/images/logo-512.png"]
      }
    }
  }
}'
```

```javascript JavaScript theme={"system"}
const API_KEY = "API_KEY";

fetch("https://api.ayrshare.com/api/ads/google/campaigns", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11"
  },
  body: JSON.stringify({
    "accountId": "123-456-7890",
    "name": "Fall sale PMax",
    "type": "performanceMax",
    "budget": { "amount": 40, "type": "daily" },
    "bidding": { "strategy": "maximizeConversions" },
    "targeting": { "locations": ["2840"] },
    "euPoliticalAdvertising": false,
    "platformOptions": {
      "google": {
        "finalUrl": "https://example.com/fall-sale",
        "assets": {
          "headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
          "longHeadlines": ["Every running shoe 30% off this week only"],
          "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
          "businessName": "Acme Shoes",
          "marketingImages": ["https://example.com/images/fall-1200x628.png"],
          "squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
          "logos": ["https://example.com/images/logo-512.png"]
        }
      }
    }
  })
})
  .then((res) => res.json())
  .then((json) => console.log(json))
  .catch(console.error);
```

```python Python theme={"system"}
import requests

headers = {
    "Authorization": "Bearer API_KEY",
    "Idempotency-Key": "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11",
}

payload = {
  "accountId": "123-456-7890",
  "name": "Fall sale PMax",
  "type": "performanceMax",
  "budget": { "amount": 40, "type": "daily" },
  "bidding": { "strategy": "maximizeConversions" },
  "targeting": { "locations": ["2840"] },
  "euPoliticalAdvertising": False,
  "platformOptions": {
    "google": {
      "finalUrl": "https://example.com/fall-sale",
      "assets": {
        "headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
        "longHeadlines": ["Every running shoe 30% off this week only"],
        "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
        "businessName": "Acme Shoes",
        "marketingImages": ["https://example.com/images/fall-1200x628.png"],
        "squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
        "logos": ["https://example.com/images/logo-512.png"]
      }
    }
  }
}

r = requests.post("https://api.ayrshare.com/api/ads/google/campaigns", headers=headers, json=payload)

print(r.json())
```

```php PHP theme={"system"}
<?php
$payload = <<<'JSON'
{
  "accountId": "123-456-7890",
  "name": "Fall sale PMax",
  "type": "performanceMax",
  "budget": { "amount": 40, "type": "daily" },
  "bidding": { "strategy": "maximizeConversions" },
  "targeting": { "locations": ["2840"] },
  "euPoliticalAdvertising": false,
  "platformOptions": {
    "google": {
      "finalUrl": "https://example.com/fall-sale",
      "assets": {
        "headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
        "longHeadlines": ["Every running shoe 30% off this week only"],
        "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
        "businessName": "Acme Shoes",
        "marketingImages": ["https://example.com/images/fall-1200x628.png"],
        "squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
        "logos": ["https://example.com/images/logo-512.png"]
      }
    }
  }
}
JSON;

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/campaigns",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer API_KEY",
        "Content-Type: application/json",
        "Idempotency-Key: 0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11"
    ],
    CURLOPT_POSTFIELDS => $payload
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error: " . $err;
} else {
    echo $response;
}
?>
```

```csharp C# theme={"system"}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        var client = new HttpClient();
        client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
        client.DefaultRequestHeaders.Add("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11");

        var payload = """
            {
              "accountId": "123-456-7890",
              "name": "Fall sale PMax",
              "type": "performanceMax",
              "budget": { "amount": 40, "type": "daily" },
              "bidding": { "strategy": "maximizeConversions" },
              "targeting": { "locations": ["2840"] },
              "euPoliticalAdvertising": false,
              "platformOptions": {
                "google": {
                  "finalUrl": "https://example.com/fall-sale",
                  "assets": {
                    "headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
                    "longHeadlines": ["Every running shoe 30% off this week only"],
                    "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
                    "businessName": "Acme Shoes",
                    "marketingImages": ["https://example.com/images/fall-1200x628.png"],
                    "squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
                    "logos": ["https://example.com/images/logo-512.png"]
                  }
                }
              }
            }
            """;

        var response = await client.PostAsync(
            "https://api.ayrshare.com/api/ads/google/campaigns",
            new StringContent(payload, Encoding.UTF8, "application/json"));
        var content = await response.Content.ReadAsStringAsync();

        Console.WriteLine(content);
    }
}
```

```go Go theme={"system"}
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    payload := `{
  "accountId": "123-456-7890",
  "name": "Fall sale PMax",
  "type": "performanceMax",
  "budget": { "amount": 40, "type": "daily" },
  "bidding": { "strategy": "maximizeConversions" },
  "targeting": { "locations": ["2840"] },
  "euPoliticalAdvertising": false,
  "platformOptions": {
    "google": {
      "finalUrl": "https://example.com/fall-sale",
      "assets": {
        "headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
        "longHeadlines": ["Every running shoe 30% off this week only"],
        "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
        "businessName": "Acme Shoes",
        "marketingImages": ["https://example.com/images/fall-1200x628.png"],
        "squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
        "logos": ["https://example.com/images/logo-512.png"]
      }
    }
  }
}`

    req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/ads/google/campaigns", strings.NewReader(payload))
    req.Header.Add("Authorization", "Bearer API_KEY")
    req.Header.Add("Content-Type", "application/json")
    req.Header.Add("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}
```

```java Java theme={"system"}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class CreateCampaign {
    public static void main(String[] args) throws Exception {
        String payload = """
            {
              "accountId": "123-456-7890",
              "name": "Fall sale PMax",
              "type": "performanceMax",
              "budget": { "amount": 40, "type": "daily" },
              "bidding": { "strategy": "maximizeConversions" },
              "targeting": { "locations": ["2840"] },
              "euPoliticalAdvertising": false,
              "platformOptions": {
                "google": {
                  "finalUrl": "https://example.com/fall-sale",
                  "assets": {
                    "headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
                    "longHeadlines": ["Every running shoe 30% off this week only"],
                    "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
                    "businessName": "Acme Shoes",
                    "marketingImages": ["https://example.com/images/fall-1200x628.png"],
                    "squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
                    "logos": ["https://example.com/images/logo-512.png"]
                  }
                }
              }
            }
            """;

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.ayrshare.com/api/ads/google/campaigns"))
            .header("Authorization", "Bearer API_KEY")
            .header("Content-Type", "application/json")
            .header("Idempotency-Key", "0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11")
            .POST(HttpRequest.BodyPublishers.ofString(payload))
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
```

```ruby Ruby theme={"system"}
require 'net/http'
require 'uri'

uri = URI.parse('https://api.ayrshare.com/api/ads/google/campaigns')

request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer API_KEY'
request['Content-Type'] = 'application/json'
request['Idempotency-Key'] = '0b7a6f1c-2d4e-4c55-9a3e-2f8d1b7c9e11'
request.body = <<~JSON
  {
    "accountId": "123-456-7890",
    "name": "Fall sale PMax",
    "type": "performanceMax",
    "budget": { "amount": 40, "type": "daily" },
    "bidding": { "strategy": "maximizeConversions" },
    "targeting": { "locations": ["2840"] },
    "euPoliticalAdvertising": false,
    "platformOptions": {
      "google": {
        "finalUrl": "https://example.com/fall-sale",
        "assets": {
          "headlines": ["Fall sale", "Shoes 30% off", "Free returns"],
          "longHeadlines": ["Every running shoe 30% off this week only"],
          "descriptions": ["Every shoe 30% off this week.", "Free returns on every order."],
          "businessName": "Acme Shoes",
          "marketingImages": ["https://example.com/images/fall-1200x628.png"],
          "squareMarketingImages": ["https://example.com/images/fall-1200x1200.png"],
          "logos": ["https://example.com/images/logo-512.png"]
        }
      }
    }
  }
JSON

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

puts response.body
```

```json 200: Campaign Created theme={"system"}
{
  "status": "success",
  "platform": "google",
  "campaignId": "21534567891",
  "assetGroupId": "6512345678",
  "campaignStatus": "paused"
}
```

```json 200: Created, No Conversion Tracking theme={"system"}
{
  "status": "success",
  "platform": "google",
  "campaignId": "21534567891",
  "assetGroupId": "6512345678",
  "campaignStatus": "paused",
  "warnings": [
    "This Google Ads account has no conversion tracking. Performance Max optimizes for conversions, so Google may limit the campaign's spend until you set up conversion tracking in Google Ads."
  ]
}
```

```json 400: Image Too Small theme={"system"}
{
  "action": "request",
  "status": "error",
  "code": 101,
  "message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
  "details": "platformOptions.google.assets.logos[0]: the image is 100x100; use at least 128x128."
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.