Flutter数字足迹管理插件flutter_linkid_digitalfootprint的使用
Flutter数字足迹管理插件flutter_linkid_digitalfootprint的使用
flutter_linkid_digitalfootprint
LinkId Digital Footprint
开始使用
LinkId Digital Footprint for Flutter
在项目中添加插件:
$ flutter pub add flutter_linkid_digitalfootprint
这将在您的包的pubspec.yaml
文件中添加如下依赖(并运行隐式的dart pub get
):
dependencies:
flutter_linkid_digitalfootprint: ^1.5.6
或者,您的编辑器可能支持dart pub get
或flutter pub get
。请查阅您的编辑器文档以了解更多信息。
使用说明
以下是插件的基本用法示例:
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_linkid_digitalfootprint/text_field_watcher.dart';
import 'package:flutter_linkid_digitalfootprint/flutter_linkid_digitalfootprint.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
[@override](/user/override)
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
[@override](/user/override)
void initState() {
super.initState();
initSDK();
}
void initSDK() async {
// 启用日志打印
FlutterLinkidDigitalFootprint.shared.setShowLog(true);
// 初始化服务
FlutterLinkidDigitalFootprint.shared.initService(
tenantId: "1",
apiKey: "96c3bd74-ba62-46b3-bfdc-cee0ad902639",
url: "https://digitalfootprint-test.linkid.vn");
// 设置推荐ID
FlutterLinkidDigitalFootprint.shared.setReferralId("112233445566");
// 监听焦点变化
focusNode.addListener(() {
print("tuandv8 = ${focusNode.hasFocus}");
setState(() {});
});
}
FocusNode focusNode = FocusNode();
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
const Text('Running on'),
TextFieldWatcher(
name: 'name01',
focusNode: focusNode,
secure: false,
inputBuilder: (context, handle) => TextField(
cursorColor: Colors.black,
onChanged: (value) {
handle.call(value);
},
decoration: const InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15, bottom: 11, top: 11, right: 15),
hintText: "Enter your word"),
),
),
TextFieldWatcher(
inputBuilder: (context, handle) {
return TextField(
onChanged: (text) {
handle(text);
},
);
},
name: 'name02',
),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.logEvent("TestEvent01", data: {'ten': "Tuan", "email": "tuandv@linkid4.vn"});
},
child: const Text("Log Event")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.logEvent("TestEvent02");
},
child: const Text("Log Event 2")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.saveData({'bundle_reg_input_phone_number': "1234567890", "dienthoai": "888888888"});
},
child: const Text("Save Data")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.setCurrentScreen(
"Screen01",
data: {'bundle_reg_input_phone_number': '99999999', 'hovaten': 'khanh'}
);
},
child: const Text("Start Current Screen")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.setCurrentScreen(
"Screen02"
);
},
child: const Text("Start Current Screen 2")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.startScreenFlow("Screen01");
},
child: const Text("Start Screen Flow")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.endScreenFlow("Screen01", data: {'screenKey': 1, 'bundle_reg_input_phone_number': '0966370710'});
},
child: const Text("End Screen Flow"))
],
),
),
),
);
}
}
示例代码
以下是一个完整的示例代码,展示如何使用flutter_linkid_digitalfootprint
插件:
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_linkid_digitalfootprint/text_field_watcher.dart';
import 'package:flutter_linkid_digitalfootprint/flutter_linkid_digitalfootprint.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
[@override](/user/override)
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
[@override](/user/override)
void initState() {
super.initState();
initSDK();
}
void initSDK() async {
// 启用日志打印
FlutterLinkidDigitalFootprint.shared.setShowLog(true);
// 初始化服务
FlutterLinkidDigitalFootprint.shared.initService(
tenantId: "1",
apiKey: "96c3bd74-ba62-46b3-bfdc-cee0ad902639",
url: "https://digitalfootprint-test.linkid.vn");
// 设置推荐ID
FlutterLinkidDigitalFootprint.shared.setReferralId("112233445566");
// 监听焦点变化
focusNode.addListener(() {
print("tuandv8 = ${focusNode.hasFocus}");
setState(() {});
});
}
FocusNode focusNode = FocusNode();
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
const Text('Running on'),
TextFieldWatcher(
name: 'name01',
focusNode: focusNode,
secure: false,
inputBuilder: (context, handle) => TextField(
cursorColor: Colors.black,
onChanged: (value) {
handle.call(value);
},
decoration: const InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding: EdgeInsets.only(
left: 15, bottom: 11, top: 11, right: 15),
hintText: "Enter your word"),
),
),
TextFieldWatcher(
inputBuilder: (context, handle) {
return TextField(
onChanged: (text) {
handle(text);
},
);
},
name: 'name02',
),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.logEvent("TestEvent01", data: {'ten': "Tuan", "email": "tuandv@linkid4.vn"});
},
child: const Text("Log Event")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.logEvent("TestEvent02");
},
child: const Text("Log Event 2")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.saveData({'bundle_reg_input_phone_number': "1234567890", "dienthoai": "888888888"});
},
child: const Text("Save Data")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.setCurrentScreen(
"Screen01",
data: {'bundle_reg_input_phone_number': '99999999', 'hovaten': 'khanh'}
);
},
child: const Text("Start Current Screen")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.setCurrentScreen(
"Screen02"
);
},
child: const Text("Start Current Screen 2")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.startScreenFlow("Screen01");
},
child: const Text("Start Screen Flow")),
ElevatedButton(
onPressed: () {
FlutterLinkidDigitalFootprint.shared
.endScreenFlow("Screen01", data: {'screenKey': 1, 'bundle_reg_input_phone_number': '0966370710'});
},
child: const Text("End Screen Flow"))
],
),
),
),
);
}
}
更多关于Flutter数字足迹管理插件flutter_linkid_digitalfootprint的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter数字足迹管理插件flutter_linkid_digitalfootprint的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
flutter_linkid_digitalfootprint
是一个用于管理数字足迹的 Flutter 插件,通常用于收集和分析用户在应用中的行为数据。以下是如何使用该插件的基本步骤:
1. 添加依赖
首先,你需要在 pubspec.yaml
文件中添加 flutter_linkid_digitalfootprint
插件的依赖。
dependencies:
flutter:
sdk: flutter
flutter_linkid_digitalfootprint: ^1.0.0 # 请使用最新版本
然后运行 flutter pub get
来获取依赖。
2. 初始化插件
在你的 Flutter 应用中初始化插件。通常,你可以在 main.dart
文件中进行初始化。
import 'package:flutter/material.dart';
import 'package:flutter_linkid_digitalfootprint/flutter_linkid_digitalfootprint.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// 初始化插件
await FlutterLinkidDigitalfootprint.init(
appKey: 'YOUR_APP_KEY', // 替换为你的应用密钥
appSecret: 'YOUR_APP_SECRET', // 替换为你的应用密钥
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
3. 收集用户行为数据
你可以在应用的不同部分调用插件的方法来收集用户行为数据。例如,当用户点击某个按钮时,你可以记录该事件。
import 'package:flutter/material.dart';
import 'package:flutter_linkid_digitalfootprint/flutter_linkid_digitalfootprint.dart';
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Demo Home Page'),
),
body: Center(
child: ElevatedButton(
onPressed: () async {
// 记录用户点击事件
await FlutterLinkidDigitalfootprint.trackEvent(
eventName: 'button_click',
eventData: {'button_id': 'home_button'},
);
},
child: Text('Click Me'),
),
),
);
}
}
4. 用户身份识别
如果你需要识别用户身份,可以调用 identifyUser
方法。
await FlutterLinkidDigitalfootprint.identifyUser(
userId: 'USER_ID', // 替换为你的用户ID
userData: {'email': 'user@example.com'}, // 可选的用户数据
);
5. 其他功能
插件可能还提供其他功能,如用户属性更新、事件属性更新等。你可以根据插件的文档来使用这些功能。
6. 处理隐私和合规性
在使用数字足迹管理插件时,确保你遵守相关的隐私法规(如 GDPR、CCPA 等)。你可能需要向用户提供隐私政策,并获得他们的同意。
7. 调试和测试
在开发过程中,你可以使用插件的调试模式来查看收集的数据。
await FlutterLinkidDigitalfootprint.setDebugMode(true);