• Google Ads API —— reporting & Google Ads Query Language (GAQL)


    https://developers.google.com/google-ads/api/docs/reporting/overview

    This guide describes the steps necessary to create and submit a query to the Google Ads API to get back data. To get started, jump to the section that best fits your use case:

    https://developers.google.com/google-ads/api/docs/reporting/criteria-metrics

    In the AdWords API, you can retrieve performance data (metrics) for different criteria from various reports (e.g., the Keywords Performance Report or the Age Range Performance Report).

    To provide similar functionality in Google Ads API, each criteria report is represented by a separate resource. For example, data similar to the Keywords Performance Report is available in the keyword_view resource. Unless absolutely necessary, *_view resources will only contain a resource_name field.

    Google Ads API clients will need to specify corresponding ad_group_criterion or campaign_criterion fields if any criteria specific data needs to be fetched. This will allow Google Ads API clients to request ad_group_criterion or campaign_criterion fields and the *_view resource in the same request to the GoogleAdsService.SearchStream method.

    SELECT
      ad_group_criterion.keyword.text,
      ad_group.name,
      campaign.name,
      metrics.impressions,
      metrics.clicks,
      metrics.ctr,
      metrics.average_cpc
    FROM keyword_view
    WHERE segments.date DURING LAST_30_DAYS

    https://developers.google.com/google-ads/api/docs/reporting/example

    We now take a look at a common use case: summarizing the performance of an account over the last 30 days by campaign, segmented by device. The query for this report is as follows:

     
    SELECT
      campaign.name,
      campaign.status,
      segments.device,
      metrics.impressions,
      metrics.clicks,
      metrics.ctr,
      metrics.average_cpc,
      metrics.cost_micros
    FROM campaign
    WHERE segments.date DURING LAST_30_DAYS

    To issue this request, pass the Google Ads Query Language statement above to the GoogleAdsService.SearchStream interface.

    HTTP request URL

    The request consists of an HTTP POST to the Google Ads API server at the following URL:

     
    https://googleads.googleapis.com/v9/customers/{customer_id}/googleAds:searchStream

    Complete HTTP request sample

    Here is a complete example of the report definition above, enclosed in an HTTP POST request.

     
     
    POST /v9/customers/{customer_id}/googleAds:searchStream HTTP/1.1
    Host: googleads.googleapis.com
    User-Agent: curl
    Content-Type: application/json
    Accept: application/json
    Authorization: Bearer [Enter OAuth 2.0 access token here]
    developer-token: [Enter developerToken here]
    
    Parameters:
    {
      "query" : "SELECT campaign.name, campaign.status, segments.device,
                        metrics.impressions, metrics.clicks, metrics.ctr,
                        metrics.average_cpc, metrics.cost_micros
                FROM campaign
                WHERE segments.date DURING LAST_30_DAYS"
    }
    

    https://developers.google.com/google-ads/api/docs/query/overview

    Google Ads Query Language Grammar

    Here is the Google Ads Query Language grammar reference (in regular expression notation):

     
    Query            -> SelectClause FromClause WhereClause? OrderByClause? LimitClause? ParametersClause?
    SelectClause     -> SELECT FieldName (, FieldName)*
    FromClause       -> FROM ResourceName
    WhereClause      -> WHERE Condition (AND Condition)*
    OrderByClause    -> ORDER BY Ordering (, Ordering)*
    LimitClause      -> LIMIT PositiveInteger
    ParametersClause -> PARAMETERS Literal = Value (, Literal = Value)*

    Condition        -> FieldName Operator Value
    Operator         -> = | != | > | >= | < | <= | IN | NOT IN |
                        LIKE | NOT LIKE | CONTAINS ANY | CONTAINS ALL |
                        CONTAINS NONE | IS NULL | IS NOT NULL | DURING |
                        BETWEEN | REGEXP_MATCH | NOT REGEXP_MATCH
    Value            -> Literal | LiteralList | Number | NumberList | String |
                        StringList | Function
    Ordering         -> FieldName (ASC | DESC)?

    FieldName        -> [a-z] ([a-zA-Z0-9._])*
    ResourceName     -> [a-z] ([a-zA-Z_])*

    StringList       -> ( String (, String)* )
    LiteralList      -> ( Literal (, Literal)* )
    NumberList       -> ( Number (, Number)* )

    PositiveInteger  -> [1-9] ([0-9])*
    Number           -> -? [0-9]+ (. [0-9] [0-9]*)?
    String           -> (' Char* ') | (" Char* ")
    Literal          -> [a-zA-Z0-9_]*

    Function         -> LAST_14_DAYS | LAST_30_DAYS | LAST_7_DAYS |
                        LAST_BUSINESS_WEEK | LAST_MONTH | LAST_WEEK_MON_SUN |
                        LAST_WEEK_SUN_SAT | THIS_MONTH | THIS_WEEK_MON_TODAY |
                        THIS_WEEK_SUN_TODAY | TODAY | YESTERDAY

    Query Structure

    Queries for resource, segment, and metric fields can be sent to GoogleAdsService Search or SearchStream methods. To construct a query in Google Ads Query Language, you will need to build it using the language grammar. A query is made up of a number of clauses:

    • SELECT
    • FROM
    • WHERE
    • ORDER BY
    • LIMIT
    • PARAMETERS

    Clauses use field names, resource names, operators, conditions, and orderings to help you select the correct data. Once combined into a single query, a request can be made using Google Ads API.

    Report Streaming

    There are three methods for retrieving entities and reporting data with the Google Ads API.

    This guide primarily focuses on streaming data from GoogleAdsService. Here are high-level distinctions for the three data retrieval methods:

    While Search can send multiple paginated requests to download the entire report, SearchStream sends a single request and initiates a persistent connection with the Google Ads API regardless of report size.

    For SearchStream, data packets start to download immediately with the entire result cached in a data buffer. Your code can start reading the buffered data without having to wait for the entire stream to finish.

    By eliminating the round-trip network time required to request each individual page of a Search response, depending on your app, SearchStream can offer improved performance over paging, especially for bigger reports. The following table exemplifies the accounting differences.

    Performance factors

    In general, we recommend SearchStream over Search for the following reasons.

    • For single page reports (under 10,000 rows): No significant performance differences between the two methods.

    • For multiple page reports: SearchStream is typically faster since multiple roundtrips are avoided and reading/writing from disk cache is less of a factor.

    Rate limits

    Daily limits for both methods adhere to the standard limits and access levels of your developer token. A single query or report is counted as one operation regardless of the result being paged or streamed.

    https://developers.google.com/google-ads/api/docs/reporting/uireports

    Columns in the UI are equivalent to Resource fields, Segment fields, and Metrics in GAQL.

     
  • 相关阅读:
    MYSQL-------安全等于<=>
    MYSQL-------转义简单说明
    Linux命令 sed
    长目录如何快速cd
    SQLAlchemy(增删改查)
    PostgreSQL主键约束混乱
    Python实现智能回复
    Python 腾讯云发送短信
    Python3 Twilio 发送短信
    Elasticsearch 多条件查询
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/15792883.html
Copyright © 2020-2023  润新知