Skip to content

Commit 0ae7b65

Browse files
GvcZhang刘伟强
authored andcommitted
[feature]添加 page leave 逻辑
1 parent 03ae899 commit 0ae7b65

File tree

12 files changed

+97
-41
lines changed

12 files changed

+97
-41
lines changed

android/src/main/java/com/sensorsdata/analytics/sensorsanalyticsflutterplugin/SensorsAnalyticsFlutterPlugin.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
204204
case "loginWithKey":
205205
loginWithKey(list, result);
206206
break;
207+
case "isAutoTrackEventTypeIgnored":
208+
isAutoTrackEventTypeIgnored(list, result);
209+
break;
207210
default:
208211
result.notImplemented();
209212
break;
@@ -356,7 +359,16 @@ private void trackInstallation(List list) {
356359
* track 事件
357360
*/
358361
private void track(List list) {
359-
SensorsDataAPI.sharedInstance().track(assertEventName((String) list.get(0)), assertProperties((Map) list.get(1)));
362+
try {
363+
String eventName = assertEventName((String) list.get(0));
364+
JSONObject properties = assertProperties((Map) list.get(1));
365+
if (properties != null && "$AppPageLeave".equals(eventName) && !properties.has("$referrer")) {
366+
properties.put("$referrer", SensorsDataAPI.sharedInstance().getLastScreenUrl());
367+
}
368+
SensorsDataAPI.sharedInstance().track(eventName, properties);
369+
} catch (Exception e) {
370+
SALog.printStackTrace(e);
371+
}
360372
}
361373

362374
/**
@@ -666,6 +678,16 @@ private void loginWithKey(List list, Result result) {
666678
}
667679
}
668680

681+
private void isAutoTrackEventTypeIgnored(List list, Result result) {
682+
try {
683+
int type = (int) list.get(0);
684+
boolean isIgnored = SensorsDataAPI.sharedInstance().isAutoTrackEventTypeIgnored(type);
685+
result.success(isIgnored);
686+
} catch (Exception e) {
687+
SALog.printStackTrace(e);
688+
}
689+
}
690+
669691
private JSONObject assertProperties(Map map) {
670692
if (map != null) {
671693
return new JSONObject(map);

example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>8.0</string>
24+
<string>11.0</string>
2525
</dict>
2626
</plist>

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
platform :ios, '9.0'
2+
platform :ios, '11.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 51;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -166,7 +166,7 @@
166166
97C146E61CF9000F007C117D /* Project object */ = {
167167
isa = PBXProject;
168168
attributes = {
169-
LastUpgradeCheck = 1020;
169+
LastUpgradeCheck = 1300;
170170
ORGANIZATIONNAME = "";
171171
TargetAttributes = {
172172
97C146ED1CF9000F007C117D = {
@@ -209,6 +209,7 @@
209209
/* Begin PBXShellScriptBuildPhase section */
210210
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
211211
isa = PBXShellScriptBuildPhase;
212+
alwaysOutOfDate = 1;
212213
buildActionMask = 2147483647;
213214
files = (
214215
);
@@ -223,6 +224,7 @@
223224
};
224225
9740EEB61CF901F6004384FC /* Run Script */ = {
225226
isa = PBXShellScriptBuildPhase;
227+
alwaysOutOfDate = 1;
226228
buildActionMask = 2147483647;
227229
files = (
228230
);
@@ -350,7 +352,7 @@
350352
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
351353
GCC_WARN_UNUSED_FUNCTION = YES;
352354
GCC_WARN_UNUSED_VARIABLE = YES;
353-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
355+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
354356
MTL_ENABLE_DEBUG_INFO = NO;
355357
SDKROOT = iphoneos;
356358
SUPPORTED_PLATFORMS = iphoneos;
@@ -432,7 +434,7 @@
432434
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
433435
GCC_WARN_UNUSED_FUNCTION = YES;
434436
GCC_WARN_UNUSED_VARIABLE = YES;
435-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
437+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
436438
MTL_ENABLE_DEBUG_INFO = YES;
437439
ONLY_ACTIVE_ARCH = YES;
438440
SDKROOT = iphoneos;
@@ -481,7 +483,7 @@
481483
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
482484
GCC_WARN_UNUSED_FUNCTION = YES;
483485
GCC_WARN_UNUSED_VARIABLE = YES;
484-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
486+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
485487
MTL_ENABLE_DEBUG_INFO = NO;
486488
SDKROOT = iphoneos;
487489
SUPPORTED_PLATFORMS = iphoneos;

example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1300"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

example/ios/Runner/Info.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@
5959
</array>
6060
<key>UIViewControllerBasedStatusBarAppearance</key>
6161
<false/>
62+
<key>CADisableMinimumFrameDurationOnPhone</key>
63+
<true/>
64+
<key>UIApplicationSupportsIndirectInputEvents</key>
65+
<true/>
6266
</dict>
6367
</plist>

example/lib/main.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,18 @@ class _MyAppState extends State<MyApp> {
409409
print("loginwithkey===");
410410
},
411411
),
412+
ListTile(
413+
title: Text('isAutoTrackEventTypeIgnored'),
414+
onTap: () async {
415+
bool click = await SensorsAnalyticsFlutterPlugin.isAutoTrackEventTypeIgnored(SAAutoTrackType.APP_CLICK);
416+
bool end = await SensorsAnalyticsFlutterPlugin.isAutoTrackEventTypeIgnored(SAAutoTrackType.APP_END);
417+
bool start = await SensorsAnalyticsFlutterPlugin.isAutoTrackEventTypeIgnored(SAAutoTrackType.APP_START);
418+
bool screen = await SensorsAnalyticsFlutterPlugin.isAutoTrackEventTypeIgnored(SAAutoTrackType.APP_VIEW_SCREEN);
419+
420+
//SensorsAnalyticsFlutterPlugin.loginWithKey("sss3", "vvv3", {"p1111": "vvvv1"});
421+
print("isAutoTrackEventTypeIgnored====$click====$end====$start====$screen");
422+
},
423+
),
412424
],
413425
),
414426
),

example/test/widget_test.dart

Lines changed: 0 additions & 27 deletions
This file was deleted.

ios/Classes/SensorsAnalyticsFlutterPlugin.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
static NSString* const SensorsAnalyticsFlutterPluginMethodProfilePushKey = @"profilePushId";
5252
static NSString* const SensorsAnalyticsFlutterPluginMethodProfileUnsetPushKey = @"profileUnsetPushId";
5353
static NSString* const SensorsAnalyticsFlutterPluginMethodInit = @"init";
54+
static NSString* const SensorsAnalyticsFlutterPluginMethodIsAutoTrackEventTypeIgnored = @"isAutoTrackEventTypeIgnored";
5455

5556
/// 回调返回当前为可视化全埋点连接状态
5657
static NSString* const SensorsAnalyticsGetVisualizedConnectionStatus = @"getVisualizedConnectionStatus";
@@ -64,6 +65,9 @@
6465
/// 可视化全埋点状态改变,包括连接状态和自定义属性配置
6566
static NSNotificationName const kSAFlutterPluginVisualizedStatusChangedNotification = @"SensorsAnalyticsVisualizedStatusChangedNotification";
6667

68+
// referrer key
69+
static NSString* const SensorsAnalyticsPropertyReferrer = @"$referrer";
70+
6771
@interface SensorsAnalyticsFlutterPlugin()
6872
@property (nonatomic, weak) NSObject<FlutterPluginRegistrar> *registrar;
6973

@@ -362,6 +366,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
362366
// 发送 Flutter 页面元素信息
363367
[self invokeSABridgeWithMethod:method arguments:arguments];
364368
result(nil);
369+
} else if ([method isEqualToString:SensorsAnalyticsFlutterPluginMethodIsAutoTrackEventTypeIgnored]){
370+
// 判断某个 AutoTrack 事件类型是否被忽略
371+
NSNumber *autoTrackEventType = arguments[0];
372+
argumentSetNSNullToNil(&autoTrackEventType);
373+
BOOL ignored = [self isAutoTrackEventTypeIgnored:autoTrackEventType.integerValue];
374+
result([NSNumber numberWithBool:ignored]);
365375
} else {
366376
result(FlutterMethodNotImplemented);
367377
}
@@ -416,7 +426,13 @@ - (id)invokeSABridgeWithMethod:(NSString *)methodString arguments:(NSArray *)arg
416426
}
417427

418428
-(void)track:(NSString *)event properties:(nullable NSDictionary *)properties{
419-
[SensorsAnalyticsSDK.sharedInstance track:event withProperties:properties];
429+
NSMutableDictionary *tempProperties = [NSMutableDictionary dictionary];
430+
NSString *referrer = [[SensorsAnalyticsSDK sharedInstance] getLastScreenUrl];
431+
tempProperties[SensorsAnalyticsPropertyReferrer] = referrer;
432+
if (properties) {
433+
[tempProperties addEntriesFromDictionary:properties];
434+
}
435+
[SensorsAnalyticsSDK.sharedInstance track:event withProperties:[tempProperties copy]];
420436
}
421437

422438
-(NSString *)trackTimerStart:(NSString *)event{
@@ -685,6 +701,10 @@ - (void)startWithConfig:(NSDictionary *)config {
685701
}
686702
}
687703

704+
- (BOOL)isAutoTrackEventTypeIgnored:(SensorsAnalyticsAutoTrackEventType)eventType {
705+
return [[SensorsAnalyticsSDK sharedInstance] isAutoTrackEventTypeIgnored:eventType];
706+
}
707+
688708
static inline void argumentSetNSNullToNil(id *arg){
689709
*arg = (*arg == NSNull.null) ? nil:*arg;
690710
}

0 commit comments

Comments
 (0)