tokuhirom
11/19/2010 - 8:30 AM

google analystics mobile on plack.

google analystics mobile on plack.

--- ga.pl.org   2010-11-19 17:20:38.000000000 +0900
+++ ga.pl       2010-11-19 17:28:37.000000000 +0900
@@ -2,6 +2,8 @@
 #
 #  Copyright 2009 Google Inc. All Rights Reserved.
 
+package Google::Analytics::Mobile;
+
 use CGI;
 use Digest::MD5 qw(md5_hex);
 use LWP::UserAgent;
@@ -29,7 +31,7 @@
     0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
     0x02, 0x44, 0x01, 0x00, 0x3b);
 
-my $query = new CGI;
+our $query;
 
 # The last octect of the IP address is removed to anonymize the user.
 sub get_ip {
@@ -200,4 +202,13 @@
   write_gif_data($new_cookie, $utm_url);
 }
 
-track_page_view();
+use CGI::Emulate::PSGI;
+sub to_app {
+    CGI::Emulate::PSGI->handler(sub {
+        CGI::initialize_globals();
+        local $query = CGI->new();
+        track_page_view();
+    });
+}
+
+1;