0

我已经从(https://marketplace.appcelerator.com/apps/5081?2014113336)下载了谷歌分析模块。

我不知道如何使用这个模块(因为我第一次使用模块)来跟踪我的应用程序事件和下载,请任何人帮助我。这是我的代码

//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;
4

1 回答 1

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);
于 2013-06-24T13:12:54.040 回答