2013-06-24 28 views
0

我已經從(https://marketplace.appcelerator.com/apps/5081?2014113336)下載了Google Analytics(分析)模塊。如何在鈦android應用程序中使用谷歌分析模塊?

我不知道如何使用這個模塊(因爲我第一次使用模塊)來跟蹤我的應用程序事件和下載,請任何人都幫助我。這裏是我的代碼

//Application Window Component Constructor 
function ApplicationWindow() { 
var win = Ti.UI.createWindow({ 
     backgroundImage:'ui/handheld/android/images/Background_320x480.png', 
     tabBarHidden:true 
}); 
win.orientationModes = [Ti.UI.PORTRAIT]; 

var screenWidth = Ti.Platform.displayCaps.platformWidth; 
var screenHeight = Ti.Platform.displayCaps.platformHeight; 

function GetHeight(value) { 
     var temp = (value * 100)/320; 
     return parseInt((screenHeight * temp)/100); 
} 

function GetWidth(value) { 
     var temp = (value * 100)/240; 
     return parseInt((screenWidth * temp)/100); 
} 

var parent = Ti.UI.createView({}); 

//Set up analytics 
      var GA = require("analytics.google"); 
      GA.debug = true; 
      //GA.trackUncaughtExceptions = true; 

      var tracker = GA.getTracker("UA-41976730-1"); 

var image1 = Ti.UI.createImageView({ 
     image:"images/settings.png", 
     top:'10', 
     right:'8' 
}); 
parent.add(image1); 

image1.addEventListener('click', function() { 
     var win4 = Ti.UI.createWindow({ 
     title: 'Settings', 
     url: "settings.js", 
     tabBarHidden:true 
     }); 
    win4.open({modal:true}); 
}); 

var image2 = Ti.UI.createImageView({ 
     image:'images/.png', 
     layout:'horizontal', 
//  left: GetWidth(35), 
     top:40 
}); 
parent.add(image2); 

var image3 = Ti.UI.createImageView({ 
     image:'images/NewsButton.png', 
     top : GetHeight(85), 
     left : GetWidth(35) 
}); 
parent.add(image3); 

image3.addEventListener('click', function() { 
     var win2 = Ti.UI.createWindow({ 
     title: 'Industry News', 
     tabBarHidden:true, 
     backgroundColor:"white" 
     }); 
     win2.orientationModes = [Ti.UI.PORTRAIT,Ti.UI.LANDSCAPE_LEFT,Ti.UI.LANDSCAPE_RIGHT]; 
      var webview = Titanium.UI.createWebView({ 
        url:'' 
     }); 
     win2.add(webview); 

     win2.open({modal:true}); 
}); 

var label1 = Ti.UI.createLabel({ 
     text:'Industry News', 
     color:'#0768A9', 
     width:'auto', 
     height:'auto', 
     font:{fontFamily:'Trebuchet MS',fontWeight:'bold'}, 
     top : GetHeight(150), 
     left : GetWidth(32) 
}); 
parent.add(label1); 

var image4 = Ti.UI.createImageView({ 
     image:'images/BlogButton.png', 
     top : GetHeight(85), 
     right : GetWidth(35) 
}); 
parent.add(image4); 

image4.addEventListener('click', function() { 
     var win3 = Ti.UI.createWindow({ 
       title: 'Software Alerts', 
       tabBarHidden:true, 
       backgroundColor:"white" 
     }); 
     win3.orientationModes = [Ti.UI.PORTRAIT,Ti.UI.LANDSCAPE_LEFT,Ti.UI.LANDSCAPE_RIGHT]; 
     var webview = Titanium.UI.createWebView({ 
       url:'' 
     }); 


     win3.add(webview); 
     win3.open({modal:true}); 
}); 

var label2 = Ti.UI.createLabel({ 
     text:'Software Alerts', 
     color:'#0768A9', 
     width:'auto', 
     height:'auto', 
     font:{fontFamily:'Trebuchet MS',fontWeight:'bold'}, 
     top : GetHeight(150), 
     right : GetWidth(29) 
}); 
parent.add(label2); 

var image5 = Ti.UI.createImageView({ 
     image:'images/TVButton.png', 
     top : GetHeight(185), 
     left : GetWidth(35) 
}); 
parent.add(image5); 

image5.addEventListener('click', function() { 
     var win4 = Ti.UI.createWindow({ 
       backgroundColor:'#fff', 
       title: ' TV', 
       url: "Pages/tv.js", 
       tabBarHidden:true 
     }); 



     win4.open({modal:true}); 
}); 

var label3 = Ti.UI.createLabel({ 
     text:'TV', 
     color:'#0768A9', 
     width:'auto', 
     height:'auto', 
     font:{fontFamily:'Trebuchet MS',fontWeight:'bold'}, 
     top : GetHeight(250), 
     left : GetWidth(50) 
}); 
parent.add(label3); 

var image6 = Ti.UI.createImageView({ 
     image:'images/LibraryButton.png', 
     top : GetHeight(185), 
     right : GetWidth(35) 
}); 
parent.add(image6); 

image6.addEventListener('click', function() { 
     var win5 = Ti.UI.createWindow({ 
       title: 'Knowledge Library', 
       tabBarHidden:true 
     }); 
     win5.orientationModes = [Ti.UI.PORTRAIT,Ti.UI.LANDSCAPE_LEFT,Ti.UI.LANDSCAPE_RIGHT] 
     var webview = Titanium.UI.createWebView({ 
       url:'' 
     }); 


     win5.add(webview); 
     win5.open({modal:true}); 
}); 

var label4 = Ti.UI.createLabel({ 
     text:'Knowledge Library', 
     color:'#0768A9', 
     width:'auto', 
     height:'auto', 
     font:{fontFamily:'Trebuchet MS',fontWeight:'bold'}, 
     top : GetHeight(250), 
     right : GetWidth(20) 
}); 
parent.add(label4); 

win.add(parent); 

return win; 

if(Titanium.Network.networkType == Titanium.Network.NETWORK_NONE){ 
var alertDialog = Titanium.UI.createAlertDialog({ 
      title: 'WARNING!', 
      message: 'Check your network connection and try again.', 
      buttonNames: ['OK'] 
     }); 
     alertDialog.show(); 
} 
} 

module.exports = ApplicationWindow; 
+0

什麼問題? – likeitlikeit

回答

1

該模塊的創建者提出了一些方向。 https://github.com/MattTuttle/titanium-google-analytics/blob/master/mobile/ios/documentation/index.md

您似乎缺少一些trackEvents:

var GA = require('analytics.google'); 
var tracker = GA.getTracker("UA-XXXXXXX-X"); 
tracker.trackEvent({ 
    category: "my event category", 
    action: "clicked", 
    label: "how many (c)licks?", 
    value: 3 
}); 

他也有一個例子app.js文件: https://github.com/MattTuttle/titanium-google-analytics/blob/master/mobile/ios/example/app.js

看來,你寫這些事件追蹤後,您需要創建一個交易,然後trackTransation將其寫入Google。

... 
var transaction = GA.makeTransaction({ 
    id: "hi", 
    tax: 0.6, 
    shipping: 0, 
    revenue: 24.99 * 0.7 
}); 
transaction.addItem({ 
    sku: "ABC123", 
    name: "My Alphabet", 
    category: "product category", 
    price: 24.99, 
    quantity: 1 
}); 
tracker.trackTransaction(transaction); 
+0

我認爲交易部分與GA的另一部分有關。即除了trackEvent()之外,你不需要其他任何東西。 – Federico

相關問題