Skip to content

Commit

Permalink
fix(flutter): ANLSPI-20126 do not send autotrack event when session s…
Browse files Browse the repository at this point in the history
…tate is not active
  • Loading branch information
YoloMao committed Jul 16, 2024
1 parent b995ae4 commit 1ae98f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
2 changes: 0 additions & 2 deletions Modules/Flutter/GrowingFlutterPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSString *, NSString *> *_Nullable)attributes;
- (void)trackViewElementEvent:(NSDictionary *)arguments;
Expand Down
28 changes: 10 additions & 18 deletions Modules/Flutter/GrowingFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 () <GrowingULAppLifecycleDelegate>
@interface GrowingFlutterPlugin ()

@end

Expand All @@ -36,7 +36,6 @@ @implementation GrowingFlutterPlugin
#pragma mark - GrowingModuleProtocol

- (void)growingModInit:(GrowingContext *)context {
[GrowingULAppLifecycle.sharedInstance addAppLifecycleDelegate:self];
}

+ (BOOL)singleton {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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];
}];
}

Expand Down

0 comments on commit 1ae98f0

Please sign in to comment.