Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: DanteOz on April 08, 2011, 10:14:42 PM

Title: How to place Admob ads in wap2 of 2.0 rc4?
Post by: DanteOz on April 08, 2011, 10:14:42 PM
Hi, pls how do i place the following admob ad code to wap2 of my forum rc4? maybe top & bottom of page.
  <?php
// AdMob Publisher Code
// Language: PHP (curl)
// Version: 20081105
// Copyright AdMob, Inc., All rights reserved
// Documentation at http://developer.admob.com/wiki/Main_Page

$admob_params = array(
  
'PUBLISHER_ID'      => 'xxxxxxxxxxxxxx'// Required to request ads. To find your Publisher ID, log in to your AdMob account and click on the "Sites & Apps" tab.
  
'ANALYTICS_ID'      => 'your_analytics_site_id'// Required to collect Analytics data. To find your Analytics ID, log in to your Analytics account and click on the "Edit" link next to the name of your site.
  
'AD_REQUEST'        => true// To request an ad, set to TRUE.
  
'ANALYTICS_REQUEST' => false// To enable the collection of analytics data, set to TRUE.
  
'TEST_MODE'         => true// While testing, set to TRUE. When you are ready to make live requests, set to FALSE.
  // Additional optional parameters are available at: http://developer.admob.com/wiki/AdCodeDocumentation
  
'OPTIONAL'          => array()
);

// Optional parameters for AdMob Analytics (http://analytics.admob.com)
//$admob_params['OPTIONAL']['title'] = "Enter Page Title Here"; // Analytics allows you to track site usage based on custom page titles. Enter custom title in this parameter.
//$admob_params['OPTIONAL']['event'] = "Enter Event Name Here"; // To learn more about events, log in to your Analytics account and visit this page: http://analytics.admob.com/reports/events/add

/* This code supports the ability for your website to set a cookie on behalf of AdMob
 * To set an AdMob cookie, simply call admob_setcookie() on any page that you call admob_request()
 * The call to admob_setcookie() must occur before any output has been written to the page (http://www.php.net/setcookie)
 * If your mobile site uses multiple subdomains (e.g. "a.example.com" and "b.example.com"), then pass the root domain of your mobile site (e.g. "example.com") as a parameter to admob_setcookie().
 * This will allow the AdMob cookie to be visible across subdomains
 */
//admob_setcookie();

/* AdMob strongly recommends using cookies as it allows us to better uniquely identify users on your website.
 * This benefits your mobile site by providing:
 *    - Improved ad targeting = higher click through rates = more revenue!
 *    - More accurate analytics data (http://analytics.admob.com)
 */
 
// Send request to AdMob. To make additional ad requests per page, copy and paste this function call elsewhere on your page.
echo admob_request($admob_params);

/////////////////////////////////
// Do not edit below this line //
/////////////////////////////////

// This section defines AdMob functions and should be used AS IS.
// We recommend placing the following code in a separate file that is included where needed.

