-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
陈玉国
authored and
陈玉国
committed
Nov 20, 2023
1 parent
e4a79ff
commit f316700
Showing
16 changed files
with
252 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// SAAppInteractTracker.h | ||
// SensorsAnalyticsSDK | ||
// | ||
// Created by 陈玉国 on 2023/10/23. | ||
// Copyright © 2015-2023 Sensors Data Co., Ltd. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface SAAppInteractTracker : NSObject | ||
|
||
@property (nonatomic, assign) BOOL awakeFromDeeplink; | ||
@property (nonatomic, copy) NSString *wakeupUrl; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// | ||
// SAAppInteractTracker.m | ||
// SensorsAnalyticsSDK | ||
// | ||
// Created by 陈玉国 on 2023/10/23. | ||
// Copyright © 2015-2023 Sensors Data Co., Ltd. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#if ! __has_feature(objc_arc) | ||
#error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag on this file. | ||
#endif | ||
|
||
#import "SAAppInteractTracker.h" | ||
#import "SAAppLifecycle.h" | ||
#import "SAConstants+Private.h" | ||
#import "SensorsAnalyticsSDK.h" | ||
#import "SAStoreManager.h" | ||
#import "SALog.h" | ||
#import "SAIdentifier.h" | ||
#import "SACommonUtility.h" | ||
|
||
@interface SAAppInteractTracker () | ||
|
||
@property (nonatomic, assign) BOOL hasInstalledApp; | ||
|
||
@end | ||
|
||
@implementation SAAppInteractTracker | ||
|
||
- (instancetype)init { | ||
if (self = [super init]) { | ||
[self addListener]; | ||
_hasInstalledApp = [self isAppInstalled]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)addListener { | ||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appLifecycleStateDidChange:) name:kSAAppLifecycleStateDidChangeNotification object:nil]; | ||
} | ||
|
||
- (void)removeListener { | ||
[[NSNotificationCenter defaultCenter] removeObserver:self name:kSAAppLifecycleStateDidChangeNotification object:nil]; | ||
} | ||
|
||
- (void)appLifecycleStateDidChange:(NSNotification *)sender { | ||
SAAppLifecycleState newState = [sender.userInfo[kSAAppLifecycleNewStateKey] integerValue]; | ||
SAAppLifecycleState oldState = [sender.userInfo[kSAAppLifecycleOldStateKey] integerValue]; | ||
if (!self.awakeFromDeeplink && oldState == SAAppLifecycleStateInit && newState == SAAppLifecycleStateStart) { | ||
self.awakeFromDeeplink = self.awakeFromDeeplink ?: self.wakeupUrl ? YES : NO; | ||
} | ||
if (newState == SAAppLifecycleStateStart) { | ||
[self trackAppInteract]; | ||
self.awakeFromDeeplink = NO; | ||
self.hasInstalledApp = [self isAppInstalled]; | ||
} | ||
} | ||
|
||
- (BOOL)shouldTrackAppInteract { | ||
NSTimeInterval lastAppInteractTimeInterval = [[SAStoreManager sharedInstance] doubleForKey:kSAAppInteractEventTimeIntervalKey]; | ||
NSTimeInterval nowTimeInterval = [[NSDate date] timeIntervalSince1970]; | ||
if (lastAppInteractTimeInterval >= nowTimeInterval) { | ||
SALogError(@"Incorrect timeInterval for last AppInteract event"); | ||
return NO; | ||
} | ||
if (lastAppInteractTimeInterval == 0) { | ||
return YES; | ||
} | ||
NSDate *lastAppInteractDate = [NSDate dateWithTimeIntervalSince1970:lastAppInteractTimeInterval]; | ||
BOOL inToday = [[NSCalendar currentCalendar] isDateInToday:lastAppInteractDate]; | ||
return !inToday; | ||
} | ||
|
||
- (void)trackAppInteract { | ||
if (![self shouldTrackAppInteract]) { | ||
return; | ||
} | ||
BOOL hasInstalledApp = self.hasInstalledApp; | ||
BOOL awakeFromDeeplink = self.awakeFromDeeplink; | ||
[[SensorsAnalyticsSDK sharedInstance] track:kSAAppInteractEventName withProperties:@{kSAEventPropertyHasInstalledApp: @(hasInstalledApp), kSAEventPropertyAwakeFromDeeplink: @(awakeFromDeeplink), kSAEventPropertyInstallSource: [SACommonUtility appInstallSource]}]; | ||
NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970]; | ||
[[SAStoreManager sharedInstance] setDouble:timestamp forKey:kSAAppInteractEventTimeIntervalKey]; | ||
} | ||
|
||
- (BOOL)isAppInstalled { | ||
SAStoreManager *manager = [SAStoreManager sharedInstance]; | ||
return [manager boolForKey:kSAHasTrackInstallationDisableCallback] || [manager boolForKey:kSAHasTrackInstallation]; | ||
} | ||
|
||
- (void)dealloc { | ||
[self removeListener]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.