【问题标题】:How to use google analytics module in titanium android app?如何在钛 android 应用程序中使用谷歌分析模块?
【发布时间】:2013-06-24 11:40:18
【问题描述】:

我已从 (https://marketplace.appcelerator.com/apps/5081?2014113336) 下载了 Google Analytics 模块。

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

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

【问题讨论】:

    标签: android module google-analytics


    【解决方案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 把它写出来给谷歌。

    ...
    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);
    

    【讨论】:

    • 我认为事务部分与GA的另一部分有关。 IE。除了 trackEvent(),你不需要其他任何东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-02
    • 2022-06-21
    相关资源
    最近更新 更多