Serverside电子商务交易推向谷歌分析

时间:2012-01-07 09:08:43

标签: google-analytics e-commerce

我正试图以最少的信息推动电子商务交易 对于分析,以下是两种方法的实现,但没有 似乎工作。这些方法是参考的 论坛上的文档和代码片段。

    public static void pushToGoogleAnalytics(String analyticsCode, String 
domain, String product_sku, String product) { 
                Map<String, String> params=new TreeMap<String, String>(); 
                params.put("utmwv", 4+""); 
                params.put("utmn", new Random().nextInt(2147483647)+""); 
                params.put("utmhn", domain); 
                params.put("utmipc", product_sku); 
                params.put("utmipn", product); 
                params.put("utmtid", product_sku); 
                params.put("utmdt", product); 
                params.put("utmp", "/"); 
                params.put("utmhn", domain); 
                params.put("utmac", analyticsCode); 
                params.put("utmcc", "__utma%3D999.999.999.999.999.1%3B"); 
                try { 
                        byte[] response = URLUtils.get(new URL("http://www.google- 
analytics.com/__utm.gif"), params); 
                } catch (Exception e) { 
                        e.printStackTrace(); 
                } 
        } 




      public static void pushToGoogleAnalytics(String analyticsCode, String 
domain, String product_sku, String product) { 
                String var_utmac = analyticsCode; 
                String var_utmhn = domain; // domain 
                String var_utmn = random(1000000000,2147483647)+""; // random number 
                String var_cookie = random(10000000,99999999)+""; //random cookie 
number 
                String var_random = random(1000000000,2147483647)+""; //number under 
2147483647 
                String var_today = Utils.getNow().getTime()+""; 
                String var_uservar="-"; // no user-defined 
                String urchinUrl="http://www.google-analytics.com/__utm.gif? 
utmwv=3&utmn="+var_utmn+"&utmipc="+product_sku+"&utmipn="+product 
+"&utmtid="+product_sku+"&utmdt=test&utme=&utmcs=-&utmsr=-&utmsc=- 
&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn="+var_utmhn+"&utmhid="+var_utmn 
+"&utmac="+var_utmac+"&utmcc=__utma%3D"+var_cookie+"."+var_random 
+"."+var_today+"."+var_today+"."+var_today+".2%3B%2B__utmz 
%3D"+var_cookie+"."+var_today+".2.2.utmcsr%3D_SOURCE_%7Cutmccn 
%3D_CAMPAIGN_%7Cutmcmd%3D_MEDIUM_%7Cutmctr%3D_KEYWORD_%7Cutmcct 
%3D_CONTENT_%3B%2B__utmv%3D"+var_cookie+"."+var_uservar+"%3B"; 
//              urchinUrl=urchinUrl.replace("&", "&amp;"); 
                byte[] response = URLUtils.readURL(urchinUrl); 
                System.err.println("google analytics push URL: "+urchinUrl); 
        } 

1 个答案:

答案 0 :(得分:1)

请查看我最近发布的this article有关通过Python将数据推送到Google Analytics的信息。

请注意,它只为您提供最低限度,您可以轻松将其转换为您喜欢的语言。您需要添加与电子商务相关的参数。