Advertising - AdSense setup


Andy

Administrator
Staff member
This thread will explain how to setup your AdSense and XenForo Advertising code.

You will create two AdSense codes:

First AdSense code:
  1. Click Ads
  2. Click By ad unit
  3. Click Display ads
  4. Name your ad unit: fixed 728x90
  5. Click Responsive and select Fixed
  6. Enter 728 for the Width and 90 for the Height
  7. Click the Create button
  8. Copy code
  9. Click Done
Second AdSense code:
  1. Click Ads
  2. Click By ad unit
  3. Click Display ads
  4. Name your ad unit: fixed 300x50
  5. Click Responsive and select Fixed
  6. Enter 300 for the Width and 50 for the Height
  7. Click the Create button
  8. Copy code
  9. Click Done
 

Andy

Administrator
Staff member
Now you will select the XenForo Advertising page.

Admin control panel -> Setup -> Advertising

1587384326763.png
 

Andy

Administrator
Staff member
The HTML code for Container breadcrumb (top): Above.

Code:
<xf:if is="$xf.reply.template == 'forum_list'">
    <div class="advertising-wide">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>

<xf:if is="$xf.reply.template == 'forum_view'">
    <div class="advertising-wide">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>

<xf:if is="$xf.reply.template == 'thread_view'">
    <div class="advertising-wide">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:10px;margin-bottom:15px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>
 

Andy

Administrator
Staff member
The HTML code for Container breadcrumb (bottom): Above.

Code:
<xf:if is="$xf.reply.template == 'forum_list'">
    <div class="advertising-wide">
        <div style="margin-top:20px;margin-bottom:10px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:20px;margin-bottom:10px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>

<xf:if is="$xf.reply.template == 'forum_view'">
    <div class="advertising-wide">
        <div style="margin-top:20px;margin-bottom:10px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:20px;margin-bottom:10px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>

<xf:if is="$xf.reply.template == 'thread_view'">
    <div class="advertising-wide">
        <div style="margin-top:0px;margin-bottom:0px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 728x90 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:728px;height:90px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
    <div class="advertising-narrow">
        <div style="margin-top:0px;margin-bottom:0px;">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
                 crossorigin="anonymous"></script>
            <!-- fixed 300x50 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;height:50px"
                 data-ad-client="ca-pub-1234"
                 data-ad-slot="1234"></ins>
            <script>
                 (adsbygoogle = window.adsbygoogle || []).push({});
            </script>
        </div>
    </div>
</xf:if>
 

Andy

Administrator
Staff member
Display criteria. I prefer to show AdSense to all visitors and members:

1587388335786.jpg
 

Andy

Administrator
Staff member
Add the following code to the extra.less template:

Code:
// advertising

.advertising-wide
{
	display: inline;
	text-align: center;
}

.advertising-narrow
{
	display: none;
}

@media (max-width: @xf-responsiveMedium)
{
	.advertising-wide
	{
		display: none;
	}
	
	.advertising-narrow
	{
		display: inline;
		text-align: center;
	}
}
 

Andy

Administrator
Staff member
You can use the following two variables to exclude forums and or threads.

{$__globals.forum.node_id}

{$__globals.forum.last_thread_id}

So for example you would use this code:

<xf:if is="$xf.reply.template == 'forum_view' AND {$__globals.forum.node_id} != 100">

Replace 100 with the forum ID you don't want to have AdSense code shown in.
 
Top