Displaying google ads

Hello,
did anyone manage to display (responsive) ads with google api ?
https://developers.google.com/adwords/api/docs/guides/responsive-ads

In other words, will this run on Anvil ?

Hi haimari1,

The googleads library is installed in the Full runtime, so you should be able to do anything it supports.

However, I don’t think the googleads library is intended for displaying ads, I think it’s just for creating and managing them.

So to piggyback on this I’m trying to add google ads to my app now but anytime I put the script code in the html it just says an error has occurred.

Has anyone gotten google ads to work successfully or how did you setup ads in your site? Normally on my other sites this just works so I’m guessing there is some issue with where I’m putting it in the html or how anvil works with this?

In case anyone is curious the best option I found was to create a custom html form and edit the code there with the adsense code then save this a custom component that way you can pick where it loads.

Thanks

1 Like

Here’s a step-by-step explanation of how to add Google Ads to your page (thanks to @thenerdypython for confirming that this is how he did it)

  1. Run your app on a custom domain such as thenerdypython.com

  2. Set up your DNS according to the Anvil DNS guide

  3. Set up a Google AdSense account for that custom domain

  4. copy-paste the script tags that Google AdSense gives you into a Custom HTML Form. It’ll look something like

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-3227156798470330",
    enable_page_level_ads: true
  });
</script>
  1. Include the Custom HTML Form in your page: self.content_panel.add_component(Form2())

  2. Once everything has had time to propagate, your ads should now show up

  3. Profit!

Feel free to see https://demo.thenerdypython.com to see the placement and ads in action if you like :slight_smile:

So reviving this a bit, @thenerdypython is my old account lol and I have this working but I’m noticing now that in google adsense they are complaining about me needing to use an ads.txt file at the root of my project. Has anyone seen this recently? I guess it is something new they are doing.

A post was merged into an existing topic: Displaying Google Ads Help Needed