xy_umeng

English | 中文

  • Unofficial UMeng library. Supports UMeng Analytics (U-App) and Deeplink (U-Link), with more features to be added in the future.

  • Pay attention to privacy compliance and the timing of init calls to avoid app review rejections.

  • Scheme must be lowercase English only. Special characters will cause JS U-Link errors, and uppercase letters will cause Android wake-up to fail.

  • The iOS SDK collects the Advertising Identifier (IDFA) by default. In App Store Connect under the "Advertising Identifier (IDFA)" section, you need to check "Yes" and indicate whether your app contains ads. You also need to configure the NSUserTrackingUsageDescription permission description in the Info.plist file to explain to users why IDFA is used.

Requirements

Android

  • Android Gradle Plugin (AGP): >= 7.0.0
  • Gradle: >= 7.5
  • Kotlin: >= 1.8.0
  • If an error occurs:The AGP version of the main project 'android/build.gradle' needs to be configured:
buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:8.5.2'
    }
}

iOS

  • iOS Deployment Target: >= 13.0
  • Xcode: >= 14.0
  • CocoaPods: ios/Podfile setup:
platform :ios, '13.0'

U-App: Analytics Configuration

Android

  • If the developer calls methods like kill or exit to terminate the process, or if the user double-taps the back button to kill the process, make sure to call this method beforehand to save analytics data.
XYUmeng.instance.onKillProcess();

iOS

  • Configure the NSUserTrackingUsageDescription permission description in the Info.plist file to explain to users why IDFA is used.
<key>NSUserTrackingUsageDescription</key>
<string>IDFA is used to more accurately analyze and verify data. Whether it is used for advertising depends on your app's functionality.</string>

Import

import 'package:xy_umeng/xy_umeng.dart';

Initialization

// ... Requires user consent to the privacy policy before calling. 
// On subsequent launches, if consent has already been given, it can be called directly.
// Make sure to await initialization completion before calling other methods.
await XYUmeng.instance.init(androidAppKey: "", iosAppKey: "", channel: "", androidMessageSecret: "");
// Enable logging
await XYUmeng.instance.setLogEnabled(true);
// Enable automatic page tracking
await XYUmeng.instance.setAutoPageEnabled(true);

// ... 

// Account login
XYUmeng.instance.signIn('UserId');
// Account logout
XYUmeng.instance.signOff();
// Page Entry
XYUmeng.instance.onPageStart('Main');
// Page Leave
XYUmeng.instance.onPageEnd('Main');
// Statistical Events
XYUmeng.instance.onEvent('pay', attributes: {'type': 'book', 'name': "Swift Fundamentals"});

Exit App

Android

  • If the developer calls methods like kill or exit to terminate the process, or if the user double-taps the back button to kill the process, make sure to call this method beforehand to save analytics data.
XYUmeng.instance.onKillProcess();

Android Native Configuration

  • Configure in the UMeng console: Deeplink Configuration → Android Basic Parameters → Scheme (lowercase English only).

Locate android/app/src/main/AndroidManifest.xml in your project directory. Inside <application><activity>, find the existing <intent-filter> tag and add the following scheme entry below it. Replace the Scheme value with your own.

<!-- U-Link Configuration -->
<intent-filter>
    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:scheme="{Your-Unique-Scheme-From-UMeng-Console}" />
</intent-filter>

iOS Native Configuration

1. URL Scheme Configuration (Choose one; use this if you don't have a developer account)

  • Configure in the UMeng console: Deeplink Configuration → iOS Basic Parameters → Scheme (lowercase English only).

Locate ios/Runner/Info.plist in your project directory and add the following code. Replace the Scheme value with your own.

<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleTypeRole</key>
		<string>Editor</string>
		<key>CFBundleURLName</key>
		<string>UMLink</string>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>{Your-Unique-Scheme-From-UMeng-Console}</string>
		</array>
	</dict>
</array>
  • Configure in the UMeng console: Deeplink Configuration → iOS Basic Parameters → Universal Link.

Refer to the method provided by UMeng official 5. Configure Universal Link

  • Call the method below. On success, the addLinkListener.onInstall callback will be triggered, returning the parameters configured on the JS page.
// Add UMeng U-Link listener
XYUmeng.instance.addLinkListener(
  onInstall: (XYLinkInstallModel model) {
    Logger.d('onInstall getData ${model.getData}');
  },
  onWakeup: (XYLinkWakeupModel model) {
    Logger.d('onWakeup getData ${model.toString()}');
  },
  onError: (String errorMessage) {
    Logger.d('onError $errorMessage');
  },
);

// ...

// Get install params (Recommended to call on first app install)
XYUmeng.instance.getInstallParams(enablePasteboard:
true
);