How to add Google Adsense code to VB Mobile style?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fergal
    Senior Member
    • Dec 2004
    • 790

    [Forum] How to add Google Adsense code to VB Mobile style?

    Are there any guides on how to add Google Adsense ads to the VB mobile style?

    I've inserted the PHP code that I got from Adsense into;

    Ad Location Templates > ad_archive_above_content1

    But the ad is not displaying on the mobile version of my site. How do I fix that?

    Thanks!

    Edit, sorry forgot to add I got the error message below when I inserted the code:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in/var/www/vhosts/[removed].com/httpdocs/includes/adminfunctions_template.php(5436) : eval()'d code on line 3
    Fergal Crawley
    Business Advice Forum

    Forum Promotion
  • Fergal
    Senior Member
    • Dec 2004
    • 790

    #2
    Bump.
    Fergal Crawley
    Business Advice Forum

    Forum Promotion

    Comment

    • Fergal
      Senior Member
      • Dec 2004
      • 790

      #3
      Anyone.
      Fergal Crawley
      Business Advice Forum

      Forum Promotion

      Comment

      • Trevor Hannant
        vBulletin Support
        • Aug 2002
        • 24325
        • 5.7.X

        #4
        What exactly is the code you're trying to add?
        Vote for:

        - Admin Settable Paid Subscription Reminder Timeframe (vB6)
        - Add Admin ability to auto-subscribe users to specific channel(s) (vB6)

        Comment

        • Fergal
          Senior Member
          • Dec 2004
          • 790

          #5
          Thanks Trevor.

          Code:
          <?php
          
          	 
          
          
          	$GLOBALS['google']['client']='ca-mb-pub-8275518754675591';
          
          
          	$GLOBALS['google']['https']=read_global('HTTPS');
          
          
          	$GLOBALS['google']['ip']=read_global('REMOTE_ADDR');
          
          
          	$GLOBALS['google']['markup']='xhtml';
          
          
          	$GLOBALS['google']['output']='xhtml';
          
          
          	$GLOBALS['google']['ref']=read_global('HTTP_REFERER');
          
          
          	$GLOBALS['google']['slotname']='7227755759';
          
          
          	$GLOBALS['google']['url']=read_global('HTTP_HOST') . read_global('REQUEST_URI');
          
          
          	$GLOBALS['google']['useragent']=read_global('HTTP_USER_AGENT');
          
          
          	$google_dt = time();
          
          
          	google_set_screen_res();
          
          
          	google_set_muid();
          
          
          	google_set_via_and_accept();
          
          
          	function read_global($var) {
          
          
          	  return isset($_SERVER[$var]) ? $_SERVER[$var]: '';
          
          
          	}
          
          
          	 
          
          
          	function google_append_url(&$url, $param, $value) {
          
          
          	  $url .= '&' . $param . '=' . urlencode($value);
          
          
          	}
          
          
          	 
          
          
          	function google_append_globals(&$url, $param) {
          
          
          	  google_append_url($url, $param, $GLOBALS['google'][$param]);
          
          
          	}
          
          
          	 
          
          
          	function google_append_color(&$url, $param) {
          
          
          	  global $google_dt;
          
          
          	  $color_array = explode(',', $GLOBALS['google'][$param]);
          
          
          	  google_append_url($url, $param,
          
          
          	                    $color_array[$google_dt % count($color_array)]);
          
          
          	}
          
          
          	 
          
          
          	function google_set_screen_res() {
          
          
          	  $screen_res = read_global('HTTP_UA_PIXELS');
          
          
          	  if ($screen_res == '') {
          
          
          	    $screen_res = read_global('HTTP_X_UP_DEVCAP_SCREENPIXELS');
          
          
          	  }
          
          
          	  if ($screen_res == '') {
          
          
          	    $screen_res = read_global('HTTP_X_JPHONE_DISPLAY');
          
          
          	  }
          
          
          	  $res_array = preg_split('/[x,*]/', $screen_res);
          
          
          	  if (count($res_array) == 2) {
          
          
          	    $GLOBALS['google']['u_w']=$res_array[0];
          
          
          	    $GLOBALS['google']['u_h']=$res_array[1];
          
          
          	  }
          
          
          	}
          
          
          	 
          
          
          	function google_set_muid() {
          
          
          	  $muid = read_global('HTTP_X_DCMGUID');
          
          
          	  if ($muid != '') {
          
          
          	    $GLOBALS['google']['muid']=$muid;
          
          
          	     return;
          
          
          	  }
          
          
          	  $muid = read_global('HTTP_X_UP_SUBNO');
          
          
          	  if ($muid != '') {
          
          
          	    $GLOBALS['google']['muid']=$muid;
          
          
          	     return;
          
          
          	  }
          
          
          	  $muid = read_global('HTTP_X_JPHONE_UID');
          
          
          	  if ($muid != '') {
          
          
          	    $GLOBALS['google']['muid']=$muid;
          
          
          	     return;
          
          
          	  }
          
          
          	  $muid = read_global('HTTP_X_EM_UID');
          
          
          	  if ($muid != '') {
          
          
          	    $GLOBALS['google']['muid']=$muid;
          
          
          	     return;
          
          
          	  }
          
          
          	}
          
          
          	 
          
          
          	function google_set_via_and_accept() {
          
          
          	  $ua = read_global('HTTP_USER_AGENT');
          
          
          	  if ($ua == '') {
          
          
          	    $GLOBALS['google']['via']=read_global('HTTP_VIA');
          
          
          	    $GLOBALS['google']['accept']=read_global('HTTP_ACCEPT');
          
          
          	  }
          
          
          	}
          
          
          	 
          
          
          	function google_get_ad_url() {
          
          
          	  $google_ad_url = 'http://pagead2.googlesyndication.com/pagead/ads?';
          
          
          	  google_append_url($google_ad_url, 'dt',
          
          
          	                    round(1000 * array_sum(explode(' ', microtime()))));
          
          
          	  foreach ($GLOBALS['google'] as $param => $value) {
          
          
          	    if (strpos($param, 'color_') === 0) {
          
          
          	      google_append_color($google_ad_url, $param);
          
          
          	    } else if (strpos($param, 'url') === 0) {
          
          
          	      $google_scheme = ($GLOBALS['google']['https'] == 'on')
          
          
          	          ? 'https://' : 'http://';
          
          
          	      google_append_url($google_ad_url, $param,
          
          
          	                        $google_scheme . $GLOBALS['google'][$param]);
          
          
          	    } else {
          
          
          	      google_append_globals($google_ad_url, $param);
          
          
          	    }
          
          
          	  }
          
          
          	  return $google_ad_url;
          
          
          	}
          
          
          	 
          
          
          	$google_ad_handle = @fopen(google_get_ad_url(), 'r');
          
          
          	if ($google_ad_handle) {
          
          
          	  while (!feof($google_ad_handle)) {
          
          
          	    echo fread($google_ad_handle, 8192);
          
          
          	  }
          
          
          	  fclose($google_ad_handle);
          
          
          	}
          
          
          	 
          
          ?>
          Fergal Crawley
          Business Advice Forum

          Forum Promotion

          Comment

          • Carbuff
            Senior Member
            • Dec 2011
            • 251
            • 4.2.X

            #6
            Truly sorry! My mistake, confused AdSense with analytics, I'm coming off very little sleep. I was wondering why the there was AdSense in you php code in the first post. Lol.

            Maybe Trevor can delete the post?
            My board: Auto Forum powered by vBulletin.

            Comment

            • BirdOPrey5
              Senior Member
              • Jul 2008
              • 9613
              • 5.6.3

              #7
              There's a few issues here...

              1) You can't put PHP in templates. You can put HTML or JavaScript in templates.
              2) I've never seen Google supply you with PHP code. Every adsense ad I make they supply me with JavaScript code
              3) The template ad_archive_above_content1 shows up only in your Forum Archive, which isn't part of the Mobile Style. There are only 2 ad location templates available in the mobile style.

              What you need to do is get the javascript code from Google, it will look something like this:

              Code:
              <script type="text/javascript"><!--
              google_ad_client = "ca-pub-99999999999999999999";
              /* 120x600, BOP5's Ad */
              google_ad_slot = "9999999999";
              google_ad_width = 120;
              google_ad_height = 600;
              //-->
              </script>
              <script type="text/javascript"
              src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
              </script>
              And then go to Admin CP -> Styles & Templates -> Style Manager -> Mobile Style -> Edit Templates -> Ad Location Templates.... choose one of the 2 and paste the code into it.

              Comment


              • Sam-TheMaster
                Sam-TheMaster commented
                Editing a comment
                Hello there!



                Google Mobile Content (Ads for mobile gives code exact in php format)





                ===========







                ==============



                How do I add this under footer section of my mobile template?
            • BirdOPrey5
              Senior Member
              • Jul 2008
              • 9613
              • 5.6.3

              #8
              If the code is in .php format it can't be added to a template.



              Please post some of the code if you can in a new post (not a comment) and use the [CODE] BB Code to show it.

              Comment

              • Fergal
                Senior Member
                • Dec 2004
                • 790

                #9
                Joe, I've posted the code in post #5. Is it too much to ask that VB's mobile style would be compatible with Google Adsense mobile ad code?
                Fergal Crawley
                Business Advice Forum

                Forum Promotion

                Comment

                Related Topics

                Collapse

                Working...