Posts tagged with google-ad-manager

i am using google_mobile_ads: ^5.2.0 to display adds on my flutter app. I need to request and display 3 different sizes of banner ads from google.

This ad is supposed to be show in a scrollable column so i must set the height of it, the problem is that when the add is loaded i don't have the information about the loaded ad, it could be any of the three. If i don't set the height it is either hidden or there is an error that the height cannot be infinite.

note: in the snippet in only set the temporary size, because i don't know how to get the correct one.

 Future<void> loadAd() async {     _bannerAd = AdManagerBannerAd(         adUnitId: adUnitId,         request: const AdManagerAdRequest(),         sizes: [           const AdSize(width: 300, height: 100),           const AdSize(width: 300, height: 250),           const AdSize(width: 300, height: 600)         ],         listener: AdManagerBannerAdListener(           onAdLoaded: (ad) {             if (!mounted) {               ad.dispose();               return;             }             debugPrint('$ad loaded.');             setState(() {               _isLoaded = true;             });           },           onAdFailedToLoad: (ad, error) {             debugPrint('AdManagerBannerAd failed to load: $error');             ad.dispose();           },         ))       ..load();   }   @override   void dispose() {          _bannerAd?.dispose();     super.dispose();   }   @override   Widget build(BuildContext context) {     return _isLoaded && _bannerAd != null         ? Align(             alignment: Alignment.bottomCenter,             child: SafeArea(               child: SizedBox(                 width: _bannerAd!.sizes[0].width.toDouble(),                 height: _bannerAd!.sizes[0].height.toDouble(),                 child: AdWidget(ad: _bannerAd!),               ),             ),           )         : const SizedBox             .shrink();    } 

please help.

I have loaded google ads data to Big query using data transfer. I am trying to get keyword and search keyword metrics for my analysis

I used below code from p_ads_KeywordBasicStats table

WITH stats AS (   SELECT     campaign_id AS CampaignId,     ad_group_id AS AdGroupId,     ad_group_criterion_criterion_id AS CriterionID,     segments_ad_network_type AS AdNetworkType1,     metrics_clicks AS Clicks,     metrics_cost_micros AS Cost,     segments_date AS Date,     metrics_impressions AS Impressions   FROM `micro-reserve.google_ad.p_ads_KeywordBasicStats_xxxxxx    ), keywords AS (   SELECT     ad_group_criterion_criterion_id AS CriterionId,     MAX(ad_group_criterion_keyword_text) AS Criteria,     ad_group_criterion_negative,     ad_group_criterion_status   FROM `micro-reserve.google_ad.p_ads_Keyword_xxxxxxx      GROUP BY ad_group_criterion_criterion_id, ad_group_criterion_negative, ad_group_criterion_status ), campaigns AS (   SELECT     campaign_id,     MAX(campaign_name) AS campaign_name   FROM `micro-reserve.google_ad.p_ads_Campaign_xxxxx      GROUP BY campaign_id ) SELECT    Clicks,   Cost,   Date,   Impressions,   Criteria AS Keywords,   campaign_name,   ROUND(SAFE_DIVIDE(Clicks, Impressions) * 100, 2) AS CTR FROM stats LEFT JOIN keywords   ON stats.CriterionID = keywords.CriterionId LEFT JOIN campaigns   ON stats.CampaignId = campaigns.campaign_id WHERE keywords.ad_group_criterion_negative IS FALSE    AND keywords.ad_group_criterion_status = 'ENABLED'    AND Date BETWEEN '2024-09-01' AND '2024-09-13' 

========== Using below query for p_ads_SearchQueryStats table

WITH stats AS (   SELECT     campaign_id AS CampaignId,     ad_group_id AS AdGroupId,     ad_group_ad_ad_id AS CriterionID,     segments_ad_network_type AS AdNetworkType1,     SUM(metrics_clicks) AS Clicks,     SUM(metrics_cost_micros) AS Cost,     segments_date AS Date,     SUM(metrics_impressions) AS Impressions,     MAX(search_term_view_search_term) AS Criteria,     search_term_view_status   FROM `micro-reserve.google_ad.p_ads_SearchQueryStats_xxxxxx   WHERE _PARTITIONTIME = TIMESTAMP('2024-09-13')   GROUP BY ad_group_ad_ad_id, search_term_view_status, ad_group_id, campaign_id, segments_ad_network_type, segments_date ), campaigns AS (   SELECT     campaign_id,     MAX(campaign_name) AS campaign_name   FROM `micro-reserve=.google_ad.p_ads_Campaign_xxxxxxxx   WHERE _PARTITIONTIME = TIMESTAMP('2024-09-13')   GROUP BY campaign_id ) SELECT    campaigns.campaign_name,   stats.Date,   stats.Clicks,   stats.Impressions,   stats.Cost,   stats.Criteria AS Search_Keywords FROM stats LEFT JOIN campaigns   ON stats.CampaignId = campaigns.campaign_id WHERE stats.Date = '2024-09-13' 

The above query works, but the numbers are not matching with Google Ads. Is something I am doing wrong? Can anyone advise please?

I tried to fetch GCLID using campaign_id but I'm not able to find it.

I've explore over a network but can't find any way to find GCLID.

Currently I've such type of data :-

{             "campaign": {                 "resourceName": "customers/{customer_id}/campaigns/{campaign_id}",                 "status": "ENABLED",                 "name": "campaign_name"             },             "ad_account": "ad_account_id"         } 

I want GCLID with the help of any of above fields

Or informed me if there any other fields required to get GCLID.

Actual Requirement :-I'm storing leads which is comes through google ads , in that data I've store GCLID from URL parameters of the landing page where the user lands after clicking on the ad.

Lead store such like this in my Database :-

{   "_id": "652d453sd46453f45"   "lead_id": "652a2bd489a65bf1ad53618a",   "url_parameters": {     "tactic_id": "5907417",     "utm_source": "google-adwords",     "utm_medium": "Campaign_medium",     "utm_campaign": "Campaign_Name",     "utm_term": "TERM",     "device": "c",     "matchtype": "p",     "network": "g",     "gclid": "GCLID",     "gad": "1/lead"   },   "current_url": "URL/?tactic_id=5907417&utm_source=google-adwords&utm_medium=[Campaign_medium]&utm_campaign=[Campaign_Name]&utm_term=customer%20management%20tools&device=c&matchtype=p&network=g&gclid=[GCLID]&gad=1/contact", } 

So I'm displaying campaign impressions, clicks , etc.. so here i want to show how many leads come through this campaign, so for this campaign first i've to find GCLID and then I'll fetch leads which is attributed in my DATABASE with the help of using this GCLID.

I'm building a Chrome extension for educational purposes that removes/replaces a GoogleAds div with my custom div.

How do I locate the google-ad divs? Is there a specific id or class associated with it?

This is how I'm injecting my code into the website:--

content-script.js

var div=document.createElement("div"); // is there any specific divID associated with it? document.body.appendChild(div);  div.innerText="test123"; 

EDIT 1

Updating the structure as requested by @rabsom

<div class="q-box qu-pb--small" style="box-sizing: border-box;">    <div class="q-box qu-cursor--pointer dom_annotate_google_ad" id="div-gpt-ad-1633993162946-0-init-a" style="box-sizing: border-box;" data-google-query-id="CNy0k-Dxiv8CFYCFZgId2jkKvA">       <div id="google_ads_iframe_/21680945556/li_stick_home_and_ad_react_0__container__" style="border: 0pt none; margin: auto; text-align: center; width: 300px; height: 250px;">         <iframe frameborder="0" src="https://515625e180dff516c1055c5fa3af1b19.safeframe.googlesyndication.com/safeframe/1-0-40/html/container.html" id="google_ads_iframe_/21680945556/li_stick_home_and_ad_react_0" title="3rd party ad content" name="" scrolling="no" marginwidth="0" marginheight="0" width="300" height="250" data-is-safeframe="true" sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" role="region" aria-label="Advertisement" tabindex="0" data-google-container-id="1" style="border: 0px; vertical-align: bottom;" data-load-complete="true"></iframe>       </div>    </div> </div> 

EDIT 2

I'm able to use the googletag now. However, it shows up after the ads have been loaded. So, I wait for the DOM to be loaded completely.

document.addEventListener('readystatechange', event => {     if (event.target.readyState === "complete") {         for (i = 0; i < googletag.pubads().getSlots().length; i++) {             var slotDomId = googletag.pubads().getSlots()[i].getSlotElementId();             document.getElementById(slotDomId).innerHTML = '<h1>yourcustomInnerHTML</h1>';         }     } }); 

I try the above code, but even after the DOM has been loaded, it shows googletag as undefined.

I need to load a Portrait Full-screen native ad.

I have set the nativeAdOptions like these
val nativeAdOptions = NativeAdOptions.Builder().setMediaAspectRatio(MediaAspectRatio.PORTRAIT).build()

and load the ad like this

AdLoader.Builder(context, adUnitId).withNativeAdOptions(nativeAdOptions) 

Even I set the MediaAspectRatio to MediaAspectRatio.PORTRAIT. I am getting landscape ads.

Is there any issue with Google Ad Manager SDK or Do I need to specify any extra AdOptions?