la-haus / flutter-segment

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

App installed event tracking problem for iOS #26

Closed Mik77o closed 1 year ago

Mik77o commented 2 years ago

I have noticed a problem with app installed event not being tracked for iOS. I am using version 3.7.0. In the Segment configuration Segment.config I have trackApplicationLifecycleEvents set: true, but this event does not seem to work.

danielgomezrico commented 2 years ago

Are you talking about Application Installed event?

https://segment.com/docs/connections/spec/mobile/#application-installed

Mik77o commented 2 years ago

Yes :)

Mik77o commented 2 years ago

On Android, this type of event is tracked. Maybe it's related to this: https://developer.apple.com/app-store/user-privacy-and-data-use/ Asking permissions to track

What do you think?

Mik77o commented 2 years ago

@danielgomezrico, I tried to add tracking permissions via app_tracking_transparency but still this event is not being tracked in the Segment.

ariefwijaya commented 2 years ago

I don't think so, It is not because this event is not being tracked in the Segment , the event tracked by segment already, you can test it. I've tested it. Untitled-1

As you can see, it was happened because in the default event like "Application Installed" never send fields adTrackingEnabled and advertisingId. Refer to docs :

image
danielgomezrico commented 2 years ago

I checked too for iOS and the events exists 🤔

What else could be missing on your setup?

ariefwijaya commented 2 years ago

@danielgomezrico Yes, the event exists, I think the problem is about IDFA. in some case such as facebook, the event will not received without IDFA

Mik77o commented 2 years ago

@ariefwijaya, could you please include a snippet of code, what should the configuration look like in the Segment for Flutter app when using the advertising_id and flutter_segment plugin? :)

ariefwijaya commented 2 years ago

I prefer use facebook_app_events together with flutter_segment, so it will solve the problem without many boilerplate

Mik77o commented 2 years ago

@ariefwijaya @danielgomezrico How was advertisingId added manually? I added something like this on the Flutter side.

     SegmentDefaultOptions.instance.options = {
          'context': {
            'device': {
              'adTrackingEnabled': true,
              'advertisingId': advertisingId,
            }
          }
        };

Some of the fields for device field that were visible before are no longer present. It looks like the device part has been overwritten. Only the type: ios left.

From Segment:

before my changes

    "device": {
      "id": "test",
      "manufacturer": "test",
      "model": "test',
      "name": "test",
      "type": "ios"
    },

now (Adding a configuration manually)

    "device": {
      "adTrackingEnabled": true,
      "advertisingId": "00000000-0000-0000-0000-000000000000",
      "type": "ios"
    },
ariefwijaya commented 2 years ago

Yes, but it won't delete any other value except the one we want to overwrite, So, it must be

 "device": {
      "id": "test",
      "manufacturer": "test",
      "model": "test',
      "name": "test",
       "adTrackingEnabled": true,
      "advertisingId": "00000000-0000-0000-0000-000000000000",
      "type": "ios"
    },

btw , I mix it with facebook_app_event plugin to track default event such as App Install

zenled commented 2 years ago

Hey, I'm experiencing the same problem. On Android, it all works as expected. On iOS, the Application Installed event is not being triggered. (I have set trackApplicationLifecycleEvents totrue) The problem is probably in the way Segment is being configured:

