Displaying Google Ads Help Needed

Dear all,

I have been trying to follow the instructions posted by Shaun here Displaying google ads - #4 by thenerdypython to display google ads on my site but I am stuck at step 4 & 5 of the post.

I defined a new form called AdForm under my main startup form in my client code. I set the html property as Custom HTML form in the column on the right, and pasted the google ads script tags in the HTML editor on the bottom left.

Then I went back to my startup form, added a new column panel component called content_panel_ad. In the events section on the bottom right, I added the following event show code into my startup form code within the startup form class object.

  def content_panel_ad_show(self, **event_args): 
    def content_panel_ad(self,**event_args):
      self.content_panel_ad.add_component(AdForm())
      pass
    pass

The line self.content_panel_ad.add_component(AdForm()) was included and the whole anvil app ran without any internal errors but the google ads were still not showing up. Does any Anvil staff or guru user here know what I did wrong? Thank you so much for your help!

With out seeing the rest of the code I may be completely wrong here but in the content_panel_ad_show() you define another function called content_panel_ad()… but do you ever call that content_panel_ad() function? If it is not called then it will never do anything.

If you were to define the function and then call it that might be what you want.

Does this do what you want.

  def content_panel_ad(self,**event_args):
    self.content_panel_ad.add_component(AdForm())

  def content_panel_ad_show(self, **event_args): 
    # Populate the panel when the Ad Panel is shown
    self.content_panel_ad()
    

Or more simply

  def content_panel_ad_show(self, **event_args): 
    # Populate the panel when the Ad Panel is shown
    self.content_panel_ad.add_component(AdForm())

Or you could test if the content panel has anything in it and if not then add it.

  def content_panel_ad_show(self, **event_args): 
    # Populate the panel when the Ad Panel is shown if there is nothing in it
    if not self.content_panel_ad.get_components():
      self.content_panel_ad.add_component(AdForm())