> ## 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 活动，请使用 `level=campaign` 并提供活动 ID。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` | 每千次展示费用。没有展示的日期为 `null` |
| `cpc` | number 或 `null` | 每次点击费用。没有点击的日期为 `null` |
| `ctr` | number 或 `null` | 点击率，以百分比表示。没有展示的日期为 `null` |
| `actions` | number | Google 的转化次数，可以是小数 |
| `conversionValue` | number | 这些转化的价值 |

在您的 Google Ads 账户中设置转化跟踪之前，`actions` 和 `conversionValue` 都保持为 `0`。`reach` 不可用，因为 Google 不报告搜索广告的唯一覆盖人数；`breakdowns` 在 Google 上也不可用。请求其中任何一项都会返回 `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.