> ## 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 Ads 指標，包含點擊次數、費用、轉換次數與轉換價值。

即時取得您透過 Ayrshare 建立的廣告活動、廣告群組或廣告的 Google Ads 成效，每天一列。

<ul>
  <li>數據會在您呼叫時從 Google 讀取，而不是來自每晚製作的副本。</li>
  <li>所有金額皆以廣告帳戶的貨幣計算，並在每一列的 `currency` 中返回。</li>
  <li>Google 會省略沒有活動的日期，因此一個日期範圍返回的列數可能少於其天數。</li>
  <li>Google 會在某天結束後的幾天內調整該天的費用及轉換次數，因此最近幾天的數據在不同次讀取之間可能會有所變動。</li>
  <li>對於 Performance Max 廣告活動，請搭配廣告活動 ID 使用 `level=campaign`。Performance Max 廣告活動本身沒有廣告，因此 `level=ad` 不會返回任何列。</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`

## 查詢參數

**level** `string` *required*

每一列報告的對象：`campaign`（建立時返回的 `campaignId`）、`adSet`（建立時返回的 `adGroupId`）或 `ad`（建立時返回的 `adId`）。

**ids** `string` *required*

以逗號分隔的廣告活動、廣告群組或廣告 ID，最多 50 個。它們必須全部屬於同一個廣告帳戶。

**accountId** `string`

10 位數的 Google Ads 客戶 ID，可包含或不含連字號（`123-456-7890`）。

廣告及廣告群組報表會讀取您在此指定的廣告帳戶。若未指定，廣告報表會搜尋您的 Google Ads 連結可觸及的所有廣告帳戶，最多 25 個；廣告群組報表僅在您的連結只觸及一個廣告帳戶時才能運作。當您的連結觸及超過 25 個廣告帳戶，或在廣告群組報表中觸及超過一個帳戶時，請指定帳戶。否則請求會返回 `code: 101`。

**metrics** `string`

以逗號分隔的要返回的指標。省略則返回所有指標。請參閱 [指標](#metrics)。

**startDate** `string` (default: 30 天前)

第一天，格式為 `YYYY-MM-DD`。Google 會保留 37 個月的每日數據；更早的 `startDate` 會返回 `code: 101`。

**endDate** `string` (default: 今天)

最後一天，格式為 `YYYY-MM-DD`。

## 指標

| 指標 | 類型 | 說明 |
| - | - | - |
| `spend` | number | 支出金額 |
| `impressions` | number | 廣告的顯示次數 |
| `clicks` | number | 點擊次數 |
| `cpm` | number 或 `null` | 每 1,000 次曝光的費用。沒有曝光的日子為 `null` |
| `cpc` | number 或 `null` | 每次點擊的費用。沒有點擊的日子為 `null` |
| `ctr` | number 或 `null` | 點擊率，以百分比表示。沒有曝光的日子為 `null` |
| `actions` | number | Google 的轉換次數，可能包含小數 |
| `conversionValue` | number | 這些轉換的價值 |

在您的 Google Ads 帳戶設定轉換追蹤之前，`actions` 和 `conversionValue` 都會維持為 `0`。無法使用 `reach`，因為 Google 不提供搜尋廣告的不重複觸及人數；Google 也不提供 `breakdowns`。要求其中任一項都會返回 `code: 101`。

## 分頁

所有列都會在同一個回應中返回，因此 `nextCursor` 一律為 `null`。

## 錯誤

| 代碼 | 發生情況 |
| - | - |
| `101` | 缺少參數或參數錯誤、不支援某個指標或細分維度、`startDate` 早於 37 個月前、傳送了超過 50 個 ID、ID 分屬多個廣告帳戶，或需要 `accountId` 但未提供 |
| `400` | 廣告活動、廣告群組或廣告不屬於您，或 `accountId` 不是 Ayrshare 為您所傳送的 ID 所記錄的廣告帳戶 |
| `370` | Google 無法返回洞察報告。請再試一次 |

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-X GET "https://api.ayrshare.com/api/ads/google/insights?level=campaign&ids=21534567890&startDate=2026-10-01&endDate=2026-10-07"
```

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

fetch("https://api.ayrshare.com/api/ads/google/insights?level=campaign&ids=21534567890&startDate=2026-10-01&endDate=2026-10-07", {
  method: "GET",
  headers: {
    "Authorization": `Bearer ${API_KEY}`
  }
})
  .then((res) => res.json())
  .then((json) => console.log(json))
  .catch(console.error);
```

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

headers = {
    "Authorization": "Bearer API_KEY",
}

r = requests.get("https://api.ayrshare.com/api/ads/google/insights?level=campaign&ids=21534567890&startDate=2026-10-01&endDate=2026-10-07", headers=headers)

print(r.json())
```

```php PHP theme={"system"}
<?php
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/insights?level=campaign&ids=21534567890&startDate=2026-10-01&endDate=2026-10-07",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer API_KEY"
    ]
]);

$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.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        var client = new HttpClient();
        client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");

        var response = await client.GetAsync("https://api.ayrshare.com/api/ads/google/insights?level=campaign&ids=21534567890&startDate=2026-10-01&endDate=2026-10-07");
        var content = await response.Content.ReadAsStringAsync();

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

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

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

func main() {
    req, _ := http.NewRequest("GET", "https://api.ayrshare.com/api/ads/google/insights?level=campaign&ids=21534567890&startDate=2026-10-01&endDate=2026-10-07", nil)
    req.Header.Add("Authorization", "Bearer API_KEY")

    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 GetAdInsights {
    public static void main(String[] args) throws Exception {
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.ayrshare.com/api/ads/google/insights?level=campaign&ids=21534567890&startDate=2026-10-01&endDate=2026-10-07"))
            .header("Authorization", "Bearer API_KEY")
            .GET()
            .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/insights?level=campaign&ids=21534567890&startDate=2026-10-01&endDate=2026-10-07')

request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer API_KEY'

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

puts response.body
```

```json 200: Success theme={"system"}
{
  "status": "success",
  "platform": "google",
  "level": "campaign",
  "startDate": "2026-10-01",
  "endDate": "2026-10-07",
  "insights": [
    {
      "date": "2026-10-01",
      "level": "campaign",
      "id": "21534567890",
      "currency": "USD",
      "spend": 12.48,
      "impressions": 1830,
      "clicks": 41,
      "cpm": 6.82,
      "cpc": 0.3,
      "ctr": 2.2404,
      "actions": 3.5,
      "conversionValue": 140
    }
  ],
  "count": 1,
  "nextCursor": null
}
```


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