Posts tagged with adsense

I want to create a campaign through the Google Ads API. And I've successfully created a campaign. But when I compared it with the UI created one, I realized that I didn't choose a custom goal. In the UI I'll set it up like this. enter image description here

I can get all the custom goals via GAQL.

SELECT    custom_conversion_goal.resource_name,    custom_conversion_goal.id,    custom_conversion_goal.name,    custom_conversion_goal.conversion_actions,    custom_conversion_goal.status,    customer.id  FROM custom_conversion_goal  WHERE custom_conversion_goal.name='xxx' 

This is shown in the figure below.enter image description here

Now, I want to select the custom goal from the query while creating a campaign using google ads api.How should I write my python code?

Reference document link

Also, I've attached the sample code for the base campaign that I've successfully created, it's not much different from what's in the documentation.

import sys from google.ads.googleads.client import GoogleAdsClient from google.ads.googleads.errors import GoogleAdsException _DATE_FORMAT = "%Y%m%d" def handle_googleads_exception(exception):     print(         f'Request with ID "{exception.request_id}" failed with status '         f'"{exception.error.code().name}" and includes the following errors:'     )     for error in exception.failure.errors:         print(f'\tError with message "{error.message}".')         if error.location:             for field_path_element in error.location.field_path_elements:                 print(f"\t\tOn field: {field_path_element.field_name}")     sys.exit(1) def create_campaign(client, customer_id):     campaign_budget_service = client.get_service("CampaignBudgetService")     campaign_service = client.get_service("CampaignService")     campaign_budget_operation = client.get_type("CampaignBudgetOperation")     campaign_budget = campaign_budget_operation.create     ampaign_budget.amount_micros = 50000000     campaign_budget.explicitly_shared = False     campaign_budget_response = None     try:         campaign_budget_response = campaign_budget_service.mutate_campaign_budgets(             customer_id=customer_id, operations=[campaign_budget_operation]         )     except GoogleAdsException as e:         handle_googleads_exception(e)     campaign_operation = client.get_type("CampaignOperation")     campaign = campaign_operation.create     campaign.name = 'campaign-test1'     campaign.status = client.enums.CampaignStatusEnum.PAUSED campaign.tracking_url_template = "{...}"     campaign.advertising_channel_type = client.enums.AdvertisingChannelTypeEnum.DISPLAY     campaign.targeting_setting.target_restrictions.targeting_dimension = client.enums.TargetingDimensionEnum.AUDIENCE     campaign.targeting_setting.target_restrictions.bid_only = False     campaign.audience_setting.use_audience_grouped = False     campaign.geo_target_type_setting.positive_geo_target_type = client.enums.PositiveGeoTargetTypeEnum.PRESENCE     campaign.geo_target_type_setting.negative_geo_target_type = client.enums.NegativeGeoTargetTypeEnum.PRESENCE     campaign.target_cpa.target_cpa_micros = 100000     campaign.campaign_budget = campaign_budget_response.results[0].resource_name     # Setting the specified custom goal but with an error     # AttributeError: Unknown field for Campaign: conversion_goal_campaign_config     campaign.conversion_goal_campaign_config.custom_conversion_goal = "customers/xxxx/customConversionGoals/xxxxx"     try:         campaign_response = campaign_service.mutate_campaigns(             customer_id=customer_id, operations=[campaign_operation]         )         print(f"Created campaign {campaign_response.results[0].resource_name}.")     except GoogleAdsException as ex:         handle_googleads_exception(ex) if __name__ == '__main__':     googleads_client = GoogleAdsClient.load_from_storage(         path=r"./google-ads-th.yaml",         version="v17"     )     customer_id = "xxxx"     create_campaign(googleads_client, customer_id) 

I never found in the documentation how to select a custom goal when creating campaign.and I had to specify the campaign type as DISPLAY. It can't be a performance max campaign or an app campaign. Both campaigns can specify a custom goal. Because it is clearly stated in the documentation.

