1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.5 Mobile - Google page-level adsense ads

Discussion in 'XenForo Questions and Support' started by tommydamic68, Apr 28, 2016.

  1. tommydamic68

    tommydamic68 Well-Known Member

    Has anyone incorporated these new Google adsense "mobile only" ads? Apparently they do not add to your existing 3 ads per page quota. If so, where would you add the code?

    Screen Shot 2016-04-28 at 5.24.35 AM.png
    Last edited: Apr 28, 2016
    Skylined likes this.
  2. Chris D

    Chris D XenForo Developer Staff Member

    Place the code in the <head> tag, preferably.

    The page_container_js_head template would be a good location for this.
    Skylined, Divvens and tommydamic68 like this.
  3. Sunka

    Sunka Well-Known Member

    I put it in PAGE_CONTAINER template.
    Is it better to put it into page_container_js_head template?
    If yes, where exactly?
        <script src="{$jQuerySource}"></script>   
        <xen:if is="{$jQuerySource} != {$jQuerySourceLocal}">
            <script>if (!window.jQuery) { document.write('<scr'+'ipt type="text/javascript" src="{$jQuerySourceLocal}"><\/scr'+'ipt>'); }</script>
        </xen:if><xen:if is="{$xenOptions.uncompressedJs} == 1 OR {$xenOptions.uncompressedJs} == 3">
        <script src="{$javaScriptSource}/jquery/jquery.xenforo.rollup.js?_v={$xenOptions.jsVersion}"></script></xen:if>   
        <script src="{xen:helper javaScriptUrl, '{$javaScriptSource}/xenforo/xenforo.js?_v={$xenOptions.jsVersion}'}"></script>
  4. Chris D

    Chris D XenForo Developer Staff Member

    It's fine in there, too.
    Skylined and Sunka like this.
  5. OakleyForum

    OakleyForum Active Member

    I assume you can throw conditionals around this to only show the ads for certain usergroups/forums?
  6. Chris D

    Chris D XenForo Developer Staff Member

    Yep, most likely.
  7. tommydamic68

    tommydamic68 Well-Known Member

    In case anyone is wondering what it looks like on mobile view, you can see the ad at the bottom of the forum in picture below. I chose the anchor/ overlay.

    Skylined, zastavra and Divvens like this.
  8. Genchi

    Genchi Member

    Can anyone ELI5 this? So, exactly what should I do? I see the page_container_js_head listed above under the templates tab. Do I delete whats in there and then copy/paste what Google gives me? The help is very much appreciated.
    I apologize in advance for my ignorance in these matters....:(
  9. Chris D

    Chris D XenForo Developer Staff Member

    Never delete what's in the existing templates unless you know what you are doing.

    Just add it to the end or beginning of that template.
    OakleyForum likes this.
  10. Genchi

    Genchi Member

    Thanks for the quick reply and the help. I just added the code Google gave me at the end without touching anything else. I just checked via Mobile and didn't see anything pop up but I also checked the Sphynxlair.com mobile website above and nothing popped up on my mobile either so IDK. I know that the Google says they will display at "Optimal Times" so I can just guess that now is not an optimal time. I will keep an eye out. Thanks again for all you do.
  11. Skylined

    Skylined Active Member

    I've used conditionals to show ads to guests in some pages and it's working perfectly.

    Thanks for your help @Chris D! (y)
  12. tommydamic68

    tommydamic68 Well-Known Member

    Its random, I see it here and there.
  13. Beanjam

    Beanjam Active Member

    I'm trying out the anchor ads and it looks like the bottom half of the ad is being cut off. Is anybody having that happen?
  14. ProCom

    ProCom Active Member

    Hey @Skylined , would you mind posting the conditions code you used and where you put it? Thanks!
  15. Skylined

    Skylined Active Member

    Sure! :)

    Template: page_container_js_head

    You have to insert the followin, replace the ca-pub-XXXXXXXXXXXXXXXX with yours (get this from AdSense).

    <xen:if is="!in_array({$contentTemplate}, array('', 'message_page', 'online_list', 'lost_password_confirm', 'login_two_step', 'forum_list', 'help_index', 'help_smilies', 'help_bb_codes', 'error', 'help_cookies', 'help_terms', 'member_view', 'account_personal_details', 'account_alerts', 'account_likes', 'conversation_list', 'conversation_add', 'conversation_view', 'account_contact_details', 'account_privacy', 'account_preferences', 'account_alert_preferences', 'account_following', 'account_ignored', 'account_external_accounts', 'account_security', 'search_form', 'search_form_post', 'search_form_profile_post', 'lost_password', 'member_notable', 'xengallery_search_form_media', 'search_results', 'register_form', 'login', 'error_with_login', 'contact', 'thread_view', 'register_facebook', 'register_twitter', 'register_google', 'cta_overtaking_index'))">
    <xen:if is="!{$visitor.user_id}">   
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
      (adsbygoogle = window.adsbygoogle || []).push({
        google_ad_client: "ca-pub-XXXXXXXXXXXXXXXX",
        enable_page_level_ads: true
    eagle eyes and ProCom like this.
  16. ProCom

    ProCom Active Member

    Brilliant, thanks!

Share This Page