Posts tagged with javascript

I have this script set up but I am getting a 404 what do I need to do to make sure I can call the API?

const scriptProperties = PropertiesService.getScriptProperties(); function GIdea(keywords = "Demo") {     var accessToken = getOAuthToken();      var CLIENTID = scriptProperties.getProperty('CLIENTID');     var endpoint = 'https://googleads.googleapis.com/v10/customers/' + CLIENTID +'/keywordPlans:generateKeywordIdeas';     var requestBody = {       "customerId": CLIENTID,       "language": "ENGLISH",       "geo_target_constants": [],       "include_adult_keywords": false,       "page_size": 10,       "keyword_plan_network": "GOOGLE_SEARCH_AND_PARTNERS",       "keyword_seed": keywords     };     var options = {       'method': 'post',       'contentType': 'application/json',       'headers': {         'Authorization': 'Bearer ' + accessToken       },       'payload': JSON.stringify(requestBody)     };     var response = UrlFetchApp.fetch(endpoint, options);     var ideas = JSON.parse(response.getContentText());     return ideas; } function getOAuthToken() {   var CLIENTID = scriptProperties.getProperty('CLIENTID');   var SECRETFORADS = scriptProperties.getProperty('SECRETFORADS');   var service = OAuth2.createService('GoogleAds')     .setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')     .setTokenUrl('https://accounts.google.com/o/oauth2/token')     .setClientId(CLIENTID)     .setClientSecret(SECRETFORADS)     .setScope('https://www.googleapis.com/auth/adwords');   if (!service.hasAccess()) {     return 'No access to Google Ads API';   }   var url = API_URL;   var headers = {     "Authorization": "Bearer " + service.getAccessToken(),     "Content-Type": "application/json",     "muteHttpExceptions": false   };   var options = {     "method": "get",     "headers": headers,   };   var response = UrlFetchApp.fetch(url, options);   var jsonResponse = JSON.parse(response.getContentText());   return jsonResponse } 

Exception: Request failed for https://googleads.googleapis.com returned code 404. Truncated server response: <titl... (use muteHttpExceptions option to examine full response) (line 70).

I call the function in a Google Sheets cell and get a 404 instead of the results of the API call.

I am using the following code to insert Google Ads at three slots on my website. However, I am getting the following error:

Uncaught TagError: adsbygoogle.push() error: No slot size for availableWidth=0

<div align="center"> <!-- Sidebar Ads --> <ins class="adsbygoogle"      style="display:block"      data-ad-client="(ad-client-xxxxx)"      data-ad-slot="(xxxxx)"      data-ad-format="auto"      data-full-width-responsive="true"></ins> </div> <script>(adsbygoogle = window.adsbygoogle || []).push({});</script> 

I tried the solution described in the following stack overflow question:

TagError: adsbygoogle.push() error: No slot size for availableWidth=0 when i use responsive ads

However, that didn't seem to help!

I am using Admob (react-native-admob-native-ads) package with my react-native(android) app. I have a problem with NativeAd, onAdImpression callback on NatveAd is not called even after the ad is loaded and display on screen. But when i open my app from app-tray onAdImpression called correctly.

Here is my code for NativeAd

<NativeAd ref={nativeAdViewRef} adUnitID={NATIVE_AD_ID} onAdLoaded={()=>console.log('Ad Loaded successfully')} onAdImpression={()=>console.log 'impression count'}/>

Here Ad Loaded successfully printed in concole but impression count not until i open my app from app-tray

I am struggling with implement google native ads on web, i tired to find some documentation on google site, but all refers to mobile app. Has anyone perhaps implemented this?

Already what i do:

  1. I dig through the google documentation
  2. Ask chat GPT :) , give me few useless info
  3. Some tests with google ads events etc.

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.