I want to add Google Analytics and Google Adsense to my website in NextJS. I found this official doc: https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries#google-tag-manager

According to this, its enough to add:

 <GoogleTagManager gtmId="GTM-XYZ" /> 

However, I have problem with understanding how Google adsense works. I know that google adsense require from me to include another script to my head (my account is not approved yet for google ads). The problem is that I want to let user decide whether he accepts analytics and advertisement cookies. I was going to simply remove GoogleTagManager from my head for analytics but what with advertsiement? I.e. I can't remove the Google Ads script because I dont want to remove ads at all so have can I distinguish between "personalized adverts" (user accepted cookies) and "not personalized" adverts? How should I construct my code to handle all cases?

I have implemented server-side tagging in in Google Tag Manager (GTM), but I'm sending HTTP requests directly from my backend code, rather than using JavaScript on the frontend (as many other developers). Since, the conversion tracking cookies set by Meta and Google aren't automatically sent when sending a HTTP request from my backend code, I am getting the _fbp and _fbc cookie values from the context and sending them as a "ep.x-fb-ck-fbp" and "ep.x-fb-ck-fbc" to the GTM server container, which allows me to track Facebook ads conversions successfully.

I am now looking to replicate this process for Google Ads. I understand that for Google Ads conversion tracking, the GCLID is a parameter that sets the _gcl_aw cookie which I should use to track conversion. However, I am not certain how to send this cookie value in the Http request that I'm sending from my server to the GTM server container.

In other words, if I'm sending the Meta's _fbc cookie value as a "ep.x-fb-ck-fbc" parameter, how should I send the Google's _gcl_aw and _gcl_au cookies.

I'm trying to send a google ads measurement conversion purchase event from my python backend.

I have the correct conversion lable and id.

class GoogleAds(Analytic): def __init__(self, data, shop_unique_id, event):     self.base_url = "https://www.googleadservices.com/pagead/conversion/{conversion_id}/"     super().__init__(data, shop_unique_id, event) def send_google_ads_event(self, payload):     try:         label = "label"         conversion_id = "id"         # for market in self.profile.markets:         #     if market_domain == market.domain:         #         ga4_measurement_id = market.ga4_measurement_id         #         ga4_api_secret = market.ga4_api_secret         if (             label != ""             and label is not None             and conversion_id != ""             and conversion_id is not None         ):             payload['conversion_id'] = conversion_id             payload['label'] = label             response = requests.get(self.base_url.format(conversion_id=conversion_id), params=payload)         # Check if the conversion was registered successfully         if response.status_code == 200 and response.headers.get('Content-Type') == 'image/gif':             log.info(                 "Finished sending data to Google ads",                 extra={                     "url": response.request.url,                     "sending_params": payload,                     "response_content_type": response.headers.get('Content-Type'),                     "status_code": response.status_code,                 },             )             return True         else:             log.error("Failed to send data to Google ads", extra={"status_code": response.status_code})             return False     except requests.RequestException as e:         log.error(f"Error sending data to Google ads: {e}")         return False 

This request returns status code 200, but on google ads measurements ui the count is still 0.

Payload looks like this

def purchase_data(webhook_data, shop_unique_id): transformed_items = [{     "id": item["product_id"],     "price": item["price"],     "quantity": item["quantity"] } for item in webhook_data["line_items"]] data = dict(     label="label",     value=float(webhook_data["total_price"]),     currency_code=webhook_data["currency"],     transaction_id=webhook_data["id"],     conversion_id="conversion_id",     items=transformed_items,     feed_country="GB",     merchant_id="merchant_id",     feed_language="GB" ) return data 

Any idea why that could be happening?

I deployed inside a docker a reactjs project (optimized build).

I added the required scripts to enable Google ADS but I got following message

It doesn't find the ads.txt file, I put it under the /public folder and re-built and re-deployed the docker but nothing.. do you have any suggestion for it?