GrowingIO 埋点(目前仅Android端)
注册好 GrowingIO 账号后,选择应用管理 → 添加应用 → 选择第三方平台,Flutter 分别选择运行平台为 Android 、 ios → 填写应用名称 → 按照官方给予的SDK安装步骤一次操作即可:
1、集成Flutter插件
1.1 添加依赖,编辑 pubspec.yaml
文件:
dependencies:
flutter_growingio_track: ^2.6.0
1.2 安装插件
flutter pub get
1.3 添加导包代码使用埋点插件,在需要自定义事件或者变量的页面引入包依赖
import 'package:flutter_growingio_track/flutter_growingio_track.dart';
2、集成Android
原生 SDK
2.1 导入SDK
编辑 app/build.gradle
文件中添加 com.growingio.android
插件、vds-android-agent
依赖和对应的资源;
apply plugin: 'com.android.application'
android {
defaultConfig {
//添加 growingio_project_id 和 growingio_url_scheme (平台会自动生成)
resValue("string", "growingio_project_id", "8293ef4552c9be54")
resValue("string", "growingio_url_scheme", "growing.c8a606bcae023aac")
}
dependencies{
// 添加 (平台会自动生成)
implementation 'com.growingio.android:vds-android-agent:track-2.8.13'
}
}
2.2 添加 URLScheme
把URL Scheme
添加到您的项目,以便我们唤醒您的程序,进行圈选。将该产品的 URLScheme
添加到你的 AndroidManifest.xml
中的 LAUNCHER Activity
下。例如
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.growingio.testdemo">
<!-- 添加权限 -- >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:AllowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
<!--请注意<application/>标签中的name属性值, 必须为您的Application类-->
android:name=".MyApplication"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!--添加一整个 intent-filter 区块,并确保其中只有一个 data 字段-->
<intent-filter>
<data android:scheme="growing.c8a606bcae023aac"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
</manifest>
2.3 初始化 SDK
请点击 Android studio
中的 Sync Now
按钮依赖 sdk
成功后,按照以下照示例代码修改您的 Application
文件:
import com.growingio.android.sdk.collection.Configuration;
import com.growingio.android.sdk.collection.GrowingIO;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
GrowingIO.startWithConfiguration(this, new Configuration()
.setTestMode(BuildConfig.DEBUG)
.setDebugMode(BuildConfig.DEBUG)
.setChannel("XXX应用商店")
);
}
}
注意: 如果找不到,可以在 android/app/src/main
下新建项目目录:若 applicationId
为com.example.growingio.testdemo
,则新建目录为 com/example/growingio/testdemo
, 在该目录下新建一个名为 MyApplication的Application
文件(完整目录为:android/app/src/main/com/example/growingio/testdemo/MyApplication.java
)
2.4 相应的页面或组件中,定义上传事件
自定义事件
GrowingIO.setEvar({
'testKey': 'testValue', 'testNumKey': 2333.0
});
到此,GrowingIO埋点Android基本完成,但是一定要注意,清楚项目build包,并重启项目,多操作几次才能成功(本人需要关闭编辑器,再次启动项目才成功,坑惨了。。。。)
3、集成 Ios
原生 SDK
(参考:https://growingio.kf5.com/hc/kb/article/1334925/)
3.1、添加依赖 (通过 Cocoapods
快速添加)
3.1.1、在项目的 ios
目录下的 Podfile
文件中添加 pod "GrowingCoreKit"
// 我的项目中的 Podfile 文件内容
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
install!'cocoapods',:deterministic_uuids=>false
platform :ios, '8.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
end
generated_key_values = {}
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) do |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
generated_key_values[podname] = podpath
else
puts "Invalid plugin specification: #{line}"
end
end
generated_key_values
end
target 'Runner' do
# Flutter Pod
copied_flutter_dir = File.join(__dir__, 'Flutter')
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
unless File.exist?(generated_xcode_build_settings_path)
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
unless File.exist?(copied_framework_path)
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
end
unless File.exist?(copied_podspec_path)
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
end
end
# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter', :path => 'Flutter'
// 微信 SDK
pod 'WechatOpenSDK'
// GrowingIO埋点 SDK
pod 'GrowingCoreKit'
# Plugin Pods
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.each do |name, path|
symlink = File.join('.symlinks', 'plugins', name)
File.symlink(path, symlink)
pod name, :path => File.join(symlink, 'ios')
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '8.0'
end
end
end
3.1.2、执行 pod install
或 pod update
更新 pod
依赖库。
根据你项目的环境可能会报各种错误,百度解决的。
3.1.3、 添加 URL Scheme
growingIO 会自动生成相应的 URL Scheme
Xcode中,找到Targets 下面的info选项卡,在URL Types中添加对应的url scheme
注意: growingIO
对 IOS
端的埋点数据信息采集 会有 1~2个 小时
的延迟(即不能及时在平台端看见访问信息),但安卓端貌似没有这个问题