From 83dea537af71e8efd27d8db57b68cdbdd41a79db Mon Sep 17 00:00:00 2001 From: weiqiangliu Date: Wed, 12 Apr 2023 15:51:07 +0800 Subject: [PATCH] Release 2.4.0 --- CHANGELOG.md | 5 ++++ README.md | 4 +-- .../FlutterVisual.java | 20 ++++++++++----- .../SensorsAnalyticsFlutterPlugin.java | 24 +++++++++++++++++- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Podfile | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 12 +++++---- .../contents.xcworkspacedata | 2 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 4 +++ example/lib/main.dart | 12 +++++++++ ios/Classes/SensorsAnalyticsFlutterPlugin.m | 22 +++++++++++++++- ios/sensors_analytics_flutter_plugin.podspec | 8 +++--- lib/sensors_analytics_flutter_plugin.dart | 25 ++++++++++++++++++- pubspec.yaml | 2 +- 15 files changed, 121 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b3582c..0e931b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.4.0 + +* 异常处理优化 +* 支持页面离开事件采集 + ## 2.3.1 * Release 模式下,延迟初始化后立即触发事件失败的问题 diff --git a/README.md b/README.md index e348c0e..5d0dab7 100755 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ ```yml dependencies: # 添加神策 flutter plugin - sensors_analytics_flutter_plugin: ^2.3.1 + sensors_analytics_flutter_plugin: ^2.4.0 ``` 执行 flutter packages get 命令安装插件 @@ -61,7 +61,7 @@ dependencies: ## License -Copyright 2015-2022 Sensors Data Inc. +Copyright 2015-2023 Sensors Data Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/FlutterVisual.java b/android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/FlutterVisual.java index 2d6fd15..01edce9 100644 --- a/android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/FlutterVisual.java +++ b/android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/FlutterVisual.java @@ -55,17 +55,25 @@ public void onReceive(Context context, Intent intent) { public synchronized void registerBroadcast(Context context) { SALog.i(TAG, "registerBroadcast:" + isRegister); if (!isRegister) { - SALog.i(TAG, "registerBroadcast"); - IntentFilter filter = new IntentFilter(); - filter.addAction(FLUTTER_ACTION); - context.registerReceiver(mDynamicReceiver, filter); - isRegister = true; + try { + SALog.i(TAG, "registerBroadcast"); + IntentFilter filter = new IntentFilter(); + filter.addAction(FLUTTER_ACTION); + context.registerReceiver(mDynamicReceiver, filter); + isRegister = true; + } catch (Exception e) { + SALog.printStackTrace(e); + } } } public synchronized void unRegisterBroadcast(Context context) { SALog.i(TAG, "unRegisterBroadcast"); - context.unregisterReceiver(mDynamicReceiver); + try { + context.unregisterReceiver(mDynamicReceiver); + } catch (Exception e) { + SALog.printStackTrace(e); + } isRegister = false; } } diff --git a/android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/SensorsAnalyticsFlutterPlugin.java b/android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/SensorsAnalyticsFlutterPlugin.java index 2ac2b60..30508c7 100644 --- a/android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/SensorsAnalyticsFlutterPlugin.java +++ b/android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/SensorsAnalyticsFlutterPlugin.java @@ -204,6 +204,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { case "loginWithKey": loginWithKey(list, result); break; + case "isAutoTrackEventTypeIgnored": + isAutoTrackEventTypeIgnored(list, result); + break; default: result.notImplemented(); break; @@ -356,7 +359,16 @@ private void trackInstallation(List list) { * track 事件 */ private void track(List list) { - SensorsDataAPI.sharedInstance().track(assertEventName((String) list.get(0)), assertProperties((Map) list.get(1))); + try { + String eventName = assertEventName((String) list.get(0)); + JSONObject properties = assertProperties((Map) list.get(1)); + if (properties != null && "$AppPageLeave".equals(eventName) && !properties.has("$referrer")) { + properties.put("$referrer", SensorsDataAPI.sharedInstance().getLastScreenUrl()); + } + SensorsDataAPI.sharedInstance().track(eventName, properties); + } catch (Exception e) { + SALog.printStackTrace(e); + } } /** @@ -666,6 +678,16 @@ private void loginWithKey(List list, Result result) { } } + private void isAutoTrackEventTypeIgnored(List list, Result result) { + try { + int type = (int) list.get(0); + boolean isIgnored = SensorsDataAPI.sharedInstance().isAutoTrackEventTypeIgnored(type); + result.success(isIgnored); + } catch (Exception e) { + SALog.printStackTrace(e); + } + } + private JSONObject assertProperties(Map map) { if (map != null) { return new JSONObject(map); diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 6b4c0f7..4f8d4d2 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 11.0 diff --git a/example/ios/Podfile b/example/ios/Podfile index 3be773c..3e0f0dc 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project - platform :ios, '9.0' + platform :ios, '11.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 0076f48..822759c 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -166,7 +166,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -209,6 +209,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -223,6 +224,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -350,7 +352,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -432,7 +434,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -481,7 +483,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a1..919434a 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140c..3db53b6 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + diff --git a/example/lib/main.dart b/example/lib/main.dart index 330d3a0..3139322 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -409,6 +409,18 @@ class _MyAppState extends State { print("loginwithkey==="); }, ), + ListTile( + title: Text('isAutoTrackEventTypeIgnored'), + onTap: () async { + bool click = await SensorsAnalyticsFlutterPlugin.isAutoTrackEventTypeIgnored(SAAutoTrackType.APP_CLICK); + bool end = await SensorsAnalyticsFlutterPlugin.isAutoTrackEventTypeIgnored(SAAutoTrackType.APP_END); + bool start = await SensorsAnalyticsFlutterPlugin.isAutoTrackEventTypeIgnored(SAAutoTrackType.APP_START); + bool screen = await SensorsAnalyticsFlutterPlugin.isAutoTrackEventTypeIgnored(SAAutoTrackType.APP_VIEW_SCREEN); + + //SensorsAnalyticsFlutterPlugin.loginWithKey("sss3", "vvv3", {"p1111": "vvvv1"}); + print("isAutoTrackEventTypeIgnored====$click====$end====$start====$screen"); + }, + ), ], ), ), diff --git a/ios/Classes/SensorsAnalyticsFlutterPlugin.m b/ios/Classes/SensorsAnalyticsFlutterPlugin.m index 8400981..f746926 100644 --- a/ios/Classes/SensorsAnalyticsFlutterPlugin.m +++ b/ios/Classes/SensorsAnalyticsFlutterPlugin.m @@ -51,6 +51,7 @@ static NSString* const SensorsAnalyticsFlutterPluginMethodProfilePushKey = @"profilePushId"; static NSString* const SensorsAnalyticsFlutterPluginMethodProfileUnsetPushKey = @"profileUnsetPushId"; static NSString* const SensorsAnalyticsFlutterPluginMethodInit = @"init"; +static NSString* const SensorsAnalyticsFlutterPluginMethodIsAutoTrackEventTypeIgnored = @"isAutoTrackEventTypeIgnored"; /// 回调返回当前为可视化全埋点连接状态 static NSString* const SensorsAnalyticsGetVisualizedConnectionStatus = @"getVisualizedConnectionStatus"; @@ -64,6 +65,9 @@ /// 可视化全埋点状态改变,包括连接状态和自定义属性配置 static NSNotificationName const kSAFlutterPluginVisualizedStatusChangedNotification = @"SensorsAnalyticsVisualizedStatusChangedNotification"; +// referrer key +static NSString* const SensorsAnalyticsPropertyReferrer = @"$referrer"; + @interface SensorsAnalyticsFlutterPlugin() @property (nonatomic, weak) NSObject *registrar; @@ -362,6 +366,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { // 发送 Flutter 页面元素信息 [self invokeSABridgeWithMethod:method arguments:arguments]; result(nil); + } else if ([method isEqualToString:SensorsAnalyticsFlutterPluginMethodIsAutoTrackEventTypeIgnored]){ + // 判断某个 AutoTrack 事件类型是否被忽略 + NSNumber *autoTrackEventType = arguments[0]; + argumentSetNSNullToNil(&autoTrackEventType); + BOOL ignored = [self isAutoTrackEventTypeIgnored:autoTrackEventType.integerValue]; + result([NSNumber numberWithBool:ignored]); } else { result(FlutterMethodNotImplemented); } @@ -416,7 +426,13 @@ - (id)invokeSABridgeWithMethod:(NSString *)methodString arguments:(NSArray *)arg } -(void)track:(NSString *)event properties:(nullable NSDictionary *)properties{ - [SensorsAnalyticsSDK.sharedInstance track:event withProperties:properties]; + NSMutableDictionary *tempProperties = [NSMutableDictionary dictionary]; + NSString *referrer = [[SensorsAnalyticsSDK sharedInstance] getLastScreenUrl]; + tempProperties[SensorsAnalyticsPropertyReferrer] = referrer; + if (properties) { + [tempProperties addEntriesFromDictionary:properties]; + } + [SensorsAnalyticsSDK.sharedInstance track:event withProperties:[tempProperties copy]]; } -(NSString *)trackTimerStart:(NSString *)event{ @@ -685,6 +701,10 @@ - (void)startWithConfig:(NSDictionary *)config { } } +- (BOOL)isAutoTrackEventTypeIgnored:(SensorsAnalyticsAutoTrackEventType)eventType { + return [[SensorsAnalyticsSDK sharedInstance] isAutoTrackEventTypeIgnored:eventType]; +} + static inline void argumentSetNSNullToNil(id *arg){ *arg = (*arg == NSNull.null) ? nil:*arg; } diff --git a/ios/sensors_analytics_flutter_plugin.podspec b/ios/sensors_analytics_flutter_plugin.podspec index be5671f..d808ba1 100644 --- a/ios/sensors_analytics_flutter_plugin.podspec +++ b/ios/sensors_analytics_flutter_plugin.podspec @@ -3,7 +3,7 @@ # Pod::Spec.new do |s| s.name = 'sensors_analytics_flutter_plugin' - s.version = '2.3.1' + s.version = '2.4.0' s.summary = 'A new flutter plugin project.' s.description = <<-DESC A new flutter plugin project. @@ -15,8 +15,8 @@ A new flutter plugin project. s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.platform = :ios, '8.0' - s.dependency 'SensorsAnalyticsSDK', ">= 4.5.0" + s.platform = :ios, '9.0' + s.dependency 'SensorsAnalyticsSDK', ">= 4.5.6" # Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported. s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'VALID_ARCHS[sdk=iphonesimulator*]' => 'x86_64' } -end \ No newline at end of file +end diff --git a/lib/sensors_analytics_flutter_plugin.dart b/lib/sensors_analytics_flutter_plugin.dart index a879ced..e41b410 100644 --- a/lib/sensors_analytics_flutter_plugin.dart +++ b/lib/sensors_analytics_flutter_plugin.dart @@ -37,7 +37,7 @@ class VisualizedConfig { // This is the official Flutter Plugin for Sensors Analytics. class SensorsAnalyticsFlutterPlugin { - static const String FLUTTER_PLUGIN_VERSION = "2.3.1"; + static const String FLUTTER_PLUGIN_VERSION = "2.4.0"; static bool hasAddedFlutterPluginVersion = false; static Future get getDistinctId async { @@ -683,6 +683,29 @@ class SensorsAnalyticsFlutterPlugin { return await _channel.invokeMethod("loginWithKey", [loginKey, loginValue, properties]); } + ///判断全埋点类型是否被忽略 + static Future isAutoTrackEventTypeIgnored(SAAutoTrackType type) async { + int result = 0; + switch (type) { + case SAAutoTrackType.NONE: + result = 0; + break; + case SAAutoTrackType.APP_START: + result = 1; + break; + case SAAutoTrackType.APP_END: + result = 1 << 1; + break; + case SAAutoTrackType.APP_CLICK: + result = 1 << 2; + break; + case SAAutoTrackType.APP_VIEW_SCREEN: + result = 1 << 3; + break; + } + return await _channel.invokeMethod("isAutoTrackEventTypeIgnored", [result]); + } + ///添加 Flutter 插件版本号 static void _setupLibPluginVersion(Map? properties) { if (!hasAddedFlutterPluginVersion) { diff --git a/pubspec.yaml b/pubspec.yaml index 3379559..4eecb16 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: sensors_analytics_flutter_plugin description: This is the official flutter plugin for Sensors Analytics,with this plugin you can easily collect your app data on Android and iOS. -version: 2.3.1 +version: 2.4.0 homepage: "https://github.com/sensorsdata/sensors_analytics_flutter_plugin" environment: