From b26f22f0fceb6d9e2ef558a1cf5dda170f330438 Mon Sep 17 00:00:00 2001 From: Brandon Sneed Date: Wed, 27 Jan 2021 12:25:34 -0800 Subject: [PATCH] Pull IDFA if it has changed and rebuild context if necessary. --- Segment/Classes/SEGAnalytics.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Segment/Classes/SEGAnalytics.m b/Segment/Classes/SEGAnalytics.m index d1881796b..35f6663ab 100644 --- a/Segment/Classes/SEGAnalytics.m +++ b/Segment/Classes/SEGAnalytics.m @@ -27,6 +27,7 @@ @interface SEGAnalytics () @property (nonatomic, strong) SEGStoreKitTracker *storeKitTracker; @property (nonatomic, strong) SEGIntegrationsManager *integrationsManager; @property (nonatomic, strong) SEGMiddlewareRunner *runner; +@property (nonatomic, strong) NSString *lastIDFA; @end @@ -47,6 +48,7 @@ - (instancetype)initWithConfiguration:(SEGAnalyticsConfiguration *)configuration if (self = [self init]) { self.oneTimeConfiguration = configuration; self.enabled = YES; + self.lastIDFA = nil; // In swift this would not have been OK... But hey.. It's objc // TODO: Figure out if this is really the best way to do things here. @@ -556,6 +558,16 @@ - (void)run:(SEGEventType)eventType payload:(SEGPayload *)payload return; } + if (getAdTrackingEnabled(self.oneTimeConfiguration)) { + // if idfa has changed since last we looked, we need to rebuild + // the static context to pick up the change. + NSString *idfa = self.oneTimeConfiguration.adSupportBlock(); + if (![idfa isEqualToString:self.lastIDFA]) { + self.lastIDFA = idfa; + [[SEGState sharedInstance].context updateStaticContext]; + } + } + if (self.oneTimeConfiguration.experimental.nanosecondTimestamps) { payload.timestamp = iso8601NanoFormattedString([NSDate date]); } else {