Posts tagged with google-ads-api

I am trying to implement Google ads enhanced conversions. I have the option of doing it using the gtag, google tag manager or using the Ads api. However, On the Ads api I don't see any documentation related to Node Js. I am not able to figure out how I can make use of the Ads api to implement enhanced conversions with Node Js.

This is the official documentation for enhanced conversion using Ads api and i don't see anything related to Node Js

https://developers.google.com/google-ads/api/docs/conversions/enhance-conversions

client_id, client_secret, developer_token = settings.CLIENT_ID, settings.CLIENT_SECRET, settings.DEVELOPER_TOKEN credentials = oauth2.GoogleRefreshTokenClient(     client_id,     client_secret,     login_user.refresh_token ) client = GoogleAdsClient(credentials, settings.DEVELOPER_TOKEN) click_conversion = client.get_type("ClickConversion") conversion_action_service = client.get_service("ConversionActionService") click_conversion.conversion_action = (     conversion_action_service.conversion_action_path(         client_id, company.conversion_name     ) ) click_conversion.gclid = deal.gclid click_conversion.conversion_value = float(deal.deal_value if deal.deal_value else 0) click_conversion.conversion_date_time = make_aware(datetime.now()).strftime('%Y%m%d %H%M%S %z') conversion_upload_service = client.get_service("ConversionUploadService") request = client.get_type("UploadClickConversionsRequest") request.customer_id = client_id request.conversions.append(click_conversion) request.partial_failure = True conversion_upload_response = (     conversion_upload_service.upload_click_conversions(         request=request,     ) ) 

Does anyone know why I'm getting the above error when trying to Upload Clicks to google ads? got this in the logs:

Request made: ClientCustomerId: xxxxxx-xxxxx.apps.googleusercontent.com, Host: googleads.googleapis.com, Method: /google.ads.googleads.v11.services.ConversionUploadService/UploadClickConversions, RequestId: None, IsFault: True, FaultMessage: Getting metadata from plugin failed with error: 'GoogleRefreshTokenClient' object has no attribute 'before_request'

I'm try to create new conversion action that the value in UI will be "Use different values for each conversion"

I'm using add_conversion_action.py from example. In the value_settings I set:

value_settings.default_value = 0.0 value_settings.always_use_default_value = True 

But in the UI I got "Don't use a value for this conversion action (not recommended)"

I try to look for answer on developers.google but all looks fine.

Thanks!

The code from example:

# [START add_conversion_action] def main(client, customer_id):     conversion_action_service = client.get_service("ConversionActionService")     # Create the operation.     conversion_action_operation = client.get_type("ConversionActionOperation")     # Create conversion action.     conversion_action = conversion_action_operation.create     conversion_action.name = f"Earth to Mars Cruises Conversion {uuid.uuid4()}"     conversion_action.type_ = (         client.enums.ConversionActionTypeEnum.UPLOAD_CLICKS     )     conversion_action.category = (         client.enums.ConversionActionCategoryEnum.DEFAULT     )     conversion_action.status = client.enums.ConversionActionStatusEnum.ENABLED     conversion_action.view_through_lookback_window_days = 15     # Create a value settings object.     value_settings = conversion_action.value_settings     value_settings.default_value = 0.0     value_settings.always_use_default_value = True     # Add the conversion action.     conversion_action_response = (         conversion_action_service.mutate_conversion_actions(             customer_id=customer_id,             operations=[conversion_action_operation],         )     )     print(         "Created conversion action "         f'"{conversion_action_response.results[0].resource_name}".'     )     # [END add_conversion_action] 

customer_service = client.get_service("CustomerService") app_list = customer_service.list_accessible_customers().resource_names def customer_query(client, customer_id):     ga_service = client.get_service("GoogleAdsService")     query = """         SELECT             customer.descriptive_name,             customer.currency_code         FROM customer         LIMIT 1"""     request = client.get_type("SearchGoogleAdsRequest")     request.customer_id = customer_id     request.query = query     response = ga_service.search(request=request)     customer = list(response)[0].customer     return customer for entry in app_list:     customer_id = entry.split('/')[1]     entry = customer_query(client, customer_id)     formatted_entry = {'customer_id': customer_id, 'name': entry.descriptive_name, 'currency': entry.currency_code}     apps.append(formatted_entry) return apps 

This seems really convoluted and I'm having to pass around a lot more data than I'd like. Surely there should be a way to just request the details.

I've been using 2 REST API calls to batch upload google offline click conversions. One generates the Access Token. The other is the API call to upload the offline click conversions.

All was well for a few weeks until suddenly we started getting invalid_grant messages in the JSON when trying to generate the Access Token. No clue why -- and we received no email or anything from Google on this. It just stopped working and the invalid_grant error was cryptic and the online help didn't explain much.

I resolved this issue by following this video to generate a new Refresh Token in the Google oAuth Playground:

https://youtu.be/KFICa7Ngzng

So, my question is -- can we automate this somehow? I can trap the invalid_grant JSON response and then would like to do some series of REST API calls to generate a new Refresh Token. Or, would I need to switch from a Web Application Type to a Service Account Type on the oAuth?

I also researched what might have caused the Refresh Token to expire. I looked at the following page and none of those bullet items applied to my situation:

https://developers.google.com/identity/protocols/oauth2#expiration