If I configure Segment using Dart, by calling Segment.config(options: SegmentConfig(... then the Application Installed event will not get triggered.

But If I configure Segment the deprecated way, by modifying the Info.plist then the Application Installed event will get triggered as expected.

In the Segment documentation is says to configure Segment in the application:didFinishLaunchingWithOptions, this is the case when configuring via the Info.plist, but not when configuring with Dart.

Mik77o commented 2 years ago

@danielgomezrico @ariefwijaya I have a problem with advertisingId and adTrackingEnabled fields in Segment for release mode (Android). It doesn't appear :/

I get the advertisingId from the advertising_id package.

ariefwijaya commented 2 years ago

@Mik77o for advertising id, this is how use it along flutter_segment.

image

you can use .setContext method to put any key-value pair under spesific preserved key. it won't delete any other value except the one we want to overwrite,

ariefwijaya commented 2 years ago

...

In the Segment documentation is says to configure Segment in the application:didFinishLaunchingWithOptions, this is the case when configuring via the Info.plist, but not when configuring with Dart.

@danielgomezrico this happened to me, I found it never track Application Installed in iOS for our Dart-Installation. I've tried but now I have no idea to fix it,

minoesteban commented 2 years ago

We are facing the same issue... after upgrading the package to 3.9.0 and removing the Info.plist keys not only we stopped getting Application Installed events but we are also not getting as many Application Opened events as we should.

We are getting Application Backgrounded correctly though.

So most times we get 4/5 Application Backgrounded events in a row from the same device, and not once we get Application Opened

By making the Dart config call conditional to all but iOS platform and adding back the Info.plist keys, we started getting the correct events frequency on iOS

Unfortunately I'm not proficient enough in iOS dev to figure out where is the issue, so I cannot offer any more assistance - I only got to conclude that createConfigFromFile and createConfigFromDict methods in FlutterSegmentPlugin.m look too similar to suspect an issue there 😅

Mik77o commented 2 years ago

@minoesteban I think that Application Updated event is also not tracked. (for iOS)

danielgomezrico commented 2 years ago

🤔 Its weird, I can see those events for iOS and android on our side, anyone has any clue?

zenled commented 2 years ago

@danielgomezrico Can you confirm you are configuring Segment via Dart and not via Info.plist.

b099l3 commented 2 years ago

Hey, I'm experiencing the same problem. On Android, it all works as expected. On iOS, the Application Installed event is not being triggered. (I have set trackApplicationLifecycleEvents totrue) The problem is probably in the way Segment is being configured:

If I configure Segment using Dart, by calling Segment.config(options: SegmentConfig(... then the Application Installed event will not get triggered.

But If I configure Segment the deprecated way, by modifying the Info.plist then the Application Installed event will get triggered as expected.

In the Segment documentation is says to configure Segment in the application:didFinishLaunchingWithOptions, this is the case when configuring via the Info.plist, but not when configuring with Dart.

This looks like it is a method sequence issue with when the dart method Segment.config() is called:

Method flow for App start with flutter-segment:

  1. AppDelegate didFinishLaunchingWithOptions:
  2. GeneratedPluginRegistrant registerWithRegistry:
  3. This is were the info.plist setup is called via createConfigFromFile and eventually SEGAnalytics setupWithConfiguration SEE SEGAnalytics setupWithConfiguration method flow BELOW
  4. Then AppDelegate calls super didFinishLaunchingWithOptions:

For the dart Implementation calling Segment.config():

  1. Calls SEGAnalytics setupWithConfiguration in the native library, SEE SEGAnalytics setupWithConfiguration method flow BELOW

SEGAnalytics setupWithConfiguration method flow

  1. Setups up listeners to the native lifecycle events
  2. Then when didFinishLaunchingWithOptions is called sends the Application Installed event

So if you call Segment.config() after AppDelegate didFinishLaunchingWithOptions: you will miss the first event. The setup instructions state that this needs to be done in a lifecycle event, e.g., didFinishLaunchingWithOptions

I wonder if there is away to call Segment.config() in didFinishLaunchingWithOptions?

b099l3 commented 2 years ago

I created a potential fix, #56, that manually sends the event Application Installed and Application Updated when we call the dart code Segment.config().

This is in the native iOS code of flutter_segement so will only run on iOS. It works in the same way that the native segment package works, analysis-ios, checks the same NSUserDefaults, the implementation details of that method is here.

Tested and is sending the events now.

savy-91 commented 2 years ago

Maybe this can be closed @danielgomezrico ?

danielgomezrico commented 2 years ago

@Mik77o has updated to the latest version? This should be fixed after https://github.com/la-haus/flutter-segment/pull/56

Mik77o commented 2 years ago

@danielgomezrico Thanks for reminder. I will check it soon :)

danielgomezrico commented 1 year ago

@Mik77o any updates? 🤓

Mik77o commented 1 year ago

@danielgomezrico Seems to be working now! :)

danielgomezrico commented 1 year ago

You are welcome to reopen if it breaks again