Ta android + ios

This commit is contained in:
LYP
2024-08-07 20:22:28 +08:00
parent 69fee08c61
commit 76458664d8
722 changed files with 41709 additions and 1 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0f80018b6b2b62a46afd80f5d35584b9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
//
// TDPresetProperties+TDDisProperties.h
// ThinkingSDK
//
// Created by wwango on 2021/12/7.
// 不能使用的
#if __has_include(<ThinkingSDK/TDPresetProperties.h>)
#import <ThinkingSDK/TDPresetProperties.h>
#else
#import "TDPresetProperties.h"
#endif
NS_ASSUME_NONNULL_BEGIN
@interface TDPresetProperties (TDDisProperties)
// - 禁用功能并过滤字段拼接
@property(class, nonatomic, readonly) BOOL disableOpsReceiptProperties;
@property(class, nonatomic, readonly) BOOL disableStartReason;
@property(class, nonatomic, readonly) BOOL disableDisk;
@property(class, nonatomic, readonly) BOOL disableRAM;
@property(class, nonatomic, readonly) BOOL disableFPS;
@property(class, nonatomic, readonly) BOOL disableSimulator;
@property(class, nonatomic, readonly) BOOL disableAppVersion;
@property(class, nonatomic, readonly) BOOL disableOsVersion;
@property(class, nonatomic, readonly) BOOL disableManufacturer;
@property(class, nonatomic, readonly) BOOL disableDeviceModel;
@property(class, nonatomic, readonly) BOOL disableScreenHeight;
@property(class, nonatomic, readonly) BOOL disableScreenWidth;
@property(class, nonatomic, readonly) BOOL disableCarrier;
@property(class, nonatomic, readonly) BOOL disableDeviceId;
@property(class, nonatomic, readonly) BOOL disableSystemLanguage;
@property(class, nonatomic, readonly) BOOL disableLib;
@property(class, nonatomic, readonly) BOOL disableLibVersion;
@property(class, nonatomic, readonly) BOOL disableBundleId;
@property(class, nonatomic, readonly) BOOL disableOs;
@property(class, nonatomic, readonly) BOOL disableInstallTime;
@property(class, nonatomic, readonly) BOOL disableDeviceType;
@property(class, nonatomic, readonly) BOOL disableSessionID;
@property(class, nonatomic, readonly) BOOL disableCalibratedTime;
// - 只过滤字段
@property(class, nonatomic, readonly) BOOL disableNetworkType;
@property(class, nonatomic, readonly) BOOL disableZoneOffset;
@property(class, nonatomic, readonly) BOOL disableDuration;
@property(class, nonatomic, readonly) BOOL disableBackgroundDuration;
@property(class, nonatomic, readonly) BOOL disableAppCrashedReason;
@property(class, nonatomic, readonly) BOOL disableResumeFromBackground;
@property(class, nonatomic, readonly) BOOL disableElementId;
@property(class, nonatomic, readonly) BOOL disableElementType;
@property(class, nonatomic, readonly) BOOL disableElementContent;
@property(class, nonatomic, readonly) BOOL disableElementPosition;
@property(class, nonatomic, readonly) BOOL disableElementSelector;
@property(class, nonatomic, readonly) BOOL disableScreenName;
@property(class, nonatomic, readonly) BOOL disableTitle;
@property(class, nonatomic, readonly) BOOL disableUrl;
@property(class, nonatomic, readonly) BOOL disableReferrer;
/// 需要过滤的预置属性
+ (NSArray*)disPresetProperties;
/// 过滤预置属性
/// @param dataDic 外层property
+ (void)handleFilterDisPresetProperties:(NSMutableDictionary *)dataDic;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: fa7b9fe20e8169b47a9c2c70b2ddcc6f
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,342 @@
//
// TDPresetProperties+TDDisProperties.m
// ThinkingSDK
//
// Created by wwango on 2021/12/7.
//
#import "TDPresetProperties+TDDisProperties.h"
static BOOL _td_disableOpsReceiptProperties;
static BOOL _td_disableStartReason;
static BOOL _td_disableDisk;
static BOOL _td_disableRAM;
static BOOL _td_disableFPS;
static BOOL _td_disableSimulator;
static BOOL _td_disableAppVersion;
static BOOL _td_disableOsVersion;
static BOOL _td_disableManufacturer;
static BOOL _td_disableDeviceModel;
static BOOL _td_disableScreenHeight;
static BOOL _td_disableScreenWidth;
static BOOL _td_disableCarrier;
static BOOL _td_disableDeviceId;
static BOOL _td_disableSystemLanguage;
static BOOL _td_disableLib;
static BOOL _td_disableLibVersion;
static BOOL _td_disableBundleId;
static BOOL _td_disableOs;
static BOOL _td_disableInstallTime;
static BOOL _td_disableDeviceType;
static BOOL _td_disableSessionID;
static BOOL _td_disableCalibratedTime;
static BOOL _td_disableNetworkType;
static BOOL _td_disableZoneOffset;
static BOOL _td_disableDuration;
static BOOL _td_disableBackgroundDuration;
static BOOL _td_disableAppCrashedReason;
static BOOL _td_disableResumeFromBackground;
static BOOL _td_disableElementId;
static BOOL _td_disableElementType;
static BOOL _td_disableElementContent;
static BOOL _td_disableElementPosition;
static BOOL _td_disableElementSelector;
static BOOL _td_disableScreenName;
static BOOL _td_disableTitle;
static BOOL _td_disableUrl;
static BOOL _td_disableReferrer;
//
static const NSString *kTDPushInfo = @"ops_push_click";
// -
static const NSString *kTDStartReason = @"#start_reason";
static const NSString *kTDPerformanceRAM = @"#ram";
static const NSString *kTDPerformanceDISK = @"#disk";
static const NSString *kTDPerformanceSIM = @"#simulator";
static const NSString *kTDPerformanceFPS = @"#fps";
static const NSString *kTDPresentAppVersion = @"#app_version";
static const NSString *kTDPresentOsVersion = @"#os_version";
static const NSString *kTDPresentManufacturer = @"#manufacturer";
static const NSString *kTDPresentDeviceModel = @"#device_model";
static const NSString *kTDPresentScreenHeight = @"#screen_height";
static const NSString *kTDPresentScreenWidth = @"#screen_width";
static const NSString *kTDPresentCarrier = @"#carrier";
static const NSString *kTDPresentDeviceId = @"#device_id";
static const NSString *kTDPresentSystemLanguage = @"#system_language";
static const NSString *kTDPresentLib = @"#lib";
static const NSString *kTDPresentLibVersion = @"#lib_version";
static const NSString *kTDPresentOs = @"#os";
static const NSString *kTDPresentBundleId = @"#bundle_id";
static const NSString *kTDPresentInstallTime = @"#install_time";
static const NSString *kTDPresentDeviceType = @"#device_type";
static const NSString *kTDPresentSessionID = @"#session_id";
static const NSString *kTDPresentCalibratedTime = @"#time_calibration";
// -
static const NSString *kTDPresentNETWORKTYPE = @"#network_type";
static const NSString *kTDPresentZONEOFFSET = @"#zone_offset";
static const NSString *kTDPresentDURATION = @"#duration";
static const NSString *kTDPresentBACKGROUNDDURATION = @"#background_duration";
static const NSString *kTDPresentCRASHREASON = @"#app_crashed_reason";
static const NSString *kTDPresentRESUMEFROMBACKGROUND = @"#resume_from_background";
static const NSString *kTDPresentELEMENTID = @"#element_id";
static const NSString *kTDPresentELEMENTTYPE = @"#element_type";
static const NSString *kTDPresentELEMENTCONTENT = @"#element_content";
static const NSString *kTDPresentELEMENTPOSITION = @"#element_position";
static const NSString *kTDPresentELEMENTSELECTOR = @"#element_selector";
static const NSString *kTDPresentSCREENNAME = @"#screen_name";
static const NSString *kTDPresentTITLE = @"#title";
static const NSString *kTDPresentURL = @"#url";
static const NSString *kTDPresentREFERRER = @"#referrer";
static const NSString *kTDPresentOpsReceiptProperties = @"#ops_receipt_properties";
#define TD_MAIM_INFO_PLIST_DISPRESTPRO_KEY @"TDDisPresetProperties"
@implementation TDPresetProperties (TDDisProperties)
static NSMutableArray *__td_disPresetProperties;
+ (NSArray*)disPresetProperties {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSArray *disPresetProperties = (NSArray *)[[[NSBundle mainBundle] infoDictionary] objectForKey:TD_MAIM_INFO_PLIST_DISPRESTPRO_KEY];
if (disPresetProperties && disPresetProperties.count) {
__td_disPresetProperties = [NSMutableArray arrayWithArray:disPresetProperties];
if ([__td_disPresetProperties containsObject:kTDPresentZONEOFFSET]) {
[__td_disPresetProperties removeObject:kTDPresentZONEOFFSET];
}
_td_disableStartReason = [__td_disPresetProperties containsObject:kTDStartReason];
_td_disableDisk = [__td_disPresetProperties containsObject:kTDPerformanceDISK];
_td_disableRAM = [__td_disPresetProperties containsObject:kTDPerformanceRAM];
_td_disableFPS = [__td_disPresetProperties containsObject:kTDPerformanceFPS];
_td_disableSimulator = [__td_disPresetProperties containsObject:kTDPerformanceSIM];
_td_disableAppVersion = [__td_disPresetProperties containsObject:kTDPresentAppVersion];
_td_disableOsVersion = [__td_disPresetProperties containsObject:kTDPresentOsVersion];
_td_disableManufacturer = [__td_disPresetProperties containsObject:kTDPresentManufacturer];
_td_disableDeviceModel = [__td_disPresetProperties containsObject:kTDPresentDeviceModel];
_td_disableScreenHeight = [__td_disPresetProperties containsObject:kTDPresentScreenHeight];
_td_disableScreenWidth = [__td_disPresetProperties containsObject:kTDPresentScreenWidth];
_td_disableCarrier = [__td_disPresetProperties containsObject:kTDPresentCarrier];
_td_disableDeviceId = [__td_disPresetProperties containsObject:kTDPresentDeviceId];
_td_disableSystemLanguage = [__td_disPresetProperties containsObject:kTDPresentSystemLanguage];
_td_disableLib = [__td_disPresetProperties containsObject:kTDPresentLib];
_td_disableLibVersion = [__td_disPresetProperties containsObject:kTDPresentLibVersion];
_td_disableBundleId = [__td_disPresetProperties containsObject:kTDPresentBundleId];
_td_disableOs = [__td_disPresetProperties containsObject:kTDPresentOs];
_td_disableInstallTime = [__td_disPresetProperties containsObject:kTDPresentInstallTime];
_td_disableDeviceType = [__td_disPresetProperties containsObject:kTDPresentDeviceType];
//_td_disableSessionID = [__td_disPresetProperties containsObject:kTDPresentSessionID];
//_td_disableCalibratedTime = [__td_disPresetProperties containsObject:kTDPresentCalibratedTime];
_td_disableSessionID = YES;
_td_disableCalibratedTime = YES;
_td_disableNetworkType = [__td_disPresetProperties containsObject:kTDPresentNETWORKTYPE];
_td_disableZoneOffset = [__td_disPresetProperties containsObject:kTDPresentZONEOFFSET];
_td_disableDuration = [__td_disPresetProperties containsObject:kTDPresentDURATION];
_td_disableBackgroundDuration = [__td_disPresetProperties containsObject:kTDPresentBACKGROUNDDURATION];
_td_disableAppCrashedReason = [__td_disPresetProperties containsObject:kTDPresentCRASHREASON];
_td_disableResumeFromBackground = [__td_disPresetProperties containsObject:kTDPresentRESUMEFROMBACKGROUND];
_td_disableElementId = [__td_disPresetProperties containsObject:kTDPresentELEMENTID];
_td_disableElementType = [__td_disPresetProperties containsObject:kTDPresentELEMENTTYPE];
_td_disableElementContent = [__td_disPresetProperties containsObject:kTDPresentELEMENTCONTENT];
_td_disableElementPosition = [__td_disPresetProperties containsObject:kTDPresentELEMENTPOSITION];
_td_disableElementSelector = [__td_disPresetProperties containsObject:kTDPresentELEMENTSELECTOR];
_td_disableScreenName = [__td_disPresetProperties containsObject:kTDPresentSCREENNAME];
_td_disableTitle = [__td_disPresetProperties containsObject:kTDPresentTITLE];
_td_disableUrl = [__td_disPresetProperties containsObject:kTDPresentURL];
_td_disableReferrer = [__td_disPresetProperties containsObject:kTDPresentREFERRER];
_td_disableOpsReceiptProperties = [__td_disPresetProperties containsObject:kTDPresentOpsReceiptProperties];
}
});
return __td_disPresetProperties;
}
+ (void)handleFilterDisPresetProperties:(NSMutableDictionary *)dataDic
{
if (!__td_disPresetProperties || !__td_disPresetProperties.count) {
return ;
}
NSArray *propertykeys = dataDic.allKeys;
NSArray *registerkeys = [TDPresetProperties disPresetProperties];
NSMutableSet *set1 = [NSMutableSet setWithArray:propertykeys];
NSMutableSet *set2 = [NSMutableSet setWithArray:registerkeys];
[set1 intersectSet:set2];//
if (!set1.allObjects.count) {
return ;
}
[dataDic removeObjectsForKeys:set1.allObjects];
return ;
}
+ (BOOL)disableOpsReceiptProperties {
return _td_disableOpsReceiptProperties;
}
+ (BOOL)disableStartReason {
return _td_disableStartReason;
}
+ (BOOL)disableDisk {
return _td_disableDisk;
}
+ (BOOL)disableRAM {
return _td_disableRAM;
}
+ (BOOL)disableFPS {
return _td_disableFPS;
}
+ (BOOL)disableSimulator {
return _td_disableSimulator;
}
+ (BOOL)disableAppVersion {
return _td_disableAppVersion;
}
+ (BOOL)disableOsVersion {
return _td_disableOsVersion;
}
+ (BOOL)disableManufacturer {
return _td_disableManufacturer;
}
+ (BOOL)disableDeviceId {
return _td_disableDeviceId;
}
+ (BOOL)disableDeviceModel {
return _td_disableDeviceModel;
}
+ (BOOL)disableScreenHeight {
return _td_disableScreenHeight;
}
+ (BOOL)disableScreenWidth {
return _td_disableScreenWidth;
}
+ (BOOL)disableCarrier {
return _td_disableCarrier;
}
+ (BOOL)disableSystemLanguage {
return _td_disableSystemLanguage;
}
+ (BOOL)disableLib {
return _td_disableLib;
}
+ (BOOL)disableLibVersion {
return _td_disableLibVersion;
}
+ (BOOL)disableOs {
return _td_disableOs;
}
+ (BOOL)disableBundleId {
return _td_disableBundleId;
}
+ (BOOL)disableInstallTime {
return _td_disableInstallTime;
}
+ (BOOL)disableDeviceType {
return _td_disableDeviceType;
}
+ (BOOL)disableNetworkType {
return _td_disableNetworkType;
}
+ (BOOL)disableZoneOffset {
return _td_disableZoneOffset;
}
+ (BOOL)disableDuration {
return _td_disableDuration;
}
+ (BOOL)disableBackgroundDuration {
return _td_disableBackgroundDuration;
}
+ (BOOL)disableAppCrashedReason {
return _td_disableAppCrashedReason;
}
+ (BOOL)disableResumeFromBackground {
return _td_disableResumeFromBackground;
}
+ (BOOL)disableElementId {
return _td_disableElementId;
}
+ (BOOL)disableElementType {
return _td_disableElementType;
}
+ (BOOL)disableElementContent {
return _td_disableElementContent;
}
+ (BOOL)disableElementPosition {
return _td_disableElementPosition;
}
+ (BOOL)disableElementSelector {
return _td_disableElementSelector;
}
+ (BOOL)disableScreenName {
return _td_disableScreenName;
}
+ (BOOL)disableTitle {
return _td_disableTitle;
}
+ (BOOL)disableUrl {
return _td_disableUrl;
}
+ (BOOL)disableReferrer {
return _td_disableReferrer;
}
+ (BOOL)disableSessionID {
return _td_disableSessionID;
}
+ (BOOL)disableCalibratedTime {
return _td_disableCalibratedTime;
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: e86fd2feb4c097446a73f152c1db5837
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
//
// TDPresetProperties.h
// ThinkingSDK
//
// Created by huangdiao on 2021/5/25.
// Copyright © 2021 thinkingdata. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TDPresetProperties : NSObject
@property (nonatomic, copy, readonly) NSString *bundle_id;
@property (nonatomic, copy, readonly) NSString *carrier;
@property (nonatomic, copy, readonly) NSString *device_id;
@property (nonatomic, copy, readonly) NSString *device_model;
@property (nonatomic, copy, readonly) NSString *manufacturer;
@property (nonatomic, copy, readonly) NSString *network_type;
@property (nonatomic, copy, readonly) NSString *os;
@property (nonatomic, copy, readonly) NSString *os_version;
@property (nonatomic, copy, readonly) NSNumber *screen_height;
@property (nonatomic, copy, readonly) NSNumber *screen_width;
@property (nonatomic, copy, readonly) NSString *system_language;
@property (nonatomic, copy, readonly) NSNumber *zone_offset;
@property (nonatomic, copy, readonly) NSString *install_time;
/**
* The key of the returned event preset property starts with "#", and it is not recommended to use it directly as the property of the event
*/
- (NSDictionary *)toEventPresetProperties;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: be2a7a171219eae44818a7bd33a279b3
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,88 @@
//
// TDPresetProperties.m
// ThinkingSDK
//
// Created by huangdiao on 2021/5/25.
// Copyright © 2021 thinkingdata. All rights reserved.
//
#import "TDPresetProperties.h"
#import "TDPresetProperties+TDDisProperties.h"
@interface TDPresetProperties ()
@property (nonatomic, copy, readwrite) NSString *bundle_id;
@property (nonatomic, copy, readwrite) NSString *carrier;
@property (nonatomic, copy, readwrite) NSString *device_id;
@property (nonatomic, copy, readwrite) NSString *device_model;
@property (nonatomic, copy, readwrite) NSString *manufacturer;
@property (nonatomic, copy, readwrite) NSString *network_type;
@property (nonatomic, copy, readwrite) NSString *os;
@property (nonatomic, copy, readwrite) NSString *os_version;
@property (nonatomic, copy, readwrite) NSNumber *screen_height;
@property (nonatomic, copy, readwrite) NSNumber *screen_width;
@property (nonatomic, copy, readwrite) NSString *system_language;
@property (nonatomic, copy, readwrite) NSNumber *zone_offset;
@property (nonatomic, copy, readwrite) NSString *install_time;
@property (nonatomic, copy) NSDictionary *presetProperties;
@end
@implementation TDPresetProperties
- (instancetype)initWithDictionary:(NSDictionary *)dict {
self = [super init];
if (self) {
[self updateValuesWithDictionary:dict];
}
return self;
}
- (void)updateValuesWithDictionary:(NSDictionary *)dict {
_bundle_id = dict[@"#bundle_id"]?:@"";
_carrier = dict[@"#carrier"]?:@"";
_device_id = dict[@"#device_id"]?:@"";
_device_model = dict[@"#device_model"]?:@"";
_manufacturer = dict[@"#manufacturer"]?:@"";
_network_type = dict[@"#network_type"]?:@"";
_os = dict[@"#os"]?:@"";
_os_version = dict[@"#os_version"]?:@"";
_screen_height = dict[@"#screen_height"]?:@(0);
_screen_width = dict[@"#screen_width"]?:@(0);
_system_language = dict[@"#system_language"]?:@"";
_zone_offset = dict[@"#zone_offset"]?:@(0);
_install_time = dict[@"#install_time"]?:@"";
_presetProperties = [NSDictionary dictionaryWithDictionary:dict];
NSMutableDictionary *updateProperties = [_presetProperties mutableCopy];
NSArray *propertykeys = updateProperties.allKeys;
NSArray *registerkeys = [TDPresetProperties disPresetProperties];
NSMutableSet *set1 = [NSMutableSet setWithArray:propertykeys];
NSMutableSet *set2 = [NSMutableSet setWithArray:registerkeys];
[set1 intersectSet:set2];
if (set1.allObjects.count) {
[updateProperties removeObjectsForKeys:set1.allObjects];
}
if ([updateProperties.allKeys containsObject:@"#lib"]) {
[updateProperties removeObjectForKey:@"#lib"];
}
if ([updateProperties.allKeys containsObject:@"#lib_version"]) {
[updateProperties removeObjectForKey:@"#lib_version"];
}
if ([updateProperties.allKeys containsObject:@"#time_calibration"]) {
[updateProperties removeObjectForKey:@"#time_calibration"];
}
_presetProperties = updateProperties;
}
- (NSDictionary *)toEventPresetProperties {
return [_presetProperties copy];
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 63af3e2b94b0a3f428bf23cb7e8a8f68
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8956e17887d5e364d87791db095f5edf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
//
// TAPresetPropertyPlugin.h
// ThinkingSDK
//
// Created by Yangxiongon 2022/6/12.
//
#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#endif
#import "TAPropertyPluginManager.h"
NS_ASSUME_NONNULL_BEGIN
@interface TAPresetPropertyPlugin : NSObject<TAPropertyPluginProtocol>
@property(nonatomic, copy)NSString *instanceToken;
@property (nonatomic, strong) NSTimeZone *defaultTimeZone;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 000e3e0ae2b22e24c8f5a87332343565
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,61 @@
//
// TAPresetPropertyPlugin.m
// ThinkingSDK
//
// Created by Yangxiongon 2022/6/12.
//
#import "TAPresetPropertyPlugin.h"
#import "TDPresetProperties.h"
#import "TDPresetProperties+TDDisProperties.h"
#import "TDDeviceInfo.h"
#import "TAReachability.h"
#import "NSDate+TAFormat.h"
@interface TAPresetPropertyPlugin ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, id> *properties;
@end
@implementation TAPresetPropertyPlugin
- (instancetype)init
{
self = [super init];
if (self) {
self.properties = [NSMutableDictionary dictionary];
}
return self;
}
- (void)start {
if (![TDPresetProperties disableAppVersion]) {
self.properties[@"#app_version"] = [TDDeviceInfo sharedManager].appVersion;
}
if (![TDPresetProperties disableBundleId]) {
self.properties[@"#bundle_id"] = [TDDeviceInfo bundleId];
}
if (![TDPresetProperties disableInstallTime]) {
NSString *timeString = [[TDDeviceInfo td_getInstallTime] ta_formatWithTimeZone:self.defaultTimeZone formatString: @"yyyy-MM-dd HH:mm:ss.SSS"];
if (timeString && [timeString isKindOfClass:[NSString class]] && timeString.length){
self.properties[@"#install_time"] = timeString;
}
}
}
- (void)asyncGetPropertyCompletion:(TAPropertyPluginCompletion)completion {
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
[mutableDict addEntriesFromDictionary:[[TDDeviceInfo sharedManager] getAutomaticData]];
if (![TDPresetProperties disableNetworkType]) {
mutableDict[@"#network_type"] = [[TAReachability shareInstance] networkState];
}
if (completion) {
completion(mutableDict);
}
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 0d82a3ca4f3430e48ba011b309387866
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
//
// TAPropertyPluginManager.h
// ThinkingSDK
//
// Created by Yangxiongon 2022/6/12.
//
#import <Foundation/Foundation.h>
#import "TABaseEvent.h"
NS_ASSUME_NONNULL_BEGIN
typedef void(^TAPropertyPluginCompletion)(NSDictionary<NSString *, id> *properties);
@protocol TAPropertyPluginProtocol <NSObject>
@property(nonatomic, copy)NSString *instanceToken;
- (NSDictionary<NSString *, id> *)properties;
@optional
- (void)start;
- (TAEventType)eventTypeFilter;
- (void)asyncGetPropertyCompletion:(TAPropertyPluginCompletion)completion;
@end
@interface TAPropertyPluginManager : NSObject
- (void)registerPropertyPlugin:(id<TAPropertyPluginProtocol>)plugin;
- (NSMutableDictionary<NSString *, id> *)currentPropertiesForPluginClasses:(NSArray<Class> *)classes;
- (NSMutableDictionary<NSString *, id> *)propertiesWithEventType:(TAEventType)type;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: b18a39c791368ed428e8fbc76a89de00
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,127 @@
//
// TAPropertyPluginManager.m
// ThinkingSDK
//
// Created by Yangxiongon 2022/6/12.
//
#import "TAPropertyPluginManager.h"
@interface TAPropertyPluginManager ()
@property (nonatomic, strong) NSMutableArray<id<TAPropertyPluginProtocol>> *plugins;
@end
@implementation TAPropertyPluginManager
//MARK: - Public Methods
- (instancetype)init {
self = [super init];
if (self) {
self.plugins = [NSMutableArray array];
}
return self;
}
- (void)registerPropertyPlugin:(id<TAPropertyPluginProtocol>)plugin {
BOOL isResponds = [plugin respondsToSelector:@selector(properties)];
NSAssert(isResponds, @"properties plugin must implement `- properties` method!");
if (!isResponds) {
return;
}
// delete old plugin
for (id<TAPropertyPluginProtocol> object in self.plugins) {
if (object.class == plugin.class) {
[self.plugins removeObject:object];
break;
}
}
[self.plugins addObject:plugin];
if ([plugin respondsToSelector:@selector(start)]) {
[plugin start];
}
}
- (NSMutableDictionary<NSString *,id> *)currentPropertiesForPluginClasses:(NSArray<Class> *)classes {
NSArray *plugins = [self.plugins copy];
NSMutableArray<id<TAPropertyPluginProtocol>> *matchResult = [NSMutableArray array];
for (id<TAPropertyPluginProtocol> obj in plugins) {
for (Class cla in classes) {
if ([obj isKindOfClass:cla]) {
[matchResult addObject:obj];
break;
}
}
}
NSMutableDictionary *pluginProperties = [self propertiesWithPlugins:matchResult];
return pluginProperties;
}
- (NSMutableDictionary<NSString *,id> *)propertiesWithEventType:(TAEventType)type {
NSArray *plugins = [self.plugins copy];
NSMutableArray<id<TAPropertyPluginProtocol>> *matchResult = [NSMutableArray array];
for (id<TAPropertyPluginProtocol> obj in plugins) {
if ([self isMatchedWithPlugin:obj eventType:type]) {
[matchResult addObject:obj];
}
}
return [self propertiesWithPlugins:matchResult];
}
//MARK: - Private Methods
- (NSMutableDictionary *)propertiesWithPlugins:(NSArray<id<TAPropertyPluginProtocol>> *)plugins {
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
dispatch_semaphore_t semaphore;
for (id<TAPropertyPluginProtocol> plugin in plugins) {
if ([plugin respondsToSelector:@selector(asyncGetPropertyCompletion:)]) {
semaphore = dispatch_semaphore_create(0);
[plugin asyncGetPropertyCompletion:^(NSDictionary<NSString *,id> * _Nonnull dict) {
[properties addEntriesFromDictionary:dict];
dispatch_semaphore_signal(semaphore);
}];
}
NSDictionary *pluginProperties = [plugin respondsToSelector:@selector(properties)] ? plugin.properties : nil;
if (pluginProperties) {
[properties addEntriesFromDictionary:pluginProperties];
}
if (semaphore) {
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)));
}
semaphore = nil;
}
return properties;
}
- (BOOL)isMatchedWithPlugin:(id<TAPropertyPluginProtocol>)plugin eventType:(TAEventType)type {
TAEventType eventTypeFilter;
if (![plugin respondsToSelector:@selector(eventTypeFilter)]) {
// If the plug-in does not implement the type filtering method, it will only be added for track type data by default, including the first event, updateable event, and rewritable event. In addition to user attribute events
eventTypeFilter = TAEventTypeTrack | TAEventTypeTrackFirst | TAEventTypeTrackUpdate | TAEventTypeTrackOverwrite;
} else {
eventTypeFilter = plugin.eventTypeFilter;
}
if ((eventTypeFilter & type) == type) {
return YES;
}
return NO;
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: c111649cbe2bc7147ae29d6d1c34414c
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
//
// TASessionIdManager.h
// ThinkingSDK
//
// Created by Charles on 6.12.22.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TASessionIdManager : NSObject
+ (instancetype)shareInstance;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 6dbe7ef45b4d88747904e89fa268be52
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
//
// TASessionIdManager.m
// ThinkingSDK
//
// Created by Charles on 6.12.22.
//
#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#endif
#import "TASessionIdManager.h"
#import "TAAppLifeCycle.h"
#import "TDAppState.h"
#import "ThinkingAnalyticsSDKPrivate.h"
@implementation TASessionIdManager
+ (instancetype)shareInstance {
static dispatch_once_t onceToken;
static id instance = nil;
dispatch_once(&onceToken, ^{
instance = [[[self class] alloc] init];
});
return instance;
}
- (instancetype)init
{
self = [super init];
if (self) {
[self registerAppLifeCycleListener];
}
return self;
}
- (void)registerAppLifeCycleListener {
if ([TDAppState runningInAppExtension]) {
return;
}
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
#if TARGET_OS_IOS
[notificationCenter addObserver:self selector:@selector(appStateWillChangeNotification:) name:kTAAppLifeCycleStateWillChangeNotification object:nil];
#endif
}
- (void)appStateWillChangeNotification:(NSNotification *)notification {
TAAppLifeCycleState newState = [[notification.userInfo objectForKey:kTAAppLifeCycleNewStateKey] integerValue];
TAAppLifeCycleState oldState = [[notification.userInfo objectForKey:kTAAppLifeCycleOldStateKey] integerValue];
if (oldState == TAAppLifeCycleStateInit) {
return;
}
if (newState == TAAppLifeCycleStateStart) {
@synchronized ([self class]) {
[self updateSessionId];
}
}
}
- (void)updateSessionId {
// NSMutableDictionary *dic = [ThinkingAnalyticsSDK _getAllInstances];
// for (NSString *instanceToken in dic.allKeys) {
// ThinkingAnalyticsSDK *instance = dic[instanceToken];
// if ([instance isKindOfClass:[ThinkingAnalyticsSDK class]]) {
// [instance.sessionidPlugin updateSessionId];
// }
// }
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: d337a51411d7b0f4e913089deb7a0f89
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
//
// TASessionIdPropertyPlugin.h
// ThinkingSDK
//
// Created by Charles on 28.11.22.
//
#if TARGET_OS_IOS
#import <UIKit/UIKit.h>
#endif
#import "TAPropertyPluginManager.h"
NS_ASSUME_NONNULL_BEGIN
@interface TASessionIdPropertyPlugin : NSObject<TAPropertyPluginProtocol>
@property(nonatomic, copy)NSString *instanceToken;
- (void)updateSessionId;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 42e00b90bf099a645987eb01277fb3c7
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,66 @@
//
// TASessionIdPropertyPlugin.m
// ThinkingSDK
//
// Created by Charles on 28.11.22.
//
#import "TASessionIdPropertyPlugin.h"
#import "TDPresetProperties.h"
#import "TDPresetProperties+TDDisProperties.h"
#import "TAAppLifeCycle.h"
#import "TDFile.h"
#import "TDAppState.h"
@interface TASessionIdPropertyPlugin ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, id> *properties;
@property (nonatomic, strong) TDFile *file;
@property (atomic, assign) long long sessionid;
@property (atomic, copy) NSString *sessionidString;
@end
@implementation TASessionIdPropertyPlugin
- (instancetype)init
{
self = [super init];
if (self) {
self.properties = [NSMutableDictionary dictionary];
}
return self;
}
- (void)updateSessionId {
#if TARGET_OS_IOS
if (![TDPresetProperties disableSessionID]) {
@synchronized ([self class]) {
self.sessionid ++;
self.sessionidString = [NSString stringWithFormat:@"%@_%lld", [NSUUID UUID].UUIDString, self.sessionid];
[self.file archiveSessionID:self.sessionid];
self.properties[@"#session_id"] = self.sessionidString;
}
}
#endif
}
- (void)start {
if (![TDPresetProperties disableSessionID]) {
@synchronized ([self class]) {
if (!self.file) {
self.file = [[TDFile alloc] initWithAppid:self.instanceToken];
}
self.sessionid = [self.file unarchiveSessionID];
[self updateSessionId];
}
}
}
- (void)asyncGetPropertyCompletion:(TAPropertyPluginCompletion)completion {
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 720df558845bf294e80b241e86d6ab7f
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
//
// TAAutoTrackSuperProperty.h
// ThinkingSDK
//
// Created by Yangxiongon 2022/6/19.
//
#import <Foundation/Foundation.h>
#import "TDConstant.h"
NS_ASSUME_NONNULL_BEGIN
@interface TAAutoTrackSuperProperty : NSObject
- (void)registerSuperProperties:(NSDictionary *)properties withType:(ThinkingAnalyticsAutoTrackEventType)type;
- (NSDictionary *)currentSuperPropertiesWithEventName:(NSString *)eventName;
- (void)registerDynamicSuperProperties:(NSDictionary<NSString *, id> *(^)(ThinkingAnalyticsAutoTrackEventType, NSDictionary *))dynamicSuperProperties;
- (NSDictionary *)obtainDynamicSuperPropertiesWithType:(ThinkingAnalyticsAutoTrackEventType)type currentProperties:(NSDictionary *)properties;
/// Only used for auto track in Unity3D environment
/// - Parameter dynamicSuperProperties: dynamic properties
- (void)registerAutoTrackDynamicProperties:(NSDictionary<NSString *, id> *(^ _Nullable)(void))dynamicSuperProperties;
/// Only used for auto track in Unity3D environment
- (NSDictionary *)obtainAutoTrackDynamicSuperProperties;
- (void)clearSuperProperties;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 18d01d4c971ce524982ecc27bdd39870
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,121 @@
//
// TAAutoTrackSuperProperty.m
// ThinkingSDK
//
// Created by Yangxiongon 2022/6/19.
//
#import "TAAutoTrackSuperProperty.h"
#import "ThinkingAnalyticsSDKPrivate.h"
@interface TAAutoTrackSuperProperty ()
@property (atomic, strong) NSMutableDictionary<NSString *, NSDictionary *> *eventProperties;
@property (nonatomic, copy) NSDictionary *(^dynamicSuperProperties)(ThinkingAnalyticsAutoTrackEventType type, NSDictionary *properties);
/// Only used for auto track in Unity3D environment
@property (nonatomic, copy) NSDictionary<NSString *, id> *(^autoTrackDynamicSuperProperties)(void);
@end
@implementation TAAutoTrackSuperProperty
- (instancetype)init
{
self = [super init];
if (self) {
self.eventProperties = [NSMutableDictionary dictionary];
}
return self;
}
- (void)registerSuperProperties:(NSDictionary *)properties withType:(ThinkingAnalyticsAutoTrackEventType)type {
NSDictionary<NSNumber *, NSString *> *autoTypes = @{
@(ThinkingAnalyticsEventTypeAppStart) : TD_APP_START_EVENT,
@(ThinkingAnalyticsEventTypeAppEnd) : TD_APP_END_EVENT,
@(ThinkingAnalyticsEventTypeAppClick) : TD_APP_CLICK_EVENT,
@(ThinkingAnalyticsEventTypeAppInstall) : TD_APP_INSTALL_EVENT,
@(ThinkingAnalyticsEventTypeAppViewCrash) : TD_APP_CRASH_EVENT,
@(ThinkingAnalyticsEventTypeAppViewScreen) : TD_APP_VIEW_EVENT
};
NSArray<NSNumber *> *typeKeys = autoTypes.allKeys;
for (NSInteger i = 0; i < typeKeys.count; i++) {
NSNumber *key = typeKeys[i];
ThinkingAnalyticsAutoTrackEventType eventType = key.integerValue;
if ((type & eventType) == eventType) {
NSString *eventName = autoTypes[key];
if (properties) {
NSDictionary *oldProperties = self.eventProperties[eventName];
if (oldProperties && [oldProperties isKindOfClass:[NSDictionary class]]) {
NSMutableDictionary *mutiOldProperties = [oldProperties mutableCopy];
[mutiOldProperties addEntriesFromDictionary:properties];
self.eventProperties[eventName] = mutiOldProperties;
} else {
self.eventProperties[eventName] = properties;
}
if (eventType == ThinkingAnalyticsEventTypeAppStart) {
NSDictionary *startParam = self.eventProperties[TD_APP_START_EVENT];
if (startParam && [startParam isKindOfClass:[NSDictionary class]]) {
self.eventProperties[TD_APP_START_BACKGROUND_EVENT] = startParam;
}
}
}
}
}
}
- (NSDictionary *)currentSuperPropertiesWithEventName:(NSString *)eventName {
NSDictionary *autoEventProperty = [self.eventProperties objectForKey:eventName];
NSDictionary *validProperties = [TAPropertyValidator validateProperties:[autoEventProperty copy]];
return validProperties;
}
- (void)registerDynamicSuperProperties:(NSDictionary<NSString *, id> *(^)(ThinkingAnalyticsAutoTrackEventType, NSDictionary *))dynamicSuperProperties {
@synchronized (self) {
self.dynamicSuperProperties = dynamicSuperProperties;
}
}
- (NSDictionary *)obtainDynamicSuperPropertiesWithType:(ThinkingAnalyticsAutoTrackEventType)type currentProperties:(NSDictionary *)properties {
@synchronized (self) {
if (self.dynamicSuperProperties) {
NSDictionary *result = self.dynamicSuperProperties(type, properties);
NSDictionary *validProperties = [TAPropertyValidator validateProperties:[result copy]];
return validProperties;
}
return nil;
}
}
- (void)registerAutoTrackDynamicProperties:(NSDictionary<NSString *,id> * _Nonnull (^)(void))dynamicSuperProperties {
@synchronized (self) {
self.autoTrackDynamicSuperProperties = dynamicSuperProperties;
}
}
- (NSDictionary *)obtainAutoTrackDynamicSuperProperties {
@synchronized (self) {
if (self.autoTrackDynamicSuperProperties) {
NSDictionary *properties = self.autoTrackDynamicSuperProperties();
NSDictionary *validProperties = [TAPropertyValidator validateProperties:[properties copy]];
return validProperties;
}
return nil;
}
}
- (void)clearSuperProperties {
self.eventProperties = [@{} mutableCopy];
}
//MARK: - Private Methods
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 8a0a6059a7aa043478b3f9d5aa546030
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
//
// TASuperProperty.h
// ThinkingSDK
//
// Created by Yangxiongon 2022/6/10.
//
// Methods related to static public properties of this class are not thread-safe; methods related to dynamic public properties are thread-safe.
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TASuperProperty : NSObject
#pragma mark - UNAVAILABLE
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)initWithToken:(NSString *)token isLight:(BOOL)isLight;
- (void)registerSuperProperties:(NSDictionary *)properties;
- (void)unregisterSuperProperty:(NSString *)property;
- (void)clearSuperProperties;
- (NSDictionary *)currentSuperProperties;
- (void)registerDynamicSuperProperties:(NSDictionary<NSString *, id> *(^ _Nullable)(void))dynamicSuperProperties;
- (NSDictionary *)obtainDynamicSuperProperties;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: da3cad822fb23aa418f6587d2dc85768
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,106 @@
//
// TASuperProperty.m
// ThinkingSDK
//
// Created by Yangxiongon 2022/6/10.
//
#import "TASuperProperty.h"
#import "TAPropertyValidator.h"
#import "TDLogging.h"
#import "TDFile.h"
@interface TASuperProperty ()
///multi-instance identifier
@property (nonatomic, copy) NSString *token;
/// static public property
@property (atomic, strong) NSDictionary *superProperties;
/// dynamic public properties
@property (nonatomic, copy) NSDictionary<NSString *, id> *(^dynamicSuperProperties)(void);
@property (nonatomic, strong) TDFile *file;
@property (nonatomic, assign) BOOL isLight;
@end
@implementation TASuperProperty
- (instancetype)initWithToken:(NSString *)token isLight:(BOOL)isLight {
if (self = [super init]) {
NSAssert(token.length > 0, @"token cant empty");
self.token = token;
self.isLight = isLight;
if (!isLight) {
self.file = [[TDFile alloc] initWithAppid:token];
self.superProperties = [self.file unarchiveSuperProperties];
}
}
return self;
}
- (void)registerSuperProperties:(NSDictionary *)properties {
properties = [properties copy];
properties = [TAPropertyValidator validateProperties:properties];
if (properties.count <= 0) {
TDLogError(@"%@ propertieDict error.", properties);
return;
}
NSMutableDictionary *tmp = [NSMutableDictionary dictionaryWithDictionary:self.superProperties];
[tmp addEntriesFromDictionary:properties];
self.superProperties = [NSDictionary dictionaryWithDictionary:tmp];
[self.file archiveSuperProperties:self.superProperties];
}
- (void)unregisterSuperProperty:(NSString *)property {
NSError *error = nil;
[TAPropertyValidator validateEventOrPropertyName:property withError:&error];
if (error) {
return;
}
NSMutableDictionary *tmp = [NSMutableDictionary dictionaryWithDictionary:self.superProperties];
tmp[property] = nil;
self.superProperties = [NSDictionary dictionaryWithDictionary:tmp];
[self.file archiveSuperProperties:self.superProperties];
}
- (void)clearSuperProperties {
self.superProperties = @{};
[self.file archiveSuperProperties:self.superProperties];
}
- (NSDictionary *)currentSuperProperties {
if (self.superProperties) {
return [TAPropertyValidator validateProperties:[self.superProperties copy]];
} else {
return @{};
}
}
- (void)registerDynamicSuperProperties:(NSDictionary<NSString *, id> *(^ _Nullable)(void))dynamicSuperProperties {
@synchronized (self) {
self.dynamicSuperProperties = dynamicSuperProperties;
}
}
- (NSDictionary *)obtainDynamicSuperProperties {
@synchronized (self) {
if (self.dynamicSuperProperties) {
NSDictionary *properties = self.dynamicSuperProperties();
NSDictionary *validProperties = [TAPropertyValidator validateProperties:[properties copy]];
return validProperties;
}
return nil;
}
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 0d28f334c0ccb354295c108bd6fced89
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4a20a7aa750a48b4f90277c818ca6fa7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
//
// NSArray+TAProperty.h
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import <Foundation/Foundation.h>
#import "TAValidatorProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface NSArray (TAProperty) <TAPropertyValueValidating>
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: ec613b013ff5aef4e8aa28eaaaedac1c
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
//
// NSArray+TAProperty.m
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import "NSArray+TAProperty.h"
@implementation NSArray (TAProperty)
- (void)ta_validatePropertyValueWithError:(NSError *__autoreleasing _Nullable *)error {
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 906fcbde20a55d942bbf71335d6e503a
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
//
// NSDate+TAProperty.h
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import <Foundation/Foundation.h>
#import "TAValidatorProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface NSDate (TAProperty) <TAPropertyValueValidating>
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 7815960cdb2892d43a211eabfeb5e693
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
//
// NSDate+TAProperty.m
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import "NSDate+TAProperty.h"
@implementation NSDate (TAProperty)
- (void)ta_validatePropertyValueWithError:(NSError *__autoreleasing _Nullable *)error {
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 369f72e6c8b3cd443a39b34386a7c4b2
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
//
// NSDictionary+TAProperty.h
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import <Foundation/Foundation.h>
#import "TAValidatorProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface NSDictionary (TAProperty) <TAPropertyValueValidating>
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 7670f9711b4d48b4e992d002f831e032
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
//
// NSDictionary+TAProperty.m
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import "NSDictionary+TAProperty.h"
@implementation NSDictionary (TAProperty)
- (void)ta_validatePropertyValueWithError:(NSError *__autoreleasing _Nullable *)error {
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: a0f6b32af78b7e74aa6e07ce63484fff
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
//
// NSNumber+TAProperty.h
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import <Foundation/Foundation.h>
#import "TAValidatorProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface NSNumber (TAProperty) <TAPropertyValueValidating>
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: b2891f0078a828f4fbd278fe48bc60bf
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
//
// NSNumber+TAProperty.m
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import "NSNumber+TAProperty.h"
@implementation NSNumber (TAProperty)
- (void)ta_validatePropertyValueWithError:(NSError *__autoreleasing _Nullable *)error {
if ([self doubleValue] > 9999999999999.999 || [self doubleValue] < -9999999999999.999) {
NSString *errorMsg = [NSString stringWithFormat:@"The number value [%@] is invalid.", self];
TDLogError(errorMsg);
*error = TAPropertyError(10009, errorMsg);
}
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 37a2d705dc4fb714d8748c79e8c13bf9
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
//
// NSString+TAProperty.h
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import <Foundation/Foundation.h>
#import "TAValidatorProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface NSString (TAProperty) <TAPropertyKeyValidating, TAPropertyValueValidating>
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: c5c6c8921f5d1304f8cd9de8249dff8a
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
//
// NSString+TAProperty.m
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import "NSString+TAProperty.h"
static NSInteger kTAPropertyNameMaxLength = 50;
@implementation NSString (TAProperty)
- (void)ta_validatePropertyKeyWithError:(NSError *__autoreleasing _Nullable *)error {
if (self.length == 0) {
NSString *errorMsg = @"Property key or Event name is empty";
TDLogError(errorMsg);
*error = TAPropertyError(10003, errorMsg);
return;
}
if (self.length > kTAPropertyNameMaxLength) {
NSString *errorMsg = [NSString stringWithFormat:@"Property key or Event name %@'s length is longer than %ld", self, kTAPropertyNameMaxLength];
TDLogError(errorMsg);
*error = TAPropertyError(10006, errorMsg);
return;
}
*error = nil;
}
- (void)ta_validatePropertyValueWithError:(NSError *__autoreleasing _Nullable *)error {
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 04eda97ca3c873b43934892ac240713b
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
//
// TAPropertyDefaultValidator.h
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import <Foundation/Foundation.h>
#import "TAValidatorProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface TAPropertyDefaultValidator : NSObject <TAEventPropertyValidating>
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: b8c942cce0a6c0c41956903b4a222783
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
//
// TAPropertyDefaultValidator.m
// Adjust
//
// Created by Yangxiongon 2022/7/1.
//
#import "TAPropertyDefaultValidator.h"
#import "TAPropertyValidator.h"
@implementation TAPropertyDefaultValidator
- (void)ta_validateKey:(NSString *)key value:(id)value error:(NSError *__autoreleasing _Nullable *)error {
[TAPropertyValidator validateBaseEventPropertyKey:key value:value error:error];
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 29d0ba676609b7b498d181a120c8957a
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
//
// TAPropertyValidator.h
// Adjust
//
// Created by Yangxiongon 2022/6/10.
//
#import <Foundation/Foundation.h>
#import "TAValidatorProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface TAPropertyValidator : NSObject
+ (void)validateEventOrPropertyName:(NSString *)name withError:(NSError **)error;
+ (void)validateBaseEventPropertyKey:(NSString *)key value:(NSString *)value error:(NSError **)error;
+ (void)validateNormalTrackEventPropertyKey:(NSString *)key value:(NSString *)value error:(NSError **)error;
+ (void)validateAutoTrackEventPropertyKey:(NSString *)key value:(NSString *)value error:(NSError **)error;
+ (NSMutableDictionary *)validateProperties:(NSDictionary *)properties;
+ (NSMutableDictionary *)validateProperties:(NSDictionary *)properties validator:(id<TAEventPropertyValidating>)validator;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 5c9bdd8243e62ab469ee2435b4905767
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,133 @@
//
// TAPropertyValidator.m
// Adjust
//
// Created by Yangxiongon 2022/6/10.
//
#import "TAPropertyValidator.h"
#import "NSString+TAProperty.h"
#import "TAPropertyDefaultValidator.h"
@implementation TAPropertyValidator
/// Custom attribute name format validation
static NSString *const kTANormalTrackProperNameValidateRegularExpression = @"^[a-zA-Z][a-zA-Z\\d_]*$";
/// Custom attribute name regularization
static NSRegularExpression *_regexForNormalTrackValidateKey;
/// Automatic collection, custom attribute name format validation. All automatic collection of custom attributes needs to meet the following rules
static NSString *const kTAAutoTrackProperNameValidateRegularExpression = @"^([a-zA-Z][a-zA-Z\\d_]{0,49}|\\#(resume_from_background|app_crashed_reason|screen_name|referrer|title|url|element_id|element_type|element_content|element_position|background_duration|start_reason))$";
static NSRegularExpression *_regexForAutoTrackValidateKey;
+ (void)validateEventOrPropertyName:(NSString *)name withError:(NSError *__autoreleasing _Nullable *)error {
if (!name) {
NSString *errorMsg = @"Property key or Event name is empty";
TDLogError(errorMsg);
*error = TAPropertyError(10003, errorMsg);
return;
}
if (![name isKindOfClass:NSString.class]) {
NSString *errorMsg = [NSString stringWithFormat:@"Property key or Event name is not NSString: [%@]", name];
TDLogError(errorMsg);
*error = TAPropertyError(10007, errorMsg);
return;
}
[name ta_validatePropertyKeyWithError:error];
}
+ (void)validateBaseEventPropertyKey:(NSString *)key value:(NSString *)value error:(NSError **)error {
if (![key conformsToProtocol:@protocol(TAPropertyKeyValidating)]) {
NSString *errMsg = [NSString stringWithFormat:@"The property KEY must be NSString. got: %@ %@", [key class], key];
TDLogError(errMsg);
*error = TAPropertyError(10001, errMsg);
return;
}
[(id <TAPropertyKeyValidating>)key ta_validatePropertyKeyWithError:error];
if (*error) {
return;
}
if (![value conformsToProtocol:@protocol(TAPropertyValueValidating)]) {
NSString *errMsg = [NSString stringWithFormat:@"Property value must be type NSString, NSNumber, NSDate, NSDictionary or NSArray. got: %@ %@. ", [value class], value];
TDLogError(errMsg);
*error = TAPropertyError(10002, errMsg);
return;
}
[(id <TAPropertyValueValidating>)value ta_validatePropertyValueWithError:error];
}
+ (void)validateNormalTrackEventPropertyKey:(NSString *)key value:(NSString *)value error:(NSError **)error {
[self validateBaseEventPropertyKey:key value:value error:error];
if (*error) {
return;
}
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_regexForNormalTrackValidateKey = [NSRegularExpression regularExpressionWithPattern:kTANormalTrackProperNameValidateRegularExpression options:NSRegularExpressionCaseInsensitive error:nil];
});
if (!_regexForNormalTrackValidateKey) {
NSString *errorMsg = @"Property Key validate regular expression init failed";
TDLogError(errorMsg);
*error = TAPropertyError(10004, errorMsg);
return;
}
NSRange range = NSMakeRange(0, key.length);
if ([_regexForNormalTrackValidateKey numberOfMatchesInString:key options:0 range:range] < 1) {
NSString *errorMsg = [NSString stringWithFormat:@"Property Key or Event name: [%@] is invalid.", key];
TDLogError(errorMsg);
*error = TAPropertyError(10005, errorMsg);
return;
}
}
+ (void)validateAutoTrackEventPropertyKey:(NSString *)key value:(NSString *)value error:(NSError **)error {
[self validateBaseEventPropertyKey:key value:value error:error];
if (*error) {
return;
}
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_regexForAutoTrackValidateKey = [NSRegularExpression regularExpressionWithPattern:kTAAutoTrackProperNameValidateRegularExpression options:NSRegularExpressionCaseInsensitive error:nil];
});
if (!_regexForAutoTrackValidateKey) {
NSString *errorMsg = @"Property Key validate regular expression init failed";
TDLogError(errorMsg);
*error = TAPropertyError(10004, errorMsg);
return;
}
NSRange range = NSMakeRange(0, key.length);
if ([_regexForAutoTrackValidateKey numberOfMatchesInString:key options:0 range:range] < 1) {
NSString *errorMsg = [NSString stringWithFormat:@"Property Key or Event name: [%@] is invalid.", key];
TDLogError(errorMsg);
*error = TAPropertyError(10005, errorMsg);
return;
}
}
+ (NSMutableDictionary *)validateProperties:(NSDictionary *)properties {
return [self validateProperties:properties validator:[[TAPropertyDefaultValidator alloc] init]];
}
+ (NSMutableDictionary *)validateProperties:(NSDictionary *)properties validator:(id<TAEventPropertyValidating>)validator {
if (![properties isKindOfClass:[NSDictionary class]] || ![validator conformsToProtocol:@protocol(TAEventPropertyValidating)]) {
return nil;
}
for (id key in properties) {
NSError *error = nil;
id value = properties[key];
[validator ta_validateKey:key value:value error:&error];
}
return [properties copy];
}
@end

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: d497f9e3d392f73459dff3cfde70eb64
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,45 @@
//
// TAValidatorProtocol.h
// ThinkingSDK
//
// Created by Yangxiongon 2022/7/1.
//
#ifndef TAValidatorProtocol_h
#define TAValidatorProtocol_h
#import <Foundation/Foundation.h>
#if __has_include(<ThinkingSDK/TDLogging.h>)
#import <ThinkingSDK/TDLogging.h>
#else
#import "TDLogging.h"
#endif
#define TAPropertyError(errorCode, errorMsg) \
[NSError errorWithDomain:@"ThinkingAnalyticsErrorDomain" \
code:errorCode \
userInfo:@{NSLocalizedDescriptionKey:errorMsg}] \
@protocol TAPropertyKeyValidating <NSObject>
- (void)ta_validatePropertyKeyWithError:(NSError **)error;
@end
/// The validator protocol of the attribute value, used to verify the attribute value
@protocol TAPropertyValueValidating <NSObject>
- (void)ta_validatePropertyValueWithError:(NSError **)error;
@end
/// The validator protocol of event properties, used to verify the key-value of a certain property
@protocol TAEventPropertyValidating <NSObject>
- (void)ta_validateKey:(NSString *)key value:(id)value error:(NSError **)error;
@end
#endif /* TAValidatorProtocol_h */

View File

@@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 76f89a638c88fa14185e509e0802c8db
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings:
AddToEmbeddedBinaries: false
userData:
assetBundleName:
assetBundleVariant: