nativeScript-google-analytics-demographics
将原生 Google 分析 iOS 和 Android 小部件集成到 NativeScript 中,支持人口统计数据
npm i --save nativescript-google-analytics-demographics
- 版本:0.3.5
- GitHub: https://github.com/markhatchell/nativescript-google-analytics
- NPM: https://npmjs.net.cn/package/nativescript-google-analytics-demographics
- 下载量
- 昨天: 0
- 上周: 0
- 上个月: 0
NativeScript Google Analytics
发布说明
添加插件
tns plugin add nativescript-google-analytics-demographics
获取配置文件
- iOS 指令
- Android 指令
- 点击“获取配置文件”的说明
- 将刚下载的平台特定配置文件添加到相应的 App_Resources/{platform} 文件夹
在 app.js 中初始化追踪器
纯 JavaScript
var application = require("application");
var googleAnalytics = require("nativescript-google-analytics");
application.mainModule = "main-page";
application.cssFile = "./app.css";
if (application.ios) {
//iOS
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var appDelegate = (function (_super) {
__extends(appDelegate, _super);
function appDelegate() {
_super.apply(this, arguments);
}
appDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (application, launchOptions) {
initAnalytics(); //Module Code to initalize
};
appDelegate.ObjCProtocols = [UIApplicationDelegate];
return appDelegate;
})(UIResponder);
application.ios.delegate = appDelegate;
}else{
//ANDROID
application.on(application.launchEvent, function (args) {
initAnalytics(); //Module Code to initalize
});
}
application.start();
function initAnalytics(){
googleAnalytics.initalize({
trackingId: "UA-XXXXXXXX-1", //YOUR Id from GA
//userId: "9ac7a034-ffde-4783-8374-f78b3df39d32", //Optional
dispatchInterval: 5,
logging: {
native: true,
console: false
}
});
}
TypeScript
var application = require("application");
import * as googleAnalytics from "nativescript-google-analytics";
application.mainModule = "main-page";
application.cssFile = "./app.css";
if (application.ios) {
//iOS
class MyDelegate extends UIResponder implements UIApplicationDelegate {
public static ObjCProtocols = [UIApplicationDelegate];
applicationDidFinishLaunchingWithOptions(application: UIApplication, launchOptions: NSDictionary): boolean {
initAnalytics(); //Module Code to initalize
return true;
}
}
application.ios.delegate = MyDelegate;
}else{
//ANDROID
application.on(application.launchEvent, function (args) {
initAnalytics(); //Module Code to initalize
});
}
application.start();
function initAnalytics(){
googleAnalytics.initalize({
trackingId: "UA-XXXXXXXX-1", //YOUR Id from GA
//userId: "9ac7a034-ffde-4783-8374-f78b3df39d32", //Optional
dispatchInterval: 5,
logging: {
native: true,
console: false
}
});
}
方法
初始化选项
// category and action are not optional, label and value are
googleAnalytics.initalize(
{
trackingId: "UA-XXXXXXX-1",
userId: "(some userid value)", //Optional! Needs to be enabled on the tracking account: https://support.google.com/analytics/answer/3123666#FindTheUserID
dispatchInterval: 30, //(Value in seconds)...Default Android is 30 minutes, default iOS is 2 minutes (120 seconds). Disable by setting to 0.
logging: {
native: false, //Default false, should not be used in production
console: false
}
});
记录事件
// category and action are not optional, label and value are
googleAnalytics.logEvent(
{
category: "MyCategory",
action: "MyAction",
label: "MyLabel",
value: 7
});
记录屏幕视图
// category and action are not optional, label and value are
googleAnalytics.logView("Secondary-Page");
刷新消息队列(分发)
googleAnalytics.dispatch();
记录异常
googleAnalytics.logException({
description: "Cat tried to divide by 0...",
fatal: true //Optional, default false... if true will be a "Crash" in GA. False is an "Exception"
});
//or
googleAnalytics.logException("Ergmagerd excerpshern");
记录时间
//OPTION 1: Auto (Time is stored internally, just call stopTimer when you're done)
googleAnalytics.startTimer("Logo Timer", {
category: "Animations",
name: "Rotate the logo", //Optional
label: (application.ios) ? "iOS" : "Android" //Optional
});
/* ... time passes as you do something ... */
googleAnalytics.stopTimer("Logo Timer");
//OPTION 2: Raw, calculate and send yourself
googleAnalytics.logTimingEvent({
category: "Animations",
value: diffMilliseconds, //Milliseconds, example 4000
name: "Rotate the logo", //Optional
label: "Some Label" //Optional
});
问题
Android
错误:找不到 com.google.android.gms:play-services-analytics:8.4.0
解决方案:*打开 Android Studio SDK 管理器,确保所有构建工具都已更新。然后确保您的 Google Play 服务和 Google 仓库包都已更新。在 Android Studio SDK 管理器中,您可以在“SDK 工具”标签下找到它们。如果您正在使用独立的 SDK 管理器,请滚动到页面的“附加组件”部分并更新它们* *