Integrate analytics code [Solved]

A place to make for-pay "CMS made simple" job offerings
Post Reply
User avatar
mobilexhtml
Forum Members
Forum Members
Posts: 28
Joined: Fri Feb 08, 2008 11:12 pm
Location: Norway

Integrate analytics code [Solved]

Post by mobilexhtml »

I have admob analytics and would like to integrate the analytics code and still be able to validate for xhtml mp 1.0 and see no change in design.

I got the code available in : php curl, php fsockopen, J2se1.4, J2se5, C#, Cgi/Perl, Ruby on rails, VB.net, VBscript ASP...

Also I would like the recipe for this only, as I would like to try to do it my self..  ::)

Would it be possible to insert code in the meta tag section ? or only via UDT ?

And how much $ ?

-John
Last edited by mobilexhtml on Wed Feb 18, 2009 3:13 am, edited 1 time in total.
User avatar
aln_cms
Forum Members
Forum Members
Posts: 88
Joined: Mon Jan 08, 2007 7:09 pm
Location: Ireland

Re: Integrate analytics code

Post by aln_cms »

if I understand you correctly, all you need to do is create a UDT {myanalytics} with the following content :

echo ' ';

bobs your uncle!
--
Alan Ryan
Lead Developer
CodeCrunchers Internet Software Development - Ireland
http://www.codecrunchers.ie
User avatar
mobilexhtml
Forum Members
Forum Members
Posts: 28
Joined: Fri Feb 08, 2008 11:12 pm
Location: Norway

Re: Integrate analytics code

Post by mobilexhtml »

Howdy..

This is the J2se5 code:   ???



admobRequiredParams = new HashMap();
Map admobControlParams = new HashMap();
Map admobOptionalParams = new HashMap();

admobRequiredParams.put("ANALYTICS_ID", "na"); // 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.
admobRequiredParams.put("COOKIE_DOMAIN", null); // If your mobile site uses multiple subdomains, replace "null" with your root domain (e.g. "example.com") to make the AdMob cookie visible across subdomains.
admobControlParams.put("ANALYTICS_REQUEST", true); // To enable the collection of analytics data, set to true.
admobControlParams.put("TEST_MODE", false);  // 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/AdCodeD ... ation   
// admobOptionalParams.put("title", "Enter Page Title Here"); // Analytics allows you to track site usage based on custom page titles. Enter custom title in this parameter.
// admobOptionalParams.put("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

// Send request to AdMob. To make additional ad requests per page, copy and paste this function call elsewhere on your page.
out.print(admobRequest(request, response, pageContext, admobRequiredParams, admobControlParams, admobOptionalParams));
%>

requiredParams, Map controlParams, Map optionalParams) {
  if (requiredParams == null || controlParams == null)
    return "";

  StringBuilder admobReturn = new StringBuilder();
  try {
    Boolean adMode = false;
    if (requiredParams.get("PUBLISHER_ID") != null && controlParams.get("AD_REQUEST") != null)
      adMode = controlParams.get("AD_REQUEST");
     
    Boolean analyticsMode = false;
    Boolean pixelSent = (pageContext.getAttribute("admobPixelSent") == "true") ? true : false;
    if (requiredParams.get("ANALYTICS_ID") != null && controlParams.get("ANALYTICS_REQUEST") != null && !pixelSent)
      analyticsMode = controlParams.get("ANALYTICS_REQUEST");
     
    String rt = adMode ? (analyticsMode ? "2" : "0") : (analyticsMode ? "1" : "-1");
    if (rt == "-1") return "";
   
    double now = System.currentTimeMillis()/(double)1000;
    DecimalFormat df = new DecimalFormat("0.000");
    String z = df.format(now);
    String p = request.getRequestURL().toString() + (request.getQueryString() == null ? "" : "?" + request.getQueryString().toString());
    String o = admobGetCookieValue(request, response, pageContext, requiredParams.get("COOKIE_DOMAIN"));
   
    StringBuilder admobContents = new StringBuilder();
    admobAppendParams(admobContents, "rt", rt);
    admobAppendParams(admobContents, "z", z);
    admobAppendParams(admobContents, "u", request.getHeader("User-Agent"));
    admobAppendParams(admobContents, "i", request.getRemoteAddr());
    admobAppendParams(admobContents, "p", p);
    admobAppendParams(admobContents, "t", admobMd5(request.getSession() == null ? null : request.getSession().getId()));
    admobAppendParams(admobContents, "v", "20081105-JAVA15-b9c74666c607fc70");
    admobAppendParams(admobContents, "o", o);
    if (adMode) admobAppendParams(admobContents, "s", requiredParams.get("PUBLISHER_ID"));
    if (analyticsMode) admobAppendParams(admobContents, "a", requiredParams.get("ANALYTICS_ID"));
   
    if (optionalParams != null) {
      for (Map.Entry entry : optionalParams.entrySet()) {
        admobAppendParams(admobContents, entry.getKey(), entry.getValue());
      }
    }
   
    List ignoreHeaders = Arrays.asList(new String[]{"PRAGMA", "CACHE-CONTROL", "CONNECTION", "USER-AGENT", "COOKIE"});
    for (Enumeration names = request.getHeaderNames(); names.hasMoreElements()Wink {
      String name = names.nextElement();
      if (!ignoreHeaders.contains(name.toUpperCase()))
        admobAppendParams(admobContents, "h["+name+"]", request.getHeader(name));
    }

    if (controlParams.get("TEST_MODE") != null && controlParams.get("TEST_MODE")) admobContents.append("&m=test");
   
    BufferedReader admobReader = null;
    int ADMOB_TIMEOUT = 1000; // 1 second timeout
    long start = System.currentTimeMillis();
    try {
      URL admob_url = new URL("http://r.admob.com/ad_source.php");
      HttpURLConnection admobConnection = (HttpURLConnection)admob_url.openConnection();
      admobConnection.setRequestMethod("POST");
      admobConnection.setDoOutput(true);
      admobConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      admobConnection.setRequestProperty("Content-Length", Integer.toString(admobContents.length()));
      admobConnection.setConnectTimeout(ADMOB_TIMEOUT);
      admobConnection.setReadTimeout(ADMOB_TIMEOUT);
      BufferedWriter admobWriter = new BufferedWriter(new OutputStreamWriter(admobConnection.getOutputStream()));
      admobWriter.write(admobContents.toString());
      admobWriter.close();
      admobReader = new BufferedReader(new InputStreamReader(admobConnection.getInputStream()));
     
      for (String line; (line = admobReader.readLine()) != null;)
        admobReturn.append(line);
    }
    catch (Exception e) {admobReturn.setLength(0);}
    finally {if (admobReader != null) admobReader.close();}
    long stop = System.currentTimeMillis();
   
    if (!pixelSent) {
      pageContext.setAttribute("admobPixelSent", "true");
      admobReturn.append("");
    }
  }
  catch (Exception e) {}
  return admobReturn.toString();
}

private String admobGetCookieValue(HttpServletRequest request, HttpServletResponse response, PageContext pageContext, String cookieDomain) {
  try {
    Cookie cookies[] = request.getCookies();
    if (cookies != null) {
      for (int i = 0; i 0) {
    if (contents.length() > 0) contents.append("&");
    contents.append(URLEncoder.encode(key, "UTF-8")).append("=").append(URLEncoder.encode(val, "UTF-8"));
  }
}
%>


and putting it in just leaves a mess...

-John
Last edited by mobilexhtml on Wed Jan 28, 2009 10:52 pm, edited 1 time in total.
User avatar
aln_cms
Forum Members
Forum Members
Posts: 88
Joined: Mon Jan 08, 2007 7:09 pm
Location: Ireland

Re: Integrate analytics code

Post by aln_cms »

ah, I mis understood you.. Off to my bed.... I'll get back to this in the morning.  You're going to have to have a server with a servlet environment running .
--
Alan Ryan
Lead Developer
CodeCrunchers Internet Software Development - Ireland
http://www.codecrunchers.ie
User avatar
mobilexhtml
Forum Members
Forum Members
Posts: 28
Joined: Fri Feb 08, 2008 11:12 pm
Location: Norway

Re: Integrate analytics code

Post by mobilexhtml »

Okelidokely...  ???  :)
viebig

Re: Integrate analytics code

Post by viebig »

show us the php curl code
User avatar
duclet
Forum Members
Forum Members
Posts: 187
Joined: Fri Jun 23, 2006 12:55 pm

Re: Integrate analytics code

Post by duclet »

That code is not even PHP so it can't be inserted.
User avatar
aln_cms
Forum Members
Forum Members
Posts: 88
Joined: Mon Jan 08, 2007 7:09 pm
Location: Ireland

Re: Integrate analytics code

Post by aln_cms »

Hi,

What duclet says is correct - the easiest way would be to have PHP code that you could just embed into the UDT - can you point us to the PHP CURL code that you have. 

On the other hand I have always wondered about having  Java capability within CMSMS - there seems to be some PECL libraries available but I'd imagine you'd need some control over your server - shared hosting probably wouldn't have this capability.

Show  us the PHP-CURL code....
--
Alan Ryan
Lead Developer
CodeCrunchers Internet Software Development - Ireland
http://www.codecrunchers.ie
User avatar
mobilexhtml
Forum Members
Forum Members
Posts: 28
Joined: Fri Feb 08, 2008 11:12 pm
Location: Norway

Re: Integrate analytics code

Post by mobilexhtml »

Ok here goes...




'na', // 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.
  'ANALYTICS_REQUEST' => true, // To enable the collection of analytics data, set to TRUE.
  'TEST_MODE'        => false, // 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 ? 2 : 0) : ($analytics_mode ? 1 : -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($k, 0, 4) == '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($request, CURLOPT_URL, 'http://r.admob.com/ad_source.php');
  curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($request, CURLOPT_TIMEOUT, $request_timeout);
  curl_setopt($request, CURLOPT_CONNECTTIMEOUT, $request_timeout);
  curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Connection: Close'));
  curl_setopt($request, CURLOPT_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 .= "';
  }
 
  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', $value, mktime(0, 0, 0, 1, 1, 2038), $path, $domain)) {
      $_COOKIE['admobuu'] = $value; // make it visible to admob_request()
    }
  }
}
User avatar
mobilexhtml
Forum Members
Forum Members
Posts: 28
Joined: Fri Feb 08, 2008 11:12 pm
Location: Norway

Re: Integrate analytics code

Post by mobilexhtml »

Anyone ?
User avatar
mobilexhtml
Forum Members
Forum Members
Posts: 28
Joined: Fri Feb 08, 2008 11:12 pm
Location: Norway

Re: Integrate analytics code

Post by mobilexhtml »

I have cash for this project, and I need to use them now.. Does anyone want to do this for some money ? If not,  I will be forced to use my money on hookers and booze... Please help me avoid that...

-John
viebig

Re: Integrate analytics code

Post by viebig »

I´ll do it, contact me at viebig at gmail dot com, or PM me or msn viebig at hotmail dot com

200% satisfaction guaranteed, 1 day at most.
Post Reply

Return to “Help Wanted (commercial)”