function admob_request($admob_params) {
  static 
$pixel_sent false;

  
$ad_mode false;
  if (!empty(
$admob_params['AD_REQUEST']) && !empty($admob_params['PUBLISHER_ID'])) $ad_mode true;
  
  
$analytics_mode false;
  if (!empty(
$admob_params['ANALYTICS_REQUEST']) && !empty($admob_params['ANALYTICS_ID']) && !$pixel_sent$analytics_mode true;
  
  
$protocol 'http';
  if (!empty(
$_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off'$protocol 'https';
  
  
$rt $ad_mode ? ($analytics_mode 0) : ($analytics_mode : -1);
  if (
$rt == -1) return '';
  
  list(
$usec$sec) = explode(' 'microtime()); 
  
$params = array('rt=' $rt,
                  
'z=' . ($sec $usec),
                  
'u=' urlencode($_SERVER['HTTP_USER_AGENT']), 
                  
'i=' urlencode($_SERVER['REMOTE_ADDR']), 
                  
'p=' urlencode("$protocol://" $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']),
                  
'v=' urlencode('20081105-PHPCURL-acda0040bcdea222')); 

  
$sid = empty($admob_params['SID']) ? session_id() : $admob_params['SID'];
  if (!empty(
$sid)) $params[] = 't=' md5($sid);
  if (
$ad_mode$params[] = 's=' $admob_params['PUBLISHER_ID'];
  if (
$analytics_mode$params[] = 'a=' $admob_params['ANALYTICS_ID'];
  if (!empty(
$_COOKIE['admobuu'])) $params[] = 'o=' $_COOKIE['admobuu'];
  if (!empty(
$admob_params['TEST_MODE'])) $params[] = 'm=test';

  if (!empty(
$admob_params['OPTIONAL'])) {
    foreach (
$admob_params['OPTIONAL'] as $k => $v) {
      
$params[] = urlencode($k) . '=' urlencode($v);
    }
  }

  
$ignore = array('HTTP_PRAGMA' => true'HTTP_CACHE_CONTROL' => true'HTTP_CONNECTION' => true'HTTP_USER_AGENT' => true'HTTP_COOKIE' => true);
  foreach (
$_SERVER as $k => $v) {
    if (
substr($k04) == 'HTTP' && empty($ignore[$k]) && isset($v)) {
      
$params[] = urlencode('h[' $k ']') . '=' urlencode($v);
    }
  }
  
  
$post implode('&'$params);
  
$request curl_init();
  
$request_timeout 1// 1 second timeout
  
curl_setopt($requestCURLOPT_URL'http://r.admob.com/ad_source.php');
  
curl_setopt($requestCURLOPT_RETURNTRANSFER1);
  
curl_setopt($requestCURLOPT_TIMEOUT$request_timeout);
  
curl_setopt($requestCURLOPT_CONNECTTIMEOUT$request_timeout);
  
curl_setopt($requestCURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded''Connection: Close'));
  
curl_setopt($requestCURLOPT_POSTFIELDS$post);
  list(
$usec_start$sec_start) = explode(' 'microtime());
  
$contents curl_exec($request);
  list(
$usec_end$sec_end) = explode(' 'microtime());
  
curl_close($request);

  if (
$contents === true || $contents === false$contents '';

  if (!
$pixel_sent) {
    
$pixel_sent true;
    
$contents .= "<img src=\"$protocol://p.admob.com/e0?"
              
'rt=' $rt
              
'&amp;z=' . ($sec $usec)
              . 
'&amp;a=' . ($analytics_mode $admob_params['ANALYTICS_ID'] : '')
              . 
'&amp;s=' . ($ad_mode $admob_params['PUBLISHER_ID'] : '')
              . 
'&amp;o=' . (empty($_COOKIE['admobuu']) ? '' $_COOKIE['admobuu'])
              . 
'&amp;lt=' . ($sec_end $usec_end $sec_start $usec_start)
              . 
'&amp;to=' $request_timeout
              
'" alt="" width="1" height="1"/>';
  }
  
  return 
$contents;
}

function 
admob_setcookie($domain ''$path '/') {
  if (empty(
$_COOKIE['admobuu'])) {    
    
$value md5(uniqid(rand(), true));
    if (!empty(
$domain) && $domain[0] != '.'$domain ".$domain";
    if (
setcookie('admobuu'$valuemktime(000112038), $path$domain)) {
      
$_COOKIE['admobuu'] = $value// make it visible to admob_request()
    

  }
}
  
thnks in advance
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: DanteOz on April 10, 2011, 06:06:16 PM
I'm still patiently waiting for help. :(
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: Hj Ahmad Rasyid Hj Ismail on April 11, 2011, 11:05:46 PM
Do you know that there is template file that need to be  edited / modified to enable this? Open that file and see whether you can do it by yourself. If you cannot, attach that file here so that we can help. Oh yes, the file is default theme folder (and normally custom theme don't have this, so don't bother to find one in there).
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: DanteOz on April 12, 2011, 05:20:24 PM
Thnx for ur reply, I've tried adding it to wireless.template.php with include () function, and placed the ad code in a file in root directory of my forum, but when i visit the wap2 version of the forum i see a small empty white space that the ad is supposed to be... i've attached it below for assistance.
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: Hj Ahmad Rasyid Hj Ismail on April 13, 2011, 09:32:29 AM
I have written some suggestions on how to put adsense in wap here: http://www.simplemachines.org/community/index.php?topic=409734.msg2855381#msg2855381

This one is by another member with working file: http://www.simplemachines.org/community/index.php?topic=259039.msg1998252#msg1998252

Do read it and try it out first.
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: DanteOz on April 13, 2011, 05:31:26 PM
Thnx, i've gone thru those suggestions, it seams they're based on adsense for mobile which is not available in my adsense account cos of d country i am... any other suggestions for admob? thnx for ur help
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: Hj Ahmad Rasyid Hj Ismail on April 13, 2011, 10:59:42 PM
I think the way it works should be the same. Just replace the google adsense code with admob code and see how it goes.
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: DanteOz on April 14, 2011, 03:45:36 AM
Thnx, i tried it, i put d admob code in place of adsense for mobile code and i got this error:

Fatal error: Call to undefined function
admob_request() in /home/
megaxfor/public_html/Themes/
default/Wireless.template.php on
line 942
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: Hj Ahmad Rasyid Hj Ismail on April 14, 2011, 05:41:45 AM
Don't use this one.
Quote from: ahrasis on April 13, 2011, 09:32:29 AM
I have written some suggestions on how to put adsense in wap here: http://www.simplemachines.org/community/index.php?topic=409734.msg2855381#msg2855381
Try to use this one i.e. use the attach template file on this post:
Quote from: ahrasis on April 13, 2011, 09:32:29 AM
This one is by another member with working file: http://www.simplemachines.org/community/index.php?topic=259039.msg1998252#msg1998252
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: DanteOz on April 14, 2011, 02:25:08 PM
Dats wat i used, but it didnt work for me
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: DanteOz on April 17, 2011, 04:46:21 PM
Any further help pls?
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: Hj Ahmad Rasyid Hj Ismail on April 19, 2011, 10:06:13 PM
If you have read http://www.simplemachines.org/community/index.php?topic=409734.msg2855381#msg2855381 and try to apply your mod that way I really think it should work. The only think is you need to know a little bit of php. If you are using adsense, you can simply insert the given code (for mobile) there.

I personally think that the admob code that you attach is not the correct one (as it is incomplete in my view) since if there is an opening to a php code it must be closure too (I didnt test this). It is also too long and should really be just a simple ad code if compared to the given one. Please check again whether it is the right code.
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: DanteOz on April 22, 2011, 03:25:15 PM
Thnx ahrasis for ur continuous assistance, the above code was the right code from admob, but by adding ?> at the end of the code and calling it with php include finally work, or by moving echo admob_request($admob_params); to the end of the ad code and placing everything in the wireless.template.php excluding <?php also worked.
Title: Re: How to place Admob ads in wap2 of 2.0 rc4?
Post by: Hj Ahmad Rasyid Hj Ismail on April 22, 2011, 11:48:35 PM
It has become my best hobby helping people in using SMF though I am just another fellow learner myself. So no problem. I am really glad it helps.