Skip to content

Commit

Permalink
Release 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Apr 12, 2023
1 parent 43f8222 commit 83dea53
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.4.0

* 异常处理优化
* 支持页面离开事件采集

## 2.3.1

* Release 模式下,延迟初始化后立即触发事件失败的问题
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 命令安装插件
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>11.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
12 changes: 7 additions & 5 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -166,7 +166,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -209,6 +209,7 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -223,6 +224,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 4 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
12 changes: 12 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,18 @@ class _MyAppState extends State<MyApp> {
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");
},
),
],
),
),
Expand Down
22 changes: 21 additions & 1 deletion ios/Classes/SensorsAnalyticsFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -64,6 +65,9 @@
/// 可视化全埋点状态改变,包括连接状态和自定义属性配置
static NSNotificationName const kSAFlutterPluginVisualizedStatusChangedNotification = @"SensorsAnalyticsVisualizedStatusChangedNotification";

// referrer key
static NSString* const SensorsAnalyticsPropertyReferrer = @"$referrer";

@interface SensorsAnalyticsFlutterPlugin()
@property (nonatomic, weak) NSObject<FlutterPluginRegistrar> *registrar;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions ios/sensors_analytics_flutter_plugin.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
end
25 changes: 24 additions & 1 deletion lib/sensors_analytics_flutter_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String?> get getDistinctId async {
Expand Down Expand Up @@ -683,6 +683,29 @@ class SensorsAnalyticsFlutterPlugin {
return await _channel.invokeMethod("loginWithKey", [loginKey, loginValue, properties]);
}

///判断全埋点类型是否被忽略
static Future<bool> 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<String, dynamic>? properties) {
if (!hasAddedFlutterPluginVersion) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 83dea53

Please sign in to comment.