Mutiply two column values in GoogleAds API V10

typicallyl in sql, you can use * to mutiply columns, but I am getting an error when trying to do so in my query below within GoogleAds API – anyone face this challenge before.

Code:

import sys, json, io, gzip, sys, os
from googleads import adwords
import pandas as pd
import numpy as np


def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):
  ga_service = client.get_service("GoogleAdsService")
  search_request=client.get_type("SearchGoogleAdsStreamRequest")
  search_request.customer_id = customer_id
 
  query = """
        SELECT
          segments.date,
          ad_group.id,
          ad_group.name,
          campaign.id,
          campaign.name,
          metrics.impressions,
          metrics.clicks,
          metrics.clicks*metrics.average_cpc as cost,
          metrics.conversions,
          metrics.ctr,
          metrics.average_cpc,
          metrics.cost_per_conversion




        FROM ad_group
        where segments.date BETWEEN 20220427 AND 20220428 
        
        limit 10
        """
             
  print(query)
  search_request.query = query
  
  stream = ga_service.search_stream(search_request)
  
  for batch in stream:
    for row in batch.results:
      print(row)      
  return 1

Error:

Request made: , Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId: TevDX_z7WYF-AWUZBMVbnw, IsFault: True, FaultMessage: Error in query: unexpected input *.
Traceback (most recent call last):

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Arithmetic operations are not supported in GAQL. You’ll need to perform these calculations on the client side after you have downloaded the data.

For your specific example, it might be possible to just use metrics.cost_micros as cost instead of metrics.clicks*metrics.average_cpc as cost.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x