### GrowingTracker.startWithConfiguration Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Initializes the GrowingIO SDK with the provided configuration. This method is essential for starting data collection. ```APIDOC ## GrowingTracker.startWithConfiguration — 埋点 SDK 初始化 仅自动采集访问和 APP 关闭事件,其余事件需手动调用 API。 ```java // MyApplication.java(仅埋点 SDK) public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); GrowingTracker.startWithConfiguration(this, new CdpTrackConfiguration("your_project_id", "your_url_scheme") .setDataCollectionServerHost("https://your-server.com") .setDataSourceId("your_data_source_id") .setChannel("Google Play") .setDebugEnabled(BuildConfig.DEBUG) // 可选:自定义事件是否携带页面路径 .setCustomEventWithPath(true) // 可选:数据缓存有效期(3-30 天),默认 7 天 .setDataValidityPeriod(7) ); } } ``` ``` -------------------------------- ### Configure Autotrack with Page Rules and WebView Bridge Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Start the SDK with a configuration that includes advanced autotrack settings. Define page alias rules using exact names or regular expressions, and configure WebView bridging and Fragment tag usage for automatic tracking. ```java GrowingAutotracker.startWithConfiguration(this, new CdpAutotrackConfiguration("project_id", "url_scheme") .setDataCollectionServerHost("https://your-server.com") .setDataSourceId("data_source_id") // 无埋点配置 .addConfiguration( new AutotrackConfig() // 通过代码添加页面别名规则(无需手动调用 autotrackPage) .addPageRule("首页", "com.example.MainActivity") .addPageRule("商品详情", "com.example.ProductDetailActivity") // 支持正则匹配 .addPageMatchRule("com.example..*Fragment") // 带属性的页面规则 .addPageRuleWithAttributes("订单页", "com.example.OrderActivity", Collections.singletonMap("page_type", "order")) // 是否启用 WebView 自动桥接(默认 true) .setWebViewBridgeEnabled(true) // 是否使用 Fragment Tag 作为页面标识 .enableFragmentTag(true) ) ); ``` -------------------------------- ### Enable Data Collection Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Use this API to programmatically enable data collection within the GrowingIO SDK. Call this when you want to start tracking events. ```java GrowingTracker.get().setDataCollectionEnabled(true); ``` -------------------------------- ### Enable/Disable Data Collection Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Control whether the GrowingIO SDK should collect data. Call `setDataCollectionEnabled(true)` to start collection and `setDataCollectionEnabled(false)` to stop it. ```java GrowingAutotracker.get().setDataCollectionEnabled(true); ``` -------------------------------- ### Get A/B Test Experiment Data Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Retrieve A/B testing experiment group information based on traffic stratification IDs after registering modules with ABTestConfig. Supports cached and immediate fetch modes. ```java // 1. 在 Application 初始化时注册 ABTest 模块 GrowingAutotracker.get().registerComponent( new ABTestLibraryGioModule(), new ABTestConfig() .setAbTestServerHost("https://ab.your-server.com") .setAbTestExpired(10, TimeUnit.MINUTES) // 缓存有效期,范围 1min-24h .setAbTestTimeout(5, TimeUnit.SECONDS) // 请求超时,最小 1s ); // 2. 获取 A/B 实验数据(优先读缓存) GrowingAutotracker.get().getAbTest("homepage_layout_layer", new ABTestCallback() { @Override public void onABExperimentReceived(ABExperiment experiment, int dataType) { // dataType: ABTEST_CACHE=缓存, ABTEST_HTTP=网络, ABTEST_EXPIRED=过期缓存 String strategy = experiment.getExpStrategyName(); if ("layout_b".equals(strategy)) { showNewHomepageLayout(); } else { showDefaultLayout(); } } @Override public void onABExperimentFailed(Exception error) { // 获取失败时使用默认策略 showDefaultLayout(); } }); // 3. 强制绕过缓存,立即从服务端获取最新实验数据 GrowingAutotracker.get().getAbTestImmediately("homepage_layout_layer", callback); ``` -------------------------------- ### SDK 初始化配置 Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 在 Application 的 onCreate 方法中调用 GrowingAutotracker.startWithConfiguration 进行 SDK 初始化。如果之前集成了旧版本 SDK,需要先调用 upgrade 方法进行数据迁移。 ```java public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); //如果你之前集成的是3.0.0版本之前的SDK,请还需要初始化upgrade,将进行本地数据的迁移。 GrowingIO.getInstance().upgrade(this); //初始化无埋点SDK GrowingAutotracker.startWithConfiguration(this, new CdpAutotrackConfiguration("exampleProjectId", "exampleUrlScheme") .setDataCollectionServerHost("http://myhost.com/") .setDataSourceId("exampleSourceId") .setChannel("XXX应用商店") .setDebugEnabled(BuildConfig.DEBUG) ); } } ``` -------------------------------- ### Initialize GrowingIO SDK with Configuration Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Initialize the GrowingIO SDK with essential configuration parameters like project ID and URL scheme. Additional configurations for data collection and filtering can be chained. ```java GrowingAutotracker.startWithConfiguration(this, new CdpAutotrackConfiguration("exampleProjectId", "exampleUrlScheme") ... .setExcludeEvent(EventExcludeFilter.of(EventExcludeFilter.EVENT_MASK_TRIGGER) ); ``` -------------------------------- ### SDK Initialization Configuration Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Initialize the GrowingIO SDK by calling `GrowingTracker.startWithConfiguration` in your Application's `onCreate` method. ```APIDOC ## SDK Initialization Configuration Add the following `GrowingTracker.startWithConfiguration` call to your `Application`'s `onCreate` method: ```java public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); GrowingTracker.startWithConfiguration(this, new CdpTrackConfiguration("exampleProjectId", "exampleUrlScheme") .setDataCollectionServerHost("http://myhost.com/") .setDataSourceId("exampleSourceId") .setChannel("XXX应用商店") .setDebugEnabled(BuildConfig.DEBUG) ); } } ``` ``` -------------------------------- ### Get Device ID Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Retrieve the device ID, also known as the anonymous user ID, which is automatically generated by the SDK to identify a unique device. ```APIDOC ## Get Device ID ### Description Retrieve the device ID, also known as the anonymous user ID, which is automatically generated by the SDK to identify a unique device. This may return null if the SDK is not initialized or the collection switch is off, and may involve I/O operations. ### Method Signature ```java GrowingTracker.get().getDeviceId(); ``` ### Response - **deviceId** (String) - The unique device identifier. ``` -------------------------------- ### Initialize GrowingTracker with Configuration Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Initialize the GrowingIO SDK with project ID, URL scheme, and server configuration. Optional parameters include data source ID, channel, debug mode, custom event path inclusion, and data validity period. ```java public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); GrowingTracker.startWithConfiguration(this, new CdpTrackConfiguration("your_project_id", "your_url_scheme") .setDataCollectionServerHost("https://your-server.com") .setDataSourceId("your_data_source_id") .setChannel("Google Play") .setDebugEnabled(BuildConfig.DEBUG) // 可选:自定义事件是否携带页面路径 .setCustomEventWithPath(true) // 可选:数据缓存有效期(3-30 天),默认 7 天 .setDataValidityPeriod(7) ); } } ``` -------------------------------- ### Get Device ID for User Identification Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Retrieve the SDK-generated anonymous device ID. This ID can be used to identify unique devices and may involve IO operations. It can be mapped to a user ID in your own system. ```java String deviceId = GrowingAutotracker.get().getDeviceId(); if (deviceId != null) { Log.d("GIO", "当前设备 ID: " + deviceId); // 可用于与自有系统进行设备关联 uploadDeviceMapping(deviceId, getCurrentUserId()); } ``` -------------------------------- ### SDK Initialization Configuration Options Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Details on the parameters available for configuring the GrowingIO SDK during initialization. ```APIDOC ## SDK Initialization Configuration Options | API | Parameter Type | Required | Default Value | Description | | :------------------------- | :------ | :----: |:------ |:------| | `projectId` | `String` | Yes | `null` | Your Project ID from the official website | | `urlScheme` | `String` | Yes | `null` | Your App's URL Scheme from the official website | | `setDataSourceId` | `String` | Yes | `null` | Your App's DataSource ID from the official website | | `setDataCollectionServerHost`| `String` | Yes | `null` | The backend Host of your deployed service | | `setChannel` | `String` | No | `null` | The distribution channel of the APP | | `setDebugEnabled` | `boolean` | No | `false` | Debug mode, prints SDK logs and throws errors. Ensure this is turned off in production environments. | | `setCellularDataLimit` | `int` | No | `10` | Daily data sending limit, in MB | | `setDataUploadInterval` | `int` | No | `15` | Data sending interval, in seconds | | `setSessionInterval` | `int` | No | `30` | Maximum session duration, in seconds | | `setDataCollectionEnabled` | `boolean` | No | `true` | Whether to collect data | | `setOaidEnabled` | `boolean` | No | `false` | Whether to collect Android OAID. If set to collect, data collection may be delayed due to OAID acquisition time. | | `setUploadExceptionEnabled` | `boolean` | No | `true` | Collects SDK internal exceptions and reports them to the server. ``` -------------------------------- ### 配置 Module 级 build.gradle Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 在 module 级别的 build.gradle 文件中应用 GrowingIO 插件,并添加 autotracker-cdp 和可选的 upgrade 依赖。如果项目非 AndroidX,需添加 appcompat 依赖。 ```groovy apply plugin: 'com.android.application' //添加 GrowingIO 插件 apply plugin: 'com.growingio.android.autotracker' ... dependencies { ... //GrowingIO 无埋点 SDK implementation 'com.growingio.android:autotracker-cdp:3.2.1-06292-SNAPSHOT' //如果不是AndroidX项目,请添加下面依赖 compileOnly 'androidx.appcompat:appcompat:1.2.0' //如果你之前集成的是3.0.0版本之前的SDK,请还需要集成upgrade,方便最小程度的迁移 implementation 'com.growingio.android.sdk.upgrade:autotracker-upgrade-2to3-cdp:1.0.0' } ``` -------------------------------- ### trackTimerStart / trackTimerEnd Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Used to measure the duration of specific user behaviors, such as video viewing time or game level completion time. It supports starting, pausing, resuming, and ending timers, with options to attach custom attributes. ```APIDOC ## trackTimerStart / trackTimerEnd — 计时事件 统计某段行为的持续时长,例如视频观看时长、游戏关卡耗时等。 ```java // 开始计时(返回 timerId) String timerId = GrowingAutotracker.get().trackTimerStart("video_watch"); // 暂停计时(如切换 APP 到后台) GrowingAutotracker.get().trackTimerPause(timerId); // 恢复计时 GrowingAutotracker.get().trackTimerResume(timerId); // 结束计时并发送事件(自动携带 duration 字段,单位毫秒) GrowingAutotracker.get().trackTimerEnd(timerId); // 结束计时并附加额外属性 Map attrs = new HashMap<>(); attrs.put("video_id", "V_2024001"); attrs.put("finish_rate", "85"); GrowingAutotracker.get().trackTimerEnd(timerId, attrs); // 移除指定计时器(不发送事件) GrowingAutotracker.get().removeTimer(timerId); // 清除所有计时器 GrowingAutotracker.get().clearTrackTimer(); ``` ``` -------------------------------- ### SDK Initialization Configuration Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Configuration options for initializing the GrowingIO SDK, including project ID, server host, and various data collection settings. ```APIDOC ## SDK Initialization Configuration ### Parameters - **projectId** (String) - Required - Your project ID from the GrowingIO website. - **urlScheme** (String) - Required - The URL scheme for your app from the GrowingIO website. - **setDataSourceId** (String) - Required - The DataSourceId for your app from the GrowingIO website. - **setDataCollectionServerHost** (String) - Required - The backend host of the service you deployed. - **setChannel** (String) - Optional - The distribution channel of the app. - **setDebugEnabled** (boolean) - Optional - Debug mode, prints SDK logs and throws errors. Ensure this is off in production. - **setCellularDataLimit** (int) - Optional - Daily data traffic limit in MB. Defaults to 10. - **setDataUploadInterval** (int) - Optional - Data upload interval in seconds. Defaults to 15. - **setSessionInterval** (int) - Optional - Maximum session duration in seconds. Defaults to 30. - **setDataCollectionEnabled** (boolean) - Optional - Whether to collect data. Defaults to true. - **setOaidEnabled** (boolean) - Optional - Whether to collect Android OAID. If enabled, event collection may be delayed due to OAID acquisition time. Defaults to false. - **setUploadExceptionEnabled** (boolean) - Optional - Whether to report SDK internal exceptions to the server. Defaults to true. - **setImpressionScale** (float) - Optional - Scale factor for element impression events, range [0-1]. Defaults to 0. - **setExcludeEvent** (int) - Optional - Mask value for event types to be filtered. Defaults to 0. - **setIgnoreField** (int) - Optional - Mask value for event attributes to be ignored. Defaults to 0. ``` -------------------------------- ### Get Device ID - Java Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Retrieves the device ID, also known as the anonymous user ID, generated by the SDK. This may return null if the SDK is not initialized or data collection is disabled. Be aware of potential IO operations. ```java GrowingTracker.get().getDeviceId(); ``` -------------------------------- ### Initialize GrowingAutotracker with Configuration Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Initialize the GrowingAutotracker SDK in your Application's onCreate() method using CdpAutotrackConfiguration. Essential parameters include projectId, urlScheme, dataSourceId, and dataCollectionServerHost. Various optional parameters allow for fine-tuning data collection behavior. ```java // MyApplication.java public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); GrowingAutotracker.startWithConfiguration(this, new CdpAutotrackConfiguration("your_project_id", "your_url_scheme") // 必填:数据采集服务地址 .setDataCollectionServerHost("https://your-server.com") // 必填:数据源 ID .setDataSourceId("your_data_source_id") // 可选:渠道标识 .setChannel("华为应用市场") // 可选:调试模式(上线前务必设置为 false) .setDebugEnabled(BuildConfig.DEBUG) // 可选:移动网络每日流量上限,默认 20MB .setCellularDataLimit(20) // 可选:数据上报间隔,默认 15 秒 .setDataUploadInterval(15) // 可选:会话超时时长,默认 30 秒 .setSessionInterval(30) // 可选:曝光事件触发比例阈值 [0-1],默认 0 .setImpressionScale(0.5f) // 可选:过滤特定事件类型(VIEW_CLICK + VIEW_CHANGE + FORM_SUBMIT) .setExcludeEvent(EventExcludeFilter.of(EventExcludeFilter.EVENT_MASK_TRIGGER)) // 可选:忽略特定设备字段上报 .setIgnoreField(FieldIgnoreFilter.of(FieldIgnoreFilter.NETWORK_STATE)) // 可选:启用 ID-Mapping(多 ID 关联) .setIdMappingEnabled(true) ); } } ``` -------------------------------- ### 添加 Gradle 依赖 Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 在 project 级别的 build.gradle 文件中添加 autotracker-gradle-plugin 依赖和必要的仓库。如果使用SNAPSHOT 版本,需要添加 Sonatype snapshots 仓库。 ```groovy buildscript { repositories { jcenter() google() mavenCentral() //如果你的版本为 xxx-SNAPSHOT 版本,则需要加入该仓库。 maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" } } dependencies { classpath 'com.android.tools.build:gradle:x.x.x' //GrowingIO 无埋点 SDK plugin classpath 'com.growingio.android:autotracker-gradle-plugin:3.2.1-06292-SNAPSHOT' } } allprojects { repositories { jcenter() mavenCentral() //如果你的版本为 xxx-SNAPSHOT 版本,则需要加入该仓库。 maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" } } } ``` -------------------------------- ### Initialize GrowingIO SDK in Application Class Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Initialize the GrowingTracker with your project's configuration in the onCreate method of your custom Application class. ```java public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); GrowingTracker.startWithConfiguration(this, new CdpTrackConfiguration("exampleProjectId", "exampleUrlScheme") .setDataCollectionServerHost("http://myhost.com/") .setDataSourceId("exampleSourceId") .setChannel("XXX应用商店") .setDebugEnabled(BuildConfig.DEBUG) ); } } ``` -------------------------------- ### Initialize GrowingIO SDK with Encryption Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 When initializing the GrowingIO SDK, register the `EncoderLibraryGioModule` to enable data encryption. Ensure you have added the encryption module dependency. ```java //初始化无埋点SDK GrowingAutotracker.startWithConfiguration(this, new CdpAutotrackConfiguration("exampleProjectId", "exampleUrlScheme") .setDataCollectionServerHost("http://myhost.com/") .setDataSourceId("exampleSourceId") .setChannel("XXX应用商店") .setDebugEnabled(BuildConfig.DEBUG) ); GrowingAutotracker.get().registerComponent(new EncoderLibraryGioModule()); ``` -------------------------------- ### Dynamically Register Components at Runtime Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Register components dynamically at runtime after SDK initialization. This includes registering a standalone module like an encoder or registering a module with its specific configuration, such as an ABTest module. ```java // 方式二:运行时动态注册(初始化后调用) // 注册加密模块 GrowingAutotracker.get().registerComponent(new EncoderLibraryGioModule()); // 注册带配置的模块 GrowingAutotracker.get().registerComponent( new ABTestLibraryGioModule(), new ABTestConfig().setAbTestServerHost("https://ab.your-server.com") ); ``` -------------------------------- ### Preload Components Before Initialization Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Preload components before the SDK is initialized, which is useful for modules like event encryption that need to be registered early. This ensures these components are available before any data collection begins. ```java // 方式三:预加载模块(初始化前,适用于事件加密等需要提前注册的模块) GrowingAutotracker.startWithConfiguration(this, new CdpAutotrackConfiguration("project_id", "url_scheme") .setDataCollectionServerHost("https://your-server.com") .setDataSourceId("data_source_id") .addPreloadComponent(new EncoderLibraryGioModule()) // 优先于事件发送注册 ); ``` -------------------------------- ### Configure AndroidManifest.xml with URL Scheme Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Add necessary permissions and configure the URL scheme for your application's LAUNCHER Activity in the AndroidManifest.xml file. Ensure the data tag is correctly set up. ```xml ``` -------------------------------- ### 配置 AndroidManifest.xml Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 在 AndroidManifest.xml 中添加必要的权限,并在 LAUNCHER Activity 下配置 URL Scheme 的 intent-filter,以便圈选等功能唤醒应用。 ```xml ``` -------------------------------- ### MultiDex 配置 Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 如果使用 MultiDex 并且支持 Android 5.0 (API 21) 以下版本,需要在 app 的 build.gradle 中配置 multiDexKeepFile,并将 SDK 的 ContentProvider 添加到 keep 文件中。 ```groovy android { buildTypes { release { multiDexKeepFile file('multidex-config.txt') ... } } } ``` ```text com/growingio/android/sdk/track/middleware/EventsContentProvider.class com/growingio/android/sdk/track/middleware/EventsInfoTable.class com/growingio/android/sdk/track/middleware/EventsSQLiteOpenHelper.class ``` -------------------------------- ### Add Maven Repository to Project Gradle Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Configure your project-level build.gradle file to include the necessary Maven repositories, including a snapshot repository if needed. ```groovy repositories { mavenCentral() //如果你的版本为 xxx-SNAPSHOT 版本,则需要加入该仓库。 maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } ``` -------------------------------- ### Add Autotracker Gradle Plugin and SDK Dependencies Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Configure your project-level and module-level build.gradle files to include the Autotracker Gradle plugin for bytecode injection and the necessary SDK dependencies. Ensure to use the correct versions for the plugin and SDK. ```groovy // project/build.gradle buildscript { repositories { mavenCentral() google() } dependencies { classpath 'com.android.tools.build:gradle:8.x.x' // 无埋点 Gradle 插件(字节码注入,实现无侵入采集) classpath 'com.growingio.android:autotracker-gradle-plugin:4.5.2' } } // app/build.gradle apply plugin: 'com.android.application' apply plugin: 'com.growingio.android.autotracker' // 启用无埋点插件 dependencies { // 无埋点 SDK(CDP 版本) implementation 'com.growingio.android:autotracker-cdp:4.5.3' // 注解处理器(必须添加,用于生成模块注册代码) annotationProcessor 'com.growingio.android:compiler:4.5.3' // 可选:网络模块(二选一) implementation 'com.growingio.android:okhttp3:4.5.3' // implementation 'com.growingio.android:urlconnection:4.5.3' // 可选:数据库存储模块 implementation 'com.growingio.android:database:4.5.3' } // 仅埋点 SDK 依赖(不需要 Gradle 插件) // implementation 'com.growingio.android:tracker-cdp:4.5.3' ``` -------------------------------- ### Register Ads Module with Custom DeepLink Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Register the Ads module to collect activation events and handle DeepLinks. Customize the DeepLink service host and enable clipboard reading for delayed DeepLinks. The callback processes DeepLink parameters to navigate to the appropriate landing page. ```java GrowingAutotracker.get().registerComponent( new AdsLibraryGioModule(), new AdsConfig() // 自定义 DeepLink 服务地址(默认 https://link.growingio.com) .setDeepLinkHost("https://link.your-server.com") // 可选:开启剪贴板读取(用于延迟 DeepLink) .setReadClipBoardEnable(true) // DeepLink 唤起回调 .setDeepLinkCallback((params, error, appAwakePassedTime) -> { if (error == 0 && params != null) { String campaignId = params.get("campaign_id"); String channel = params.get("channel"); // 根据参数跳转对应落地页 navigateToLandingPage(campaignId, channel); } }) ); ``` -------------------------------- ### Configure AndroidManifest.xml for GrowingIO Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Add necessary permissions and define the URL scheme in your AndroidManifest.xml file. The URL scheme is crucial for features like visual selection and mobile debugging. ```xml ``` -------------------------------- ### Add Dependency Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Instructions for adding the GrowingIO tracker SDK dependency to your Android project's build.gradle files. ```APIDOC ## Add Dependency ### Project-level build.gradle Add the following repositories to your project-level `build.gradle` file: ```groovy repositories { mavenCentral() // If you are using a SNAPSHOT version, you need to add this repository. maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } ``` ### Module-level build.gradle Add the `tracker` dependency to your module-level `build.gradle` file: ```groovy ... dependencies { ... // GrowingIO No-Code SDK implementation 'com.growingio.android:tracker-cdp:x.x.x' } ``` ``` -------------------------------- ### Track Custom Events with GrowingIO SDK Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Use `trackCustomEvent` to log custom events. You can optionally pass a map of attributes with the event. ```java GrowingAutotracker.get().trackCustomEvent("registerSuccess"); ``` ```java Map map = new HashMap<>(); map.put("name", "June"); map.put("age", "12"); GrowingAutotracker.get().trackCustomEvent("registerSuccess", map); ``` -------------------------------- ### bridgeWebView Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Injects the GrowingIO JS Bridge into WebViews (including native, X5, and UC kernels) to enable unified data collection for H5 pages and native events. ```APIDOC ## bridgeWebView — Hybrid WebView 桥接 为 WebView(原生、X5 内核、UC 内核)注入 GrowingIO JS Bridge,实现 H5 页面与原生事件统一采集。 ```java // 需在 UI 线程调用,传入 WebView 实例 WebView webView = findViewById(R.id.web_view); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); // 注入 GIO JS Bridge GrowingAutotracker.get().bridgeWebView(view); } }); // X5 内核 WebView(腾讯浏览服务) com.tencent.smtt.sdk.WebView x5WebView = findViewById(R.id.x5_web_view); GrowingAutotracker.get().bridgeWebView(x5WebView); ``` ``` -------------------------------- ### Add GrowingIO Tracker Dependency Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Include the GrowingIO tracker SDK dependency in your module-level build.gradle file. ```groovy dependencies { ... //GrowingIO 无埋点 SDK implementation 'com.growingio.android:tracker-cdp:x.x.x' } ``` -------------------------------- ### Track Custom Event with Attributes - Java Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Sends a custom event with associated attributes. Requires prior configuration of the event and its variables in the GrowingIO UI. Attributes are optional. ```java GrowingTracker.get().trackCustomEvent("registerSuccess"); ``` ```java Map map = new HashMap<>(); map.put("name", "June"); map.put("age", "12"); GrowingTracker.get().trackCustomEvent("registerSuccess", map); ``` -------------------------------- ### Bridge WebView for Hybrid Event Collection Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Inject the GrowingIO JS Bridge into WebViews (native, X5, UC kernels) to unify data collection between H5 pages and native events. Must be called on the UI thread. ```java // 需在 UI 线程调用,传入 WebView 实例 WebView webView = findViewById(R.id.web_view); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); // 注入 GIO JS Bridge GrowingAutotracker.get().bridgeWebView(view); } }); // X5 内核 WebView(腾讯浏览服务) com.tencent.smtt.sdk.WebView x5WebView = findViewById(R.id.x5_web_view); GrowingAutotracker.get().bridgeWebView(x5WebView); ``` -------------------------------- ### Register Custom App Module using Annotation Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Define a custom application module using the @GIOAppModule annotation. This approach allows for automatic registration of extended functionalities during compile time, recommended for custom ModelLoader implementations or overriding default behaviors. ```java // 方式一:使用注解(推荐) // MyAppGioModule.java @GIOAppModule public class MyAppGioModule extends AppGioModule { @Override public void registerComponents(TrackerContext context) { // 在此注册自定义 ModelLoader 或覆盖默认实现 } } // 编译时注解处理器自动生成 GeneratedGioModuleImpl,SDK 初始化时自动加载 ``` -------------------------------- ### Conditionally Apply Autotracker Plugin Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 To improve build times in debug mode, you can configure the plugin to apply only when tasks do not contain 'Debug'. This also enables the `development` mode. ```groovy if (gradle.startParameter.taskNames.any {!it.contains("Debug")} ) { apply plugin: 'com.growingio.android.autotracker' growingAutotracker { development true } } ``` -------------------------------- ### Track Timer Start/End for Duration Events Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Measure the duration of specific user actions, such as video watch time or game level completion time. The duration is automatically sent in milliseconds. ```java // 开始计时(返回 timerId) String timerId = GrowingAutotracker.get().trackTimerStart("video_watch"); // 暂停计时(如切换 APP 到后台) GrowingAutotracker.get().trackTimerPause(timerId); // 恢复计时 GrowingAutotracker.get().trackTimerResume(timerId); // 结束计时并发送事件(自动携带 duration 字段,单位毫秒) GrowingAutotracker.get().trackTimerEnd(timerId); // 结束计时并附加额外属性 Map attrs = new HashMap<>(); attrs.put("video_id", "V_2024001"); attrs.put("finish_rate", "85"); GrowingAutotracker.get().trackTimerEnd(timerId, attrs); // 移除指定计时器(不发送事件) GrowingAutotracker.get().removeTimer(timerId); // 清除所有计时器 GrowingAutotracker.get().clearTrackTimer(); ``` -------------------------------- ### Configure Event Filtering for GrowingIO SDK Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Configure which events should be filtered out from data collection. Use `EventExcludeFilter.of()` to specify single events or combinations, including a predefined mask for common trigger events. ```java setExcludeEvent(EventExcludeFilter.of(EventExcludeFilter.VIEW_CLICK)) ``` ```java setExcludeEvent(EventExcludeFilter.of(EventExcludeFilter.VIEW_CLICK, EventExcludeFilter.VIEW_CHANGE, EventExcludeFilter.FORM_SUBMIT)) ``` ```java setExcludeEvent(EventExcludeFilter.of(EventExcludeFilter.EVENT_MASK_TRIGGER) ``` -------------------------------- ### trackCustomEvent Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Sends a custom event with associated attributes. Requires pre-configuration of events in the GrowingIO UI. ```APIDOC ## trackCustomEvent ### Description Sends a custom event. Requires events and their variables to be configured in the event management UI before sending. ### Parameters #### Path Parameters - **eventName** (String) - Required - The event name, an identifier for the event. - **attributes** (Map) - Optional - Dimension information accompanying the event. - **itemKey** (String) - Optional - The model key of the item associated with the event. - **itemId** (String) - Optional - The model ID of the item associated with the event. ### Request Example ```java GrowingTracker.get().trackCustomEvent("registerSuccess"); Map map = new HashMap<>(); map.put("name", "June"); map.put("age", "12"); GrowingTracker.get().trackCustomEvent("registerSuccess", map); ``` ``` -------------------------------- ### Set Page Alias with GrowingIO SDK Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Assign an alias to a page using `setPageAlias`. Aliases should be alphanumeric and can include underscores. It's recommended to use distinct names for equivalent pages on iOS and Android for easier data analysis. ```java GrowingAutotracker.get().setPageAlias(mActivity, "home"); ``` -------------------------------- ### Add URL Scheme Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Configure your AndroidManifest.xml to include the URL Scheme for your application, which is essential for features like Mobile Debug. ```APIDOC ## Add URL Scheme URL Scheme is the unique identifier for your application generated on the GrowingIO platform. Add the URL Scheme to your project to enable features like Mobile Debug. Add the application's URL Scheme and permissions to your `AndroidManifest.xml` within the LAUNCHER Activity. ```xml ``` ``` -------------------------------- ### Track Custom Events Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Send custom events with optional attributes and item associations. Ensure events and their variables are pre-defined on the GrowingIO platform. ```java // 无属性自定义事件 GrowingAutotracker.get().trackCustomEvent("user_register"); // 携带属性的自定义事件 Map attrs = new HashMap<>(); attrs.put("register_channel", "wechat"); attrs.put("city", "beijing"); GrowingAutotracker.get().trackCustomEvent("user_register", attrs); // 关联物品模型(商品、内容等) Map productAttrs = new HashMap<>(); productAttrs.put("discount", "0.8"); GrowingAutotracker.get().trackCustomEvent("product_view", productAttrs); // 埋点 SDK 调用方式相同 GrowingTracker.get().trackCustomEvent("button_click"); ``` -------------------------------- ### trackCustomEvent Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Sends a custom event with optional attributes and associated item models. Custom events must be pre-defined in the GrowingIO platform. ```APIDOC ## 七、trackCustomEvent — 自定义埋点事件 发送自定义事件,需在 GrowingIO 平台预先定义事件及事件变量。支持附加属性 Map 和物品模型关联。 ```java // 无属性自定义事件 GrowingAutotracker.get().trackCustomEvent("user_register"); // 携带属性的自定义事件 Map attrs = new HashMap<>(); attrs.put("register_channel", "wechat"); attrs.put("city", "beijing"); GrowingAutotracker.get().trackCustomEvent("user_register", attrs); // 关联物品模型(商品、内容等) Map productAttrs = new HashMap<>(); productAttrs.put("discount", "0.8"); GrowingAutotracker.get().trackCustomEvent("product_view", productAttrs); // 埋点 SDK 调用方式相同 GrowingTracker.get().trackCustomEvent("button_click"); ``` ``` -------------------------------- ### Track View Impression Events with GrowingIO SDK Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Use `trackViewImpression` to trigger an impression event when a specified view appears on the screen. You can provide an event name and optional attributes. ```java GrowingAutotracker.get().trackViewImpression(view, "buttonShowed"); ``` ```java Map map = new HashMap<>(); map.put("color", "red"); map.put("name", "home"); GrowingAutotracker.get().trackViewImpression(view, "buttonShowed", map); ``` -------------------------------- ### Set User Location Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Set the user's current geographical location using WGS-84 coordinates. Provide latitude and longitude values. ```java GrowingAutotracker.get().setLocation(39.9, 116.3); ``` -------------------------------- ### Track View Impression Events Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Trigger impression events when a specified View becomes visible on screen. Useful for tracking ad banners, product cards, etc. Supports tracking with or without attributes and stopping the tracking. ```java // 监听广告 Banner 曝光(无属性) GrowingAutotracker.get().trackViewImpression(bannerView, "ad_banner_show"); // 监听商品卡片曝光(携带属性) Map attrs = new HashMap<>(); attrs.put("product_id", "P_10086"); attrs.put("position", "3"); attrs.put("source", "homepage_recommend"); GrowingAutotracker.get().trackViewImpression(productCard, "product_card_show", attrs); // 停止监听曝光(如 RecyclerView item 复用时) GrowingAutotracker.get().stopTrackViewImpression(productCard); ``` -------------------------------- ### Set Login User Attributes with GrowingIO SDK Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 Use `setLoginUserAttributes` to define user attributes for logged-in users. This is useful for user-specific analysis. ```java Map map = new HashMap<>(); map.put("gender", "male"); map.put("age", "12"); GrowingAutotracker.get().setLoginUserAttributes(map); ``` -------------------------------- ### Register APM Module for Performance Monitoring Source: https://context7.com/growingio/growingio-sdk-android-autotracker/llms.txt Register the APM module to collect performance data, including Activity/Fragment lifecycle durations and uncaught exceptions. Configure which lifecycle events and exception logging to enable. ```java GrowingAutotracker.get().registerComponent( new ApmLibraryGioModule(), new ApmConfig() // 采集 Activity 生命周期耗时(默认开启) .setActivityLifecycleTracing(true) // 采集 AndroidX Fragment 生命周期耗时(默认开启) .setFragmentXLifecycleTracing(true) // 采集 Support Fragment 生命周期耗时(默认关闭) .setFragmentSupportLifecycleTracing(false) // 采集未捕获异常(默认开启) .setUncaughtException(true) // 是否在 log 中打印未捕获异常(默认关闭) .setPrintUncaughtException(true) ); ``` -------------------------------- ### Add Encryption Module Dependency Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/无埋点-SDK集成 To encrypt data during transmission (requires CDP version 13.6.1 or later), add the `encoder` module dependency to your `build.gradle` file. ```groovy dependencies { ... // 在依赖无埋点的配置文件增加 加密模块依赖 implementation 'com.growingio.android:encoder:3.2.0-SNAPSHOT' } ``` -------------------------------- ### Set User Location - Java Source: https://github.com/growingio/growingio-sdk-android-autotracker/wiki/埋点-SDK集成 Sets the user's geographical location using latitude and longitude. Ensure the SDK is initialized before calling this method. ```java GrowingTracker.get().setLocation(39.9, 116.3); ```