Posts tagged with google-ads-script

I've run into an issue with the Google Ads Query Validator and need some help debugging.

  * API Version: v10

  * Query: "SELECT customer.id, metrics.impressions FROM group_placement_view WHERE group_placement_view.placement_type IN ("YOUTUBE_CHANNEL") AND (metrics.impressions + metrics.average_cpm) > 1000000"

  * Result: Invalid Query (errors below)

    * The filtering condition '(metrics.impressions + metrics.average_cpm) > 1000000' in the WHERE clause is not valid. Filtering conditions must take the form of 'field operator operand'. The operators IS NULL and IS NOT NULL take no operand.

  * Link to query result: https://gaql-query-builder.uc.r.appspot.com/v10/share?q=SELECT%20customer.id%2C%20metrics.impressions%20FROM%20group_placement_view%20WHERE%20group_placement_view.placement_type%20IN%20(%22YOUTUBE_CHANNEL%22)%20AND%20(metrics.impressions%20%2B%20metrics.average_cpm)%20%3E%201000000

  * Expected result: Using SQL, I can do arithmetic operation in the "WHERE" clause. This syntax is not valid for GAQL?

How can I filter group_placements WHERE the spend is above X ? There is no metric "spend" or "cost"

I thought to use: (all_conversions * cost_per_all_conversions)

I have this GAQL:

  var query = 'SELECT \     customer.id,\     customer.descriptive_name,\     group_placement_view.placement_type,\     group_placement_view.display_name,\     metrics.average_cpm\  FROM group_placement_view\  WHERE\     group_placement_view.placement_type IN ("YOUTUBE_CHANNEL")\     AND campaign.advertising_channel_type = "VIDEO"\     AND segments.date BETWEEN "'+ fromDate.query_date + '" AND "' + toDate.query_date + '"\     AND metrics.impressions >= 100\     AND metrics.average_cpm > 1000000' 

IIUC it segments data by days. Correct? segments.date

But the metrics.impressions >= 100 relates to the aggregated data of the whole period. Right?

I am using python to execute the query and retrieve the data from Google Ads I am trying to set start and end date as variable and use these in my query.

The query looks like this:

GAquery = """ SELECT     segments.date,     segments.device,     campaign.name,     metrics.clicks,     metrics.conversions,     metrics.conversions_value,     metrics.cost_micros,     metrics.impressions FROM    campaign WHERE segments.date >= '2021-12-01' AND segments.date <= '2022-02-27' ORDER BY     metrics.clicks DESC""" 

and it is executed by Google Function for Python

response = ga_service.search_stream(customer_id=customer_id, query=GAquery) 

This function does not have element params where i could use %s as placeholder in the query and then call it in params regular execute(sql,conn, params[Sdate,Edate] function in python.

So what i need to do is somehow break the query string, and add the dates in between. Something like this:

sdate = (dt.date.today() - dt.timedelta(days=60)) edate = dt.date.today() GAquery = """ SELECT     segments.date,     segments.device,     campaign.name,     metrics.clicks,     metrics.conversions,     metrics.conversions_value,     metrics.cost_micros,     metrics.impressions FROM    campaign WHERE segments.date """ + """>= """+ str(sdate) +""" AND segments.date""" +  """<=""" +str(edate) + """ ORDER BY     metrics.clicks DESC""" 

So basically i am trying to force variables into GAquery by breaking the query apart inserting it and stitching it together.

It is failing because i am not breaking it correctly and not adding it back together correctly.

Any idea how to handle this?

Could you please confirm GQAL doesn't support compound WHERE clause?

 FROM group_placement_view\  WHERE\     metrics.impressions >= 10000 \     AND (metrics.video_view_rate < 10' OR metrics.average_cpm > 10000 ) 

and not event OR as non-compound clause?

    metrics.average_cpm\  FROM group_placement_view\  WHERE\     metrics.impressions >= 10000 \     OR metrics.video_view_rate < 10' 

I am using a third-party tool that use the Adwords Reporting https://developers.google.com/adwords/api/docs/appendix/reports/all-reports to retrieve data.

At the moment all the "Performance Max" campaigns are lost from the Adwords Reporting and I need to retrieve them to include their costs. With the migration from Adwords to Ads, also, I need to find a solution before April 2022.

I only need to move that data into my Google BigQuery project.

At the moment the solution using the BigQuery Data Transfer is NOT OK because use the same v201809 reporting of Adwords ( https://cloud.google.com/bigquery-transfer/docs/adwords-transfer?hl=en-GB ) .

Also the Google Ads Script don't support Google Ads but only report name of Adwords v201809 ( https://developers.google.com/google-ads/scripts/docs/solutions/bigquery-exporter )

Do you have a suggestion to help me? Thanks