> ## 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 廣告活動。您傳送文字和圖片網址；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>新廣告活動預設以 `paused` 狀態開始，除非您傳送 `status: "active"`。</li>
  <li>預算為每日預算，使用廣告帳戶的幣別，且絕不會與其他廣告活動共用。</li>
  <li>其他幣別的支出會依 Open Exchange Rates 提供的當日匯率換算為 USD 計費。使用無法換算之幣別的帳戶會在建立任何項目之前返回 `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 個橫向圖片網址：1.91:1，至少 600×314。

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

1 到 20 個正方形圖片網址：1:1，至少 300×300。

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

1 到 5 個正方形標誌網址：1:1，至少 128×128。

**landscapeLogos** `string[]`

最多 4 個橫向標誌網址：4:1，至少 512×128。Google 最多接受標誌與橫向標誌合計 5 個。

### 圖片

Ayrshare 會從每個圖片網址下載圖片，並在傳送任何內容至 Google 之前進行檢查：

<ul>
  <li>GIF、JPG 或 PNG 格式，每個最多 5120 KB。</li>
  <li>至少達到上方所列的最小尺寸，且符合其欄位的長寬比（誤差 1% 以內）。</li>
  <li>所有圖片合計最多 45 MB。</li>
  <li>網址必須是公開的。私人位址會遭拒絕。</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.