Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shift responsibility of IDFA collection to clients #5

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PostHog/Classes/Internal/PHGPostHogIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ - (NSDictionary *)staticContext
if (NSClassFromString(PHGAdvertisingClassIdentifier)) {
dict[@"$device_adCapturingEnabled"] = @(GetAdCapturingEnabled());
}
if (self.configuration.enableAdvertisingCapturing) {
NSString *idfa = PHGIDFA();
if (self.configuration.enableAdvertisingCapturing && self.configuration.adSupportBlock != nil) {
NSString *idfa = self.configuration.adSupportBlock();
if (idfa.length) dict[@"$device_advertisingId"] = idfa;
}

Expand Down
2 changes: 0 additions & 2 deletions PostHog/Classes/Internal/PHGPostHogUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ void PHGLog(NSString *format, ...);

JSON_DICT PHGCoerceDictionary(NSDictionary *_Nullable dict);

NSString *_Nullable PHGIDFA(void);

NSString *PHGEventNameForScreenTitle(NSString *title);

// Deep copy and check NSCoding conformance
Expand Down
22 changes: 0 additions & 22 deletions PostHog/Classes/Internal/PHGPostHogUtils.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#import "PHGPostHogUtils.h"
#import <AdSupport/ASIdentifierManager.h>

static BOOL kPostHogLoggerShowLogs = NO;

Expand Down Expand Up @@ -164,27 +163,6 @@ static id PHGCoerceJSONObject(id obj)
return PHGCoerceJSONObject(dict);
}

NSString *PHGIDFA()
{
NSString *idForAdvertiser = nil;
Class identifierManager = NSClassFromString(@"ASIdentifierManager");
if (identifierManager) {
SEL sharedManagerSelector = NSSelectorFromString(@"sharedManager");
id sharedManager =
((id (*)(id, SEL))
[identifierManager methodForSelector:sharedManagerSelector])(
identifierManager, sharedManagerSelector);
SEL advertisingIdentifierSelector =
NSSelectorFromString(@"advertisingIdentifier");
NSUUID *uuid =
((NSUUID * (*)(id, SEL))
[sharedManager methodForSelector:advertisingIdentifierSelector])(
sharedManager, advertisingIdentifierSelector);
idForAdvertiser = [uuid UUIDString];
}
return idForAdvertiser;
}

NSString *PHGEventNameForScreenTitle(NSString *title)
{
return [[NSString alloc] initWithFormat:@"Viewed %@ Screen", title];
Expand Down
12 changes: 12 additions & 0 deletions PostHog/Classes/PHGPostHogConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ typedef NSMutableURLRequest *_Nonnull (^PHGRequestFactory)(NSURL *_Nonnull);
*/
@property (nonatomic, assign) BOOL enableAdvertisingCapturing;

/**
* Sets a block to be called when IDFA / AdSupport identifier is created.
* This is to allow for apps that do not want ad tracking to pass App Store guidelines in certain categories while
* still allowing apps that do ad tracking to continue to function.
*
* Example:
* configuration.adSupportBlock = ^{
* return [[ASIdentifierManager sharedManager] advertisingIdentifier];
* }
*/
@property (nonatomic, copy, nullable) NSString * _Nonnull (^adSupportBlock)(void);

/**
* The number of queued events that the posthog client should flush at. Setting this to `1` will not queue any events and will use more battery. `20` by default.
*/
Expand Down
1 change: 1 addition & 0 deletions PostHog/Classes/PHGPostHogConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ - (instancetype)init
if (self = [super init]) {
self.shouldUseLocationServices = NO;
self.enableAdvertisingCapturing = YES;
self.adSupportBlock = nil;
self.shouldUseBluetooth = NO;
self.flushAt = 20;
self.flushInterval = 30;
Expand Down
2 changes: 2 additions & 0 deletions PostHogTests/PostHogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PostHogTests: QuickSpec {
expect(posthog.configuration.host) == URL(string: "https://app.posthog.com")
expect(posthog.configuration.shouldUseLocationServices) == false
expect(posthog.configuration.enableAdvertisingCapturing) == true
expect(posthog.configuration.adSupportBlock).to(beNil())
expect(posthog.configuration.shouldUseBluetooth) == false
expect(posthog.configuration.libraryName) == "posthog-ios"
expect(posthog.configuration.libraryVersion) == PHGPostHog.version()
Expand All @@ -54,6 +55,7 @@ class PostHogTests: QuickSpec {
expect(posthog.configuration.host) == URL(string: "https://testapp.posthog.test")
expect(posthog.configuration.shouldUseLocationServices) == false
expect(posthog.configuration.enableAdvertisingCapturing) == true
expect(posthog.configuration.adSupportBlock).to(beNil())
expect(posthog.configuration.shouldUseBluetooth) == false
expect(posthog.configuration.libraryVersion) == "posthog-ios-version"
expect(posthog.configuration.libraryName) == "posthog-ios-test"
Expand Down