Posts tagged with google-ads-api

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've been working on this google ads script to email a csv to me. It queries the ad words api for data, writes it to a spreadsheet, reads it from the spreadsheet, iterates through the rows to create a csv string, creates a blob and sends the email.

The reason it writes/reads to a spreadsheet is to get the data in the correct format. I'm not sure there is a better way.

The problem is that it will not create the blob. It fails with this error:

Exception: Unexpected error while getting the method or property newBlob on object Utilities. (line 53) 

I've looked online and can not find much on this error. I've tried removing arguments on the newBlob statement, sending the raw csv string, etc. Nothing seems to work and I can't figure out why creating the blob fails.

const SS_ID = '1_super_secret_id_Q'; const SS_NAME = 'GCLID Report'; const SHEET_NAME = 'DURING YESTERDAY' const EMAIL_TO = 'c_super_secret_email_g' const MILLIS_PER_DAY = 1000 * 60 * 60 * 24; function collect_report() {   return AdsApp.report(     'SELECT                ' +     '  click_view.gclid,   ' +     '  segments.date,      ' +     '  customer.id,        ' +     '  ad_group.id,        ' +     '  campaign.id         ' +     'FROM click_view       ' +     'WHERE segments.date DURING YESTERDAY'   ); } function calculate_yesterday() {   var now = new Date();   var yesterday = new Date(now.getTime() - MILLIS_PER_DAY);   var timeZone = AdsApp.currentAccount().getTimeZone();   var yesterday_str = Utilities.formatDate(yesterday, timeZone, 'yyyy-MM-dd');   return yesterday_str; } function convert_sheet_to_csv(sheet) {   var csv_data = '';      // This represents ALL the data.   var range = sheet.getDataRange();   var values = range.getValues();   // This logs the spreadsheet in CSV format.   for (let i = 0; i < values.length; i++) {     csv_data += (values[i].join(',')) + '\r\n';   } } function main() {   var report = collect_report();   var spreadsheet = SpreadsheetApp.openById(SS_ID);   var sheet = spreadsheet.getSheetByName(SHEET_NAME);      sheet.clearContents();   report.exportToSheet(sheet);   var mime = 'text/plain'   var yesterday_str = calculate_yesterday();   var filename = 'gclid_report.csv';   var csv_data = convert_sheet_to_csv(sheet);   var blob = Utilities.newBlob(csv_data, mime, filename);   var email_subject = 'Your Google Ads Report Is Ready: GCLID Report';   var email_body = 'Attached is the ' + filename;   MailApp.sendEmail(     EMAIL_TO,     email_subject,     email_body,     {         name: 'Automatic Emailer Script',         attachments: [blob]     }   ); } main(); 

I'm trying to put advertisements on my app, I put my app on amazon app store and then approved by google admob I set up Ad Unit ID (next level promotion) and put in both the xml and java part the appropriate code for it to work however I still don't get any Ad bar on the home of my app. Does anyone have any idea why it doesn't come up?

Java:

   ` MobileAds.initialize(this, initializationStatus -> {});     // Create an AdView and set the ad unit ID and ad size     adView = new AdView(this);     adView.setAdUnitId("*******");      adView.setAdSize(AdSize.BANNER);     // Add the AdView to your layout     LinearLayout adContainer = findViewById(R.id.ad_container);     if (adContainer != null) {         adContainer.addView(adView);         // Load an ad         AdRequest adRequest = new AdRequest.Builder().build();         adView.loadAd(adRequest);     }` 

XML:

       `<com.google.android.gms.ads.AdView         android:id="@+id/ad_container"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_alignParentBottom="true"         app:adSize="BANNER"         app:adUnitId="***" />`