---
# System prepended metadata

title: Google帳戶預算合約年度消耗統計討論
tags: [Ads API, Google Ads]

---

---
title: 'Google帳戶預算合約年度消耗統計討論'
disqus: hackmd
---
###### tags: `Ads API` `Google Ads`
Google帳戶預算合約年度消耗統計討論
===

[TOC]

## 參考連結
[BillingSetup](https://developers.google.com/google-ads/api/reference/rpc/v8/BillingSetup)
[account budget Report](https://developers.google.com/google-ads/api/fields/v8/account_budget#account_budget.name)

[account budget Reference](https://developers.google.com/google-ads/api/reference/rpc/v8/AccountBudget)

[GAQL Builder](https://developers.google.com/google-ads/api/fields/v8/query_validator)

[設定帳戶預算](https://support.google.com/google-ads/answer/2375395)

## 程式碼位置

放在google-account-budget-contract-annual-consumption-statistics的test package


## 此測試帳號的資訊


```java=
private static String MCCID = "825-849-0584";
private static String CID   = "398-786-8147";
```

## Campaign without segment 

```java=
String resultString=
"SELECT\r\n"
+ "  campaign.name,\r\n"
+ "  metrics.clicks\r\n"
+ "FROM campaign\r\n"
+ "WHERE segments.date > '2020-01-01'\r\n"
+ "  AND segments.date < '2021-10-01'";
```


![without segment](https://i.imgur.com/8m49r4o.png)


## Campaign with segment

```java=
String resultString=
"SELECT\r\n"
+ "  campaign.name,\r\n"
+ "  metrics.clicks,\r\n"
+ "  segments.date\r\n"
+ "FROM campaign\r\n"
+ "WHERE segments.date > '2020-01-01'\r\n"
+ "  AND segments.date < '2021-10-01'";
```

![ with segment](https://i.imgur.com/Qax40SU.png)

## account budget

```
String resultString="SELECT account_budget.id,account_budget.name,account_budget.approved_end_date_time,account_budget.amount_served_micros,account_budget.total_adjustments_micros "
+ "FROM "
+ "account_budget ";
```

![](https://i.imgur.com/yi25X5u.png)


## 幾個問題

1. QMAN說的兩種是哪兩種(先再說，先不用看)


2. 如何使用Campaign with segment 和 account budget做連結 就是Google doc裡面的impressions>0


3. 後臺怎看帳戶預算單以及花的錢

   以這組來舉例
```java=
private static String MCCID = "825-849-0584";
private static String CID   = "398-786-8147";
```
選擇帳單及預算
![](https://i.imgur.com/B7k8GUF.png)


4. > Fields from the above resources may be selected along with this resource in your SELECT and WHERE clauses. These fields **will not segment** metrics in your SELECT clause.所以這樣該怎麼樣去取得指定時間的預算

5. 該如何去抓日報表呢?

很簡單，報表 時間 日 結束這回合

![](https://i.imgur.com/Z492b2M.png)

## 解法


![](https://i.imgur.com/xYvJwWk.png)


直接去抓這個花費感覺最簡單



## 不用看
```java=
String resultString="SELECT account_budget.id,"
					+"account_budget.name,"
					+"account_budget.approved_end_date_time, "
//					+"account_budget.amount_served_micros,"
//					+"account_budget.total_adjustments_micros"
					+ "FROM account_budget";
```

## 和Robin的討論內容

1. 基本上withoutmetric指的是沒有perfomance可以撈的那種，像是account budget就是那種，另外通常withoutmetric也會無法下segment條件

2. 可以從兩種角度來撈取一個帳號到底花了多少錢

第一種是從account budget的角度

![](https://i.imgur.com/BBz1PCb.png)

```java=
String resultString="SELECT account_budget.id,account_budget.name,"
+ "account_budget.approved_start_date_time,account_budget.approved_end_date_time,account_budget.amount_served_micros,account_budget.total_adjustments_micros "
+ "FROM "
+ "account_budget ";
```

第二種是從customer的角度，可以下日期的where條件，從指定的開始日到結束日，一口氣把所有數字加起來


```java=
String resultString="SELECT metrics.impressions, metrics.cost_micros, metrics.cost_per_all_conversions, metrics.cost_per_conversion, metrics.clicks ,segments.date FROM customer WHERE segments.date >= '2021-08-18' AND segments.date < '2021-10-01' "
```


## 一些問題

1. 對齊

![](https://i.imgur.com/ewGBV27.png)

2. 預算單圖片示範

3. 流程圖 
