la-haus / flutter-segment

Segment.io library for flutter
MIT License
22 stars 141 forks source link

Request: Ad Tracking and IDFA Docs? #53

Open b099l3 opened 2 years ago

b099l3 commented 2 years ago

I see this package is using analytics-ios 4.1.6

When trying to set up Ad Tracking and IDFA I noticed the official docs has some setup steps with analytics-ios 4.1 or greater:

Starting iOS 14, applications must prompt users if that app needs to collect their Identifier for Advertisers (IDFA). Going forward with analytics-ios-4.1 and later, Segment doesn’t auto-collect IDFA. If your app or any integrations require the use of IDFA, you need to:

  1. import the AdSupport and App Tracking Transparency Frameworks by Apple
  2. pass the below code snippet to Segment config and start tracking events
  3. prompt the user for consent and collect the IDFA You can use the following closure snippet to pass the value to analytics-ios as configurations:
    
    @import AdSupport;

...

SEGAnalyticsConfiguration* configuration = [SEGAnalyticsConfiguration configurationWithWriteKey:@"YOUR_WRITE_KEY"]; // Enable advertising collection configuration.enableAdvertisingTracking = YES; // Set the block to be called when the advertisingID is needed // NOTE: In iOS 14, you'll need to manually do authorization elsewhere and only when it has been authorized, return the advertisingIdentifier to segment via the block below configuration.adSupportBlock = ^{ return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; }; [SEGAnalytics setupWithConfiguration:configuration];


Or the option of setting two keys under the context object:
> Ad-tracking affects two keys under the `context` object of every event:
> device.adTrackingEnabled | true if SDK is setup with closure and user has consented, false otherwise
> -- | --
> device.advertisingId | idfa_value if user opts-in otherwise this key is skipped from event payload

---

I did this using the second option of adding to the `context` object, with the IDFA which I got from using this [package](https://github.com/deniza/app_tracking_transparency):
```dart
final advertisingId = await getAdvertisingId();
final adTrackingEnabled = await getadTrackingEnabled();

Segment.setContext({
  'device': {
    'adTrackingEnabled': adTrackingEnabled.toString(),
    'advertisingId': advertisingId,
  }
});

I wonder if we should add some docs for setting up Ad Tracking and IDFA on iOS? I can do it just want to make sure this is something we want on this repo?

danielgomezrico commented 2 years ago

Hi @b099l3

Thanks for opening the issue, If that feature is already working and you found a way to do it feel free to add docs for it :) sure!

brunapcat commented 2 years ago

Hello,

Are there any updates abot setting up Ad Tracking and IDFA on iOS?