Skip to content

Commit

Permalink
Release 4.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujg-00 committed Dec 1, 2021
1 parent b2594de commit 80b3d63
Show file tree
Hide file tree
Showing 22 changed files with 789 additions and 327 deletions.
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SensorsAnalyticsSDK"
s.version = "4.0.3"
s.version = "4.0.4"
s.summary = "The official iOS SDK of Sensors Analytics."
s.homepage = "http://www.sensorsdata.cn"
s.source = { :git => 'https://github.com/sensorsdata/sa-sdk-ios.git', :tag => "v#{s.version}" }
Expand Down
72 changes: 62 additions & 10 deletions SensorsAnalyticsSDK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SANewCellClickPlugin.h
// SensorsAnalyticsSDK
//
// Created by 陈玉国 on 2021/11/8.
// Copyright © 2021 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 "SAEventTrackerPlugin.h"
#import "SAEventTrackerPluginProtocol.h"

NS_ASSUME_NONNULL_BEGIN

@interface SACellClickDynamicSubclassPlugin : SAEventTrackerPlugin <SAEventTrackerPluginProtocol>

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// SANewCellClickPlugin.m
// SensorsAnalyticsSDK
//
// Created by 陈玉国 on 2021/11/8.
// Copyright © 2021 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 "SACellClickDynamicSubclassPlugin.h"
#import "SASwizzle.h"
#import <UIKit/UIKit.h>

static NSString *const kSAEventTrackerPluginType = @"AppClick+ScrollView";

@implementation SACellClickDynamicSubclassPlugin

- (void)install {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self swizzleMethod];
});
self.enable = YES;
}

- (void)uninstall {
self.enable = NO;
}

- (NSString *)type {
return kSAEventTrackerPluginType;
}

- (void)swizzleMethod {
SEL selector = NSSelectorFromString(@"sensorsdata_setDelegate:");
[UITableView sa_swizzleMethod:@selector(setDelegate:)
withMethod:selector
error:NULL];
[UICollectionView sa_swizzleMethod:@selector(setDelegate:)
withMethod:selector
error:NULL];
}

@end
30 changes: 30 additions & 0 deletions SensorsAnalyticsSDK/AutoTrack/AppClick/Gesture/SAGesturePlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SAGesturePlugin.h
// SensorsAnalyticsSDK
//
// Created by 陈玉国 on 2021/11/10.
// Copyright © 2021 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 "SAEventTrackerPlugin.h"
#import "SAEventTrackerPluginProtocol.h"

NS_ASSUME_NONNULL_BEGIN

@interface SAGesturePlugin : SAEventTrackerPlugin <SAEventTrackerPluginProtocol>

@end

NS_ASSUME_NONNULL_END
63 changes: 63 additions & 0 deletions SensorsAnalyticsSDK/AutoTrack/AppClick/Gesture/SAGesturePlugin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// SAGesturePlugin.m
// SensorsAnalyticsSDK
//
// Created by 陈玉国 on 2021/11/10.
// Copyright © 2021 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 "SAGesturePlugin.h"
#import "SASwizzle.h"
#import "UIGestureRecognizer+SAAutoTrack.h"
#import <UIKit/UIKit.h>

static NSString *const kSAEventTrackerPluginType = @"AppClick+UIGestureRecognizer";

@implementation SAGesturePlugin

- (void)install {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self swizzleMethod];
});
self.enable = YES;
}

- (void)uninstall {
self.enable = NO;
}

- (NSString *)type {
return kSAEventTrackerPluginType;
}

- (void)swizzleMethod {
// Gesture
[UIGestureRecognizer sa_swizzleMethod:@selector(initWithTarget:action:)
withMethod:@selector(sensorsdata_initWithTarget:action:)
error:NULL];
[UIGestureRecognizer sa_swizzleMethod:@selector(addTarget:action:)
withMethod:@selector(sensorsdata_addTarget:action:)
error:NULL];
[UIGestureRecognizer sa_swizzleMethod:@selector(removeTarget:action:)
withMethod:@selector(sensorsdata_removeTarget:action:)
error:NULL];
}

@end
69 changes: 46 additions & 23 deletions SensorsAnalyticsSDK/AutoTrack/SAAutoTrackManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
#import "SensorsAnalyticsSDK+SAAutoTrack.h"
#import "UIViewController+SAPageLeave.h"

//event tracker plugins
#if __has_include("SACellClickHookDelegatePlugin.h")
#import "SACellClickHookDelegatePlugin.h"
#endif
#import "SACellClickDynamicSubclassPlugin.h"
#import "SAEventTrackerPluginManager.h"
#if __has_include("SAGesturePlugin.h")
#import "SAGesturePlugin.h"
#endif

@interface SAAutoTrackManager ()

@property (nonatomic, strong) SAAppStartTracker *appStartTracker;
Expand Down Expand Up @@ -98,9 +108,11 @@ - (void)setEnable:(BOOL)enable {

if (enable) {
[self enableAutoTrack];
} else {
[self.appPageLeaveTracker.timestamp removeAllObjects];
[self registerPlugins];
return;
}
[self.appPageLeaveTracker.timestamp removeAllObjects];
[self unregisterPlugins];
}

#pragma mark - SAAutoTrackModuleProtocol
Expand Down Expand Up @@ -302,27 +314,6 @@ - (void)enableAppClickAutoTrack {
SALogError(@"Failed to swizzle sendAction:to:forEvent: on UIAppplication. Details: %@", error);
error = NULL;
}

// Cell
SEL selector = NSSelectorFromString(@"sensorsdata_setDelegate:");
[UITableView sa_swizzleMethod:@selector(setDelegate:)
withMethod:selector
error:NULL];
[UICollectionView sa_swizzleMethod:@selector(setDelegate:)
withMethod:selector
error:NULL];

// Gesture
[UIGestureRecognizer sa_swizzleMethod:@selector(initWithTarget:action:)
withMethod:@selector(sensorsdata_initWithTarget:action:)
error:NULL];
[UIGestureRecognizer sa_swizzleMethod:@selector(addTarget:action:)
withMethod:@selector(sensorsdata_addTarget:action:)
error:NULL];
[UIGestureRecognizer sa_swizzleMethod:@selector(removeTarget:action:)
withMethod:@selector(sensorsdata_removeTarget:action:)
error:NULL];

}

- (void)enableAppPageLeave {
Expand All @@ -333,5 +324,37 @@ - (void)enableAppPageLeave {
[UIViewController sa_swizzleMethod:@selector(viewDidDisappear:) withMethod:@selector(sensorsdata_pageLeave_viewDidDisappear:) error:NULL];
}

- (void)registerPlugins {
BOOL enableAppClick = self.configOptions.autoTrackEventType & SensorsAnalyticsEventTypeAppClick;
if (!enableAppClick) {
return;
}
//UITableView/UICollectionView Cell + AppClick plugin register
#if __has_include("SACellClickHookDelegatePlugin.h")
[[SAEventTrackerPluginManager defaultManager] registerPlugin:[[SACellClickHookDelegatePlugin alloc] init]];
#else
[[SAEventTrackerPluginManager defaultManager] registerPlugin:[[SACellClickDynamicSubclassPlugin alloc] init]];
#endif

//UIGestureRecognizer + AppClick plugin register
#if __has_include("SAGesturePlugin.h")
[[SAEventTrackerPluginManager defaultManager] registerPlugin:[[SAGesturePlugin alloc] init]];
#endif
}

- (void)unregisterPlugins {
//unregister UITableView/UICollectionView cell click plugin
#if __has_include("SACellClickHookDelegatePlugin.h")
[[SAEventTrackerPluginManager defaultManager] unregisterPlugin:[SACellClickHookDelegatePlugin class]];
#else
[[SAEventTrackerPluginManager defaultManager] unregisterPlugin:[SACellClickDynamicSubclassPlugin class]];
#endif

//unregister SAGesturePlugin
#if __has_include("SAGesturePlugin.h")
[[SAEventTrackerPluginManager defaultManager] unregisterPlugin:[SAGesturePlugin class]];
#endif
}

@end

33 changes: 33 additions & 0 deletions SensorsAnalyticsSDK/Core/EventTrackerPlugin/SAEventTrackerPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// SAEventTrackerPlugin.h
// SensorsAnalyticsSDK
//
// Created by 陈玉国 on 2021/11/8.
// Copyright © 2021 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 SAEventTrackerPlugin : NSObject

@property (nonatomic, readonly) NSString *type;
@property (nonatomic, assign) BOOL enable;

@end

NS_ASSUME_NONNULL_END
29 changes: 29 additions & 0 deletions SensorsAnalyticsSDK/Core/EventTrackerPlugin/SAEventTrackerPlugin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// SAEventTrackerPlugin.m
// SensorsAnalyticsSDK
//
// Created by 陈玉国 on 2021/11/8.
// Copyright © 2021 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 "SAEventTrackerPlugin.h"

@implementation SAEventTrackerPlugin

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// SAEventTrackerPluginManager.h
// SensorsAnalyticsSDK
//
// Created by 陈玉国 on 2021/11/8.
// Copyright © 2021 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>
#import "SAEventTrackerPlugin.h"
#import "SAEventTrackerPluginProtocol.h"

NS_ASSUME_NONNULL_BEGIN

@interface SAEventTrackerPluginManager : NSObject

+ (instancetype)defaultManager;

//register plugin and install
- (void)registerPlugin:(SAEventTrackerPlugin<SAEventTrackerPluginProtocol> *)plugin;
- (void)unregisterPlugin:(Class)pluginClass;
- (void)unregisterAllPlugins;

- (void)enableAllPlugins;
- (void)disableAllPlugins;

- (SAEventTrackerPlugin<SAEventTrackerPluginProtocol> *)pluginWithType:(NSString *)pluginType;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 80b3d63

Please sign in to comment.