From 1ae98f066d979c724aba9598f038e4781dac38d9 Mon Sep 17 00:00:00 2001 From: YoloMao Date: Tue, 16 Jul 2024 15:44:47 +0800 Subject: [PATCH] fix(flutter): ANLSPI-20126 do not send autotrack event when session state is not active --- Modules/Flutter/GrowingFlutterPlugin.h | 2 -- Modules/Flutter/GrowingFlutterPlugin.m | 28 +++++++++----------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Modules/Flutter/GrowingFlutterPlugin.h b/Modules/Flutter/GrowingFlutterPlugin.h index b877118df..e1986964b 100644 --- a/Modules/Flutter/GrowingFlutterPlugin.h +++ b/Modules/Flutter/GrowingFlutterPlugin.h @@ -29,8 +29,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy) void (^onWebCircleStart)(void); @property (nonatomic, copy) void (^onWebCircleStop)(void); @property (nonatomic, copy) void (^_Nullable onFlutterCircleDataChange)(NSDictionary *data); -@property (nonatomic, copy) void (^onAppDidBecomeActive)(void); -@property (nonatomic, copy) void (^onAppDidEnterBackground)(void); - (void)trackPageEvent:(NSDictionary *)arguments attributes:(NSDictionary *_Nullable)attributes; - (void)trackViewElementEvent:(NSDictionary *)arguments; diff --git a/Modules/Flutter/GrowingFlutterPlugin.m b/Modules/Flutter/GrowingFlutterPlugin.m index fea19febe..28028b6a3 100644 --- a/Modules/Flutter/GrowingFlutterPlugin.m +++ b/Modules/Flutter/GrowingFlutterPlugin.m @@ -21,13 +21,13 @@ #import "GrowingTrackerCore/Event/Autotrack/GrowingPageEvent.h" #import "GrowingTrackerCore/Event/Autotrack/GrowingViewElementEvent.h" #import "GrowingTrackerCore/Event/GrowingEventManager.h" +#import "GrowingTrackerCore/Manager/GrowingSession.h" #import "GrowingTrackerCore/Public/GrowingAttributesBuilder.h" #import "GrowingTrackerCore/Thread/GrowingDispatchManager.h" -#import "GrowingULAppLifecycle.h" GrowingMod(GrowingFlutterPlugin) -@interface GrowingFlutterPlugin () +@interface GrowingFlutterPlugin () @end @@ -36,7 +36,6 @@ @implementation GrowingFlutterPlugin #pragma mark - GrowingModuleProtocol - (void)growingModInit:(GrowingContext *)context { - [GrowingULAppLifecycle.sharedInstance addAppLifecycleDelegate:self]; } + (BOOL)singleton { @@ -73,7 +72,7 @@ - (void)trackPageEvent:(NSDictionary *)arguments if (attributes) { builder = builder.setAttributes(attributes); } - [[GrowingEventManager sharedInstance] postEventBuilder:builder]; + [self trackAutotrackEventWithBuilder:builder]; } - (void)trackViewElementEvent:(NSDictionary *)arguments { @@ -105,24 +104,17 @@ - (void)trackViewElementEvent:(NSDictionary *)arguments { if (index && [index isKindOfClass:[NSNumber class]]) { builder = builder.setIndex(index.intValue); } - [[GrowingEventManager sharedInstance] postEventBuilder:builder]; + [self trackAutotrackEventWithBuilder:builder]; } -#pragma mark - GrowingULAppLifecycleDelegate - -- (void)applicationDidBecomeActive { - [GrowingDispatchManager dispatchInGrowingThread:^{ - if (self.onAppDidBecomeActive) { - self.onAppDidBecomeActive(); - } - }]; -} - -- (void)applicationDidEnterBackground { +- (void)trackAutotrackEventWithBuilder:(GrowingBaseBuilder *)builder { [GrowingDispatchManager dispatchInGrowingThread:^{ - if (self.onAppDidEnterBackground) { - self.onAppDidEnterBackground(); + if ([GrowingSession currentSession].state != GrowingSessionStateActive) { + //避免在session正在切换的时机之前,flutter侧因用户业务逻辑在后台状态下触发PAGE,回到前台后生成,造成上一个session的访问时长过长 + //另外,flutter sdk的逻辑中,会在返回前台时补发一个当前页面的PAGE,可覆盖上述场景的PAGE生成 + return; } + [[GrowingEventManager sharedInstance] postEventBuilder:builder]; }]; }