Hướng dẫn Adsense Placement for XenForo Forums - Vị trí đặt Adsense cho diễn đàn XenForo

PVS

Super Moderator
Thành viên BQT
Tham gia
28/02/2015
Bài viết
16,688
Được Like
12,676
Adsense Placement for XenForo Forums - Vị trí đặt Adsense cho diễn đàn XenForo

Mục tiêu của phương pháp này là để đạt được một sự cân bằng tốt giữa doanh thu và kinh nghiệm người dùng.

Đối với thread view, tôi chọn để:
- Không có quảng cáo phía trên bài viết đầu tiên
- 1 quảng cáo dưới bài viết đầu tiên trên mỗi trang (720x90 hoặc 300x250 tùy thuộc vào không gian có sẵn)
- 1 quảng cáo dưới bài viết cuối cùng trên mỗi trang (720x90 hoặc 300x250 tùy thuộc vào không gian có sẵn) nếu và chỉ nếu có nhiều hơn 4 bài viết trên trang
- 1 quảng cáo dưới bài viết thứ 10 trên mỗi trang nếu và chỉ nếu có 20 bài viết trên trang
- Không có quảng cáo hiển thị cho user group premium

Để thực hiện điều này, thay thế các nội dung của hai template như dưới đây sử dụng code từ bài viết này.

Thay thế: nội dung của template ad_message_below với:
Mã:
<xen:hook name="ad_message_below" />

<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$message.conversation_id} AND !{$visitor.user_id}">
<div align="center" style="margin: 10px 0px 0px 0px">

<div id="google-ads-1"></div>

<script type="text/javascript">

    /* Calculate the width of available ad space */
    ad = document.getElementById('google-ads-1');

    if (ad.getBoundingClientRect().width) {
        adWidth = ad.getBoundingClientRect().width; // for modern browsers
    } else {
        adWidth = ad.offsetWidth; // for old IE
    }

    /* Replace ca-pub-XXX with your AdSense Publisher ID */
    google_ad_client = "ca-pub-XXX";

    /* Replace 1234567890 with the AdSense Ad Slot ID from any of your Adsense ads */
    google_ad_slot = "1234567890";
    /* Do not change anything after this line */
    if ( adWidth >= 728 )
      google_ad_size = ["728", "90"];  /* Leaderboard 728x90 */
    else
      google_ad_size = ["320", "250"]; /* Medium Rectangle 320x250 */

    document.write (
     '<ins class="adsbygoogle" style="display:inline-block;width:'
      + google_ad_size[0] + 'px;height:'
      + google_ad_size[1] + 'px" data-ad-client="'
      + google_ad_client + '" data-ad-slot="'
      + google_ad_slot + '"></ins>'
    );
    (adsbygoogle = window.adsbygoogle || []).push({});

</script>
<div align="center" style="margin: 0px 0px 0px 0px">
    /* Replace orange text below with your registration URL */
<a href="https://www.domain.com/login/">This ad does not show to logged in members. Click here to register for free.</a>
</div>
</div>
</xen:if>

<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 9 AND {xen:count $posts} > 19 AND !{xen:helper ismemberof, $visitor, 38, 45}">
<div align="center" style="margin: 10px 0px 0px 0px">

<div id="google-ads-3"></div>

<script type="text/javascript">

    /* Calculate the width of available ad space */
    ad = document.getElementById('google-ads-3');

    if (ad.getBoundingClientRect().width) {
        adWidth = ad.getBoundingClientRect().width; // for modern browsers
    } else {
        adWidth = ad.offsetWidth; // for old IE
    }

    /* Replace ca-pub-XXX with your AdSense Publisher ID */
    google_ad_client = "ca-pub-XXX";

    /* Replace 1234567890 with the AdSense Ad Slot ID from any of your Adsense ads */
    google_ad_slot = "1234567890";
    /* Do not change anything after this line */
    if ( adWidth >= 728 )
      google_ad_size = ["728", "90"];  /* Leaderboard 728x90 */
    else
      google_ad_size = ["320", "250"]; /* Medium Rectangle 320x250 */

    document.write (
     '<ins class="adsbygoogle" style="display:inline-block;width:'
      + google_ad_size[0] + 'px;height:'
      + google_ad_size[1] + 'px" data-ad-client="'
      + google_ad_client + '" data-ad-slot="'
      + google_ad_slot + '"></ins>'
    );
    (adsbygoogle = window.adsbygoogle || []).push({});

</script>
<xen:if is="{$visitor.user_id}">
<div align="center" style="margin: 0px 0px 0px 0px">
    /* Replace orange text below with your account upgrades URL */
<a href="https://www.domain.com/account/upgrades">Subscribing members don't see this ad. Click here to subscribe.</a>
</div>
</xen:if>
</div>
</xen:if>

Thay thế: nội dung của template ad_thread_view_below_messages với:
Mã:
<xen:hook name="ad_thread_view_below_messages" />

/* Replace X, Y with your premium usergroup IDs */
<xen:if is="{xen:count $posts} > 4 AND !{xen:helper ismemberof, $visitor, X, Y}">
<div align="center" style="margin: 15px 0px 10px 0px">

<div id="google-ads-2"></div>

<script type="text/javascript">

    /* Calculate the width of available ad space */
    ad = document.getElementById('google-ads-2');

    if (ad.getBoundingClientRect().width) {
        adWidth = ad.getBoundingClientRect().width; // for modern browsers
    } else {
        adWidth = ad.offsetWidth; // for old IE
    }

    /* Replace ca-pub-XXX with your AdSense Publisher ID */
    google_ad_client = "ca-pub-XXX";

    /* Replace 1234567890 with the AdSense Ad Slot ID from any of your Adsense ads */
    google_ad_slot = "1234567890";
    /* Do not change anything after this line */
    if ( adWidth >= 728 )
      google_ad_size = ["728", "90"];  /* Leaderboard 728x90 */
    else
      google_ad_size = ["320", "250"]; /* Medium Rectangle 320x250 */

    document.write (
     '<ins class="adsbygoogle" style="display:inline-block;width:'
      + google_ad_size[0] + 'px;height:'
      + google_ad_size[1] + 'px" data-ad-client="'
      + google_ad_client + '" data-ad-slot="'
      + google_ad_slot + '"></ins>'
    );
    (adsbygoogle = window.adsbygoogle || []).push({});

</script>
<xen:if is="{$visitor.user_id}">
<div align="center" style="margin: 0px 0px 0px 0px">
    /* Replace orange text below with your account upgrades URL */
<a href="https://www.domain.com/account/upgrades">Subscribing members don't see this ad. Click here to subscribe.</a>
</div>
</xen:if>
</div>
</xen:if>

Tiếp theo, tôi muốn tạo ra một banner ngang (720x90 hoặc 300x50 tùy thuộc vào không gian có sẵn) để hiển thị ở phía trên cùng của forum list, forum view, và danh sách bài viết mới/gần đây.

Thay thế: nội dung của template ad_above_content với:
Mã:
<xen:hook name="ad_above_content" />

/* Replace X, Y with your premium usergroup IDs */
<xen:if is="!{xen:helper ismemberof, $visitor, X, Y} AND ({$contentTemplate} == 'forum_list' OR {$contentTemplate} == 'forum_view' OR {$contentTemplate} == 'find_new_posts')">
<div align="center" style="margin: 10px 0px 10px 0px">

<div id="google-ads-1"></div>

<script type="text/javascript">

    /* Calculate the width of available ad space */
    ad = document.getElementById('google-ads-1');

    if (ad.getBoundingClientRect().width) {
        adWidth = ad.getBoundingClientRect().width; // for modern browsers
    } else {
        adWidth = ad.offsetWidth; // for old IE
    }

    /* Replace ca-pub-XXX with your AdSense Publisher ID */
    google_ad_client = "ca-pub-XXX";

    /* Replace 1234567890 with the AdSense Ad Slot ID */
    google_ad_slot = "1234567890";
    /* Do not change anything after this line */
    if ( adWidth >= 728 )
      google_ad_size = ["728", "90"];  /* Leaderboard 728x90 */
    else
      google_ad_size = ["320", "50"]; /* Mobile Banner 320x50 */

    document.write (
     '<ins class="adsbygoogle" style="display:inline-block;width:'
      + google_ad_size[0] + 'px;height:'
      + google_ad_size[1] + 'px" data-ad-client="'
      + google_ad_client + '" data-ad-slot="'
      + google_ad_slot + '"></ins>'
    );
    (adsbygoogle = window.adsbygoogle || []).push({});

</script>
<xen:if is="{$visitor.user_id}">
<div align="center" style="margin: 0px 0px 0px 0px">
    /* Replace orange text below with your account upgrades URL */
<a href="https://www.domain.com/account/upgrades">Subscribing members don't see this ad. Click here to subscribe.</a>
</div>
</xen:if>
</div>
</xen:if>

Tôi muốn có một banner dọc lớn để hiển thị trong sidebar của trang Featured Threads (trang chủ trang web của tôi) chỉ dành cho khách.

Thay thế: nội dung của template ad_sidebar_below_visitor_panel với:
Mã:
<xen:hook name="ad_sidebar_below_visitor_panel" />

<xen:if is="!{$visitor.user_id} AND {$contentTemplate} == 'cta_featuredthreads_featured'">
<div align="center" style="margin: 10px 0px 10px 0px">
    /* Replace the line below with your 300x600 ad code.  Omit (leave out) the line "<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>" */
    Your ad code goes here
</div>
</xen:if>

Cuối cùng, để không có các quảng cáo trên xuất hiện thì thêm đoạn mã sau vào template footer của bạn, ngay trước "</xen:hook>" cuối cùng ở cuối template:
Mã:
/* Replace X, Y with your premium usergroup IDs */
<xen:if is="!{xen:helper ismemberof, $visitor, X, Y}">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
</xen:if>

Thay thế các thông tin cần thiết trong các đoạn code trên.

Chúc các bạn thành công.


Nguồn: xenforo.com​
 

Hướng dẫn sử dụng

XenForo 1 XenForo 2
Translate by PVS

Dịch vụ XenForo của VNXF

Mr. Tuấn

Mobile/Zalo: 0988 488 096

Telegram: bluekpro

Email: [email protected]

Nhà Tài Trợ

Mút Xốp Không Gian
pallet Thịnh Phát
Top Bottom