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

IDFA isn't updated properly #900

Closed
buuuudzik opened this issue Nov 30, 2023 · 12 comments · Fixed by #925
Closed

IDFA isn't updated properly #900

buuuudzik opened this issue Nov 30, 2023 · 12 comments · Fixed by #925
Labels
bug Something isn't working 🚧 Work In Progress

Comments

@buuuudzik
Copy link

buuuudzik commented Nov 30, 2023

We're using Segment and IdfaPlugin in our project. And recently I've found that IDFA isn't properly updated.

I'm using a default behaviour of this plugin in such a way:

const client = createClient({
    writeKey,
    trackAppLifecycleEvents: true,
    trackDeepLinks: true,
    collectDeviceId: true,
    flushInterval: 5,
    maxBatchSize: 15,
  });

client.add({ plugin: new IdfaPlugin() });

which means that shouldAskPermission is set to true and this.getTrackingStatus() from the constructor will be triggered immediately and this.analytics is undefined so context won't be updated even if the value has been received from the OS:
this.analytics?.context.set({ device: { ...idfa } });

I've found that it works with such a patch:

const idfaPlugin = new IdfaPlugin();
  if (!idfaPlugin.analytics) {
    idfaPlugin.analytics = client;
  }
  client.add({ plugin: idfaPlugin });

Questions:

  1. Are you aware about it?
  2. Can you add also updating the IDFA in Segment context after returning from background (because the user could minimise the app and go to the Settings and disable "Allow tracking" for this specific app and return to the app).
  • analytics-react-native version:
    "@segment/analytics-react-native": "2.15.0",
    "@segment/analytics-react-native-plugin-idfa": "^0.6.2",

  • Integrations versions (if used):
    "@segment/analytics-react-native-plugin-appsflyer": "0.5.2",

  • React Native version:
    "react-native": "0.70.13",

  • iOS
    17 and older

Steps to reproduce
Allow and cancel tracking permission

Expected behavior
IDFA should be added to the events only if the user allowed for tracking and not cancelled this permission. IdfaPlugin should properly update Segment context in every scenarios.

Actual behavior
IDFA is not updated properly. When I've had an application with permission granted in the past and then I've cancelled this permission even after fully closing and reopening the app further events still included IDFA.

I've found that this.analytics in this.getTrackingStatus() can be undefined.
image

@buuuudzik buuuudzik added the bug Something isn't working label Nov 30, 2023
@oscb
Copy link
Contributor

oscb commented Dec 4, 2023

@buuuudzik thanks for this report! You're 100% in the right here, analytics shouldn't be called in the constructor, this should be more similar to the AdvertisingID.

I also like the suggestion to check on Background -> Foreground. We'll add that too as part of this fix.

@buuuudzik
Copy link
Author

Thanks @oscb I really appreciate your quick response 👏

@buuuudzik
Copy link
Author

@oscb What is the status of this issue? We need to fix it ASAP.

@oscb
Copy link
Contributor

oscb commented Feb 26, 2024

@buuuudzik The fix is released now in v0.7.1

@buuuudzik
Copy link
Author

@oscb Great news! Big THANKS!

@buuuudzik
Copy link
Author

buuuudzik commented Feb 27, 2024

@oscb I've just checked this version and unfortunately nothing changed. Should I upgrade also Segment to make it works?

@buuuudzik
Copy link
Author

@oscb I've upgraded Segment to 2.19.0 and it also didn't help.

@buuuudzik
Copy link
Author

I'm creating a segment client in such a way:

const client = createClient({
    writeKey,
    trackAppLifecycleEvents: true,
    trackDeepLinks: true,
    collectDeviceId: true,
    flushInterval: 5,
    maxBatchSize: 15, // 15 x 32kB = 480kB so it's under the batch size limit of 500kb
    // Link to docs about size limits: https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#batch
  });

  client.add({ plugin: new IdfaPlugin() });

@buuuudzik
Copy link
Author

This patch can fix the issue (but it won't detect the change after a device will go background and then foreground):

  const client = createClient({
    writeKey,
    trackAppLifecycleEvents: true,
    trackDeepLinks: true,
    collectDeviceId: true,
    flushInterval: 5,
    maxBatchSize: 15, // 15 x 32kB = 480kB so it's under the batch size limit of 500kb
    // Link to docs about size limits: https://segment.com/docs/connections/sources/catalog/libraries/server/http-api/#batch
  });

  const idfaPlugin = new IdfaPlugin();
  if (!idfaPlugin.analytics) {
    idfaPlugin.analytics = client;
  }
  client.add({ plugin: idfaPlugin });

@oscb oscb linked a pull request Feb 28, 2024 that will close this issue
@oscb
Copy link
Contributor

oscb commented Feb 28, 2024

@buuuudzik my bad, I was mixing this with another IDFA fix we merged recently. Just fixed the problem in this PR will merge and release as soon as it passes tests.

@oscb oscb closed this as completed in #925 Feb 28, 2024
@oscb
Copy link
Contributor

oscb commented Feb 28, 2024

@buuuudzik 0.7.2 should have the fix, let us know if it doesn't work

@buuuudzik
Copy link
Author

@oscb It works! Great work! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🚧 Work In Progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants