XF 2.2 Google Adsense

HuskerGarrett

Active member
Hi, can anyone help me out with setting ads? I only want non-paying members to see them, so I created a "widget" under Advertising for "Forum view: below node list" and pasted the Google Adsense code. My Google page says my website is set up and ready to run ads as well. Nothing is showing though. Am I doing something wrong?

This is the code I pasted:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxx"
crossorigin="anonymous"></script>
 
Last edited:
That code you posted above is the main script for Google Adsense (you should also edit you post so you are not sharing your Adsense ID, the numbers at the end of the script).

There is also code per ad unit that is different for each ad position you make. You are completely missing this code.

As for make it show only for guests. Wrap the Ad unit code (that is currently missing) with this:

Code:
<xf:if is="!$xf.visitor.user_id">
   Your individual ad unit code here...
</xf:if>
 
You could also wrap the code you originally pasted with the conditional code I shared above, it will save a little on page loading resources. That script code will only be needed one time per page, even if you have multiple ad units on a page. Thebetter placement for that main code may be in the "Page_Container" template, which is loaded with every page.

Google Adsense "Display" ad units seem to work best in XenForo.

 
You could also wrap the code you originally pasted with the conditional code I shared above, it will save a little on page loading resources. That script code will only be needed one time per page, even if you have multiple ad units on a page. Thebetter placement for that main code may be in the "Page_Container" template, which is loaded with every page.

Google Adsense "Display" ad units seem to work best in XenForo.

Thank you! I figured it out and it looks like it’s working now. Random side question, it says I need to download a ads.txt file and upload it to the root level domain. Sorry this is probably a stupid question, do you know where I upload that in my Cpanel?
 
Hi, can anyone help me out with setting ads? I only want non-paying members to see them, so I created a "widget" under Advertising for "Forum view: below node list" and pasted the Google Adsense code. My Google page says my website is set up and ready to run ads as well. Nothing is showing though. Am I doing something wrong?

This is the code I pasted:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-xxxxxxxxxxxx"
crossorigin="anonymous"></script>
This code should go to the PAGE_CONTAINER in the ACP not the individual widgets. Add it between the <head> </head> tags.
 
Top Bottom