Jump to content

Recommended Posts

cfimortgage    0
cfimortgage

I am working to make my site work better with mobile browsers and I also wanted to place a floating ad along the bottom like I see on many sites. It would appear that Google changed their ad unit from a normal ad the site of a mobile screen to a completely different ad modem that is very code driven. They give you the option of either PHP or JSP but it isnt the easy to edit code they used. Plus instead of having the control of being able to place it somewhere on your page it seems to place it right at the top and I cant figure out a way around that.

I placed the PHP code directly into the functions page and it just worked but again with no control by me. I would like to use a hook or something to better control its position. I tried CSS but the control holding the iframe has a randomly generated name so I cant really apply CSS to it. When I attempt to put Either the PHP or the JSP into a function to call as an "add_action" it gives me errors. Could anyone give me some idea of how to add this where I might have a little more control of its location or the best way to add it to pagelines customize.

This is the PHP version:

<?php

$GLOBALS['google']['client']='ca-mb-pub-xxxxxxxxxxxxxx';
$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']='6199803051';
$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);
}

?>

This is the JSP version:

<%@ page import="java.io.BufferedReader,
                 java.io.InputStreamReader,
                 java.io.IOException,
                 java.io.UnsupportedEncodingException,
                 java.net.URL,
                 java.net.URLEncoder,
                 java.util.ArrayList,
                 java.util.List" %>
<%!

private static final String PAGEAD =
    "http://pagead2.googlesyndication.com/pagead/ads?";

private void googleAppendUrl(StringBuilder url, String param, String value)
    throws UnsupportedEncodingException {
  if (value != null) {
    String encodedValue = URLEncoder.encode(value, "UTF-8");
    url.append("&").append(param).append("=").append(encodedValue);
  }
}

private void googleAppendColor(StringBuilder url, String param,
    String value, long random) {
  String[] colorArray = value.split(",");
  url.append("&").append(param).append("=").append(
      colorArray[(int)(random % colorArray.length)]);
}

private void googleAppendScreenRes(StringBuilder url, String uaPixels,
    String xUpDevcapScreenpixels, String xJphoneDisplay) {
  String screenRes = uaPixels;
  if (screenRes == null) {
    screenRes = xUpDevcapScreenpixels;
  }
  if (screenRes == null) {
    screenRes = xJphoneDisplay;
  }
  if (screenRes != null) {
    String[] resArray = screenRes.split("[x,*]");
    if (resArray.length == 2) {
      url.append("&u_w=").append(resArray[0]);
      url.append("&u_h=").append(resArray[1]);
    }
  }
}

private void googleAppendMuid(StringBuilder url, List<String> muids) {
  for (String muid : muids) {
    if (muid != null) {
      url.append("&muid=").append(muid);
      return;
    }
  }
}

private void googleAppendViaAndAccept(StringBuilder url, String via,
    String accept) throws UnsupportedEncodingException {
  googleAppendUrl(url, "via", via);
  googleAppendUrl(url, "accept", accept);
}

%>
<%

long googleDt = System.currentTimeMillis();
StringBuilder googleAdUrlStr = new StringBuilder(PAGEAD);
googleAdUrlStr.append("&client=ca-mb-pub-xxxxxxxxxxxxxx");
googleAdUrlStr.append("&dt=").append(googleDt);
googleAppendUrl(googleAdUrlStr, "ip", request.getRemoteAddr());
googleAdUrlStr.append("&markup=xhtml");
googleAdUrlStr.append("&output=xhtml");
googleAppendUrl(googleAdUrlStr, "ref", request.getHeader("Referer"));
String googleUrl = request.getRequestURL().toString();
if (request.getQueryString() != null) {
  googleUrl += "?" + request.getQueryString().toString();
}
googleAdUrlStr.append("&slotname=6199803051");
googleAppendUrl(googleAdUrlStr, "url", googleUrl);
String googleUserAgent = request.getHeader("User-Agent");
googleAppendUrl(googleAdUrlStr, "useragent", googleUserAgent);
googleAppendScreenRes(googleAdUrlStr, request.getHeader("UA-pixels"),
    request.getHeader("x-up-devcap-screenpixels"),
    request.getHeader("x-jphone-display"));
List<String> googleMuids = new ArrayList<String>();
googleMuids.add(request.getHeader("X-DCMGUID"));
googleMuids.add(request.getHeader("X-UP-SUBNO"));
googleMuids.add(request.getHeader("X-JPHONE_UID"));
googleMuids.add(request.getHeader("X-EM-UID"));
googleAppendMuid(googleAdUrlStr, googleMuids);
if (googleUserAgent == null || googleUserAgent.length() == 0) {
  googleAppendViaAndAccept(googleAdUrlStr, request.getHeader("Via"),
      request.getHeader("Accept"));
}
try {
  URL googleAdUrl = new URL(googleAdUrlStr.toString());
  BufferedReader reader = new BufferedReader(
      new InputStreamReader(googleAdUrl.openStream(), "AUTO_DETECT"));
  for (String line; (line = reader.readLine()) != null;) {
    out.println(line);
  }
} catch (IOException e) {}

%>

Share this post


Link to post
Share on other sites
Rob    547
Rob

Hi,

 

First, I'd recommend you install the Action Map plugin, which is free.  This will help you to identify the proper hook to use.

 

Next, I strongly recommend the PageLines Customize plugin, which like Action Map, is free, and found in our Store.

 

Following this, I suggest the Hooker plugin. 

 

After finding the right hook, you can select that with the Hooker Plugin, then paste the actual php you want to implement and save the hook.  The complete process will be shortened and made much easier for you.

 

I'm not sure how you're implementing this Google Code for mobiles. I've not tried that, so it's a bit out of my realm at present.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
cfimortgage    0
cfimortgage

Hi,

 

First, I'd recommend you install the Action Map plugin, which is free.  This will help you to identify the proper hook to use.

 

Next, I strongly recommend the PageLines Customize plugin, which like Action Map, is free, and found in our Store.

 

Following this, I suggest the Hooker plugin. 

 

After finding the right hook, you can select that with the Hooker Plugin, then paste the actual php you want to implement and save the hook.  The complete process will be shortened and made much easier for you.

 

I'm not sure how you're implementing this Google Code for mobiles. I've not tried that, so it's a bit out of my realm at present.

 

I have everything but that hooker plugin but I have added the code to a function and added that function with an add_action to the hook I wanted but that didnt work. It caused errors in googles script. On the other hand I simply placed it into the functions.php page so it would run on load and then I was able to create a css work around for my desired result. It uses a wildcard ID search because google changes the ID of the control each time the page loads.

[id^='google_afmc_']
{
position: fixed;
bottom: 0;
z-index: 1000;
}

Share this post


Link to post
Share on other sites
Rob    547
Rob

So this issue is resolved?


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
cfimortgage    0
cfimortgage

So this issue is resolved?

Yes but I would love someone who is much better at pagelines to take a look at googles new adsense mobile ad unit and fiddle around with it on pagelines so we might have a better understanding of how best to insert is and move it around on the site besides my fix. I just feel I cant be the only one that is going to have questions about this.

Share this post


Link to post
Share on other sites
Rob    547
Rob

I've checked the code on Google, and will be testing over the next few days.  As soon as I have something to report, I'll send you a message or post it here. Sorry for the time it's taking. Not all the moderators use Google AdSense on their sites.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Similar Content

    • rijans
      By rijans
      When placing ads with "google Publisher Plugin", the plugin shows the following error! (check attached img too) But my caching plugin is already disabled! 
       
      Oops. Something went wrong. Please try again.
      The most likely reason is that you are using a WordPress cache plugin. If this is the case, please follow the plugin's instructions to clear the cache and then try again.         
      Can anyone figure out what's wrong?
    • kareemtaylor
      By kareemtaylor
      Hi,
       
      I've been wondering why relevant ads haven't been displaying on my site. Well, according to AdSense, it's because they cannot crawl my pages. It's saying "http://kareemtaylor.com/" is a "page not found". This has only been true since the installation of Pagelines. Not sure what that does to the domain or accessibility of the domain.
       
      Any help would be greatly appreciated.
       
      All the best,
       
      Kareem
    • zetanet
      By zetanet+
      On site front page I would like to add Adsense ads to morefoot or footer, but I always get some grey squares; I use the same code I wrote in Primary/Secondary Sidebar, that works. Where could it be the problem?
    • imc042
      By imc042
      Hello,

      I have just inserted an adsense banner using a custom function in my header section. My problem is that the branding section where my logo is links to my homepage and the span of the clickable area covers the full width of the header. Therefore when my adsense ad is clicked it just reloads my homepage.

      How can I either disable the homepage link altogether or make it so that it only happens when the logo of the website is clicked as opposed to clicking anywhere in the header?

      Thanks
×