-
Notifications
You must be signed in to change notification settings - Fork 195
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
Relay IDFA information through consent plugin #906
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { IdfaPlugin } from '@segment/analytics-react-native-plugin-idfa'; | ||
import { createTestClient } from '../../../test-helpers'; | ||
import { ConsentPlugin } from '../../ConsentPlugin'; | ||
import { createConsentProvider } from './utils'; | ||
import noUnmappedDestinations from './mockSettings/NoUnmappedDestinations.json'; | ||
import type { Context, ContextDevice } from '@segment/analytics-react-native'; | ||
|
||
let mockIdfaValue = { | ||
adTrackingEnabled: false, | ||
advertisingId: 'trackMeId', | ||
trackingStatus: 'denied', | ||
}; | ||
|
||
jest.mock( | ||
'@segment/analytics-react-native-plugin-idfa/lib/commonjs/AnalyticsReactNativePluginIdfa', | ||
() => ({ | ||
AnalyticsReactNativePluginIdfa: { | ||
getTrackingAuthorizationStatus: async () => { | ||
return Promise.resolve(mockIdfaValue); | ||
}, | ||
}, | ||
}) | ||
); | ||
|
||
describe('IDFA x Consent', () => { | ||
it('triggers consent update event on IDFA change and includes IDFA data', async () => { | ||
const { client, expectEvent } = createTestClient( | ||
{ | ||
settings: noUnmappedDestinations.integrations, | ||
consentSettings: noUnmappedDestinations.consentSettings, | ||
}, | ||
{ autoAddSegmentDestination: true } | ||
); | ||
|
||
const mockConsentStatuses = { | ||
C0001: false, | ||
C0002: false, | ||
C0003: false, | ||
C0004: false, | ||
C0005: false, | ||
}; | ||
|
||
client.add({ | ||
plugin: new ConsentPlugin( | ||
createConsentProvider(mockConsentStatuses), | ||
Object.keys(mockConsentStatuses) | ||
), | ||
}); | ||
|
||
const idfaPlugin = new IdfaPlugin(false); | ||
client.add({ | ||
plugin: idfaPlugin, | ||
}); | ||
|
||
await client.init(); | ||
|
||
await idfaPlugin.requestTrackingPermission(); | ||
|
||
await new Promise((r) => setTimeout(r, 1000)); | ||
|
||
expectEvent({ | ||
event: 'Segment Consent Preference', | ||
context: expect.objectContaining({ | ||
device: expect.objectContaining({ | ||
adTrackingEnabled: false, | ||
advertisingId: 'trackMeId', | ||
trackingStatus: 'denied', | ||
}) as unknown as ContextDevice, | ||
}) as unknown as Context, | ||
}); | ||
|
||
// update IDFA data | ||
|
||
mockIdfaValue = { | ||
adTrackingEnabled: true, | ||
advertisingId: 'trackMeId', | ||
trackingStatus: 'authorized', | ||
}; | ||
|
||
await idfaPlugin.requestTrackingPermission(); | ||
|
||
await new Promise((r) => setTimeout(r, 1000)); | ||
|
||
expectEvent({ | ||
event: 'Segment Consent Preference', | ||
context: expect.objectContaining({ | ||
device: expect.objectContaining({ | ||
adTrackingEnabled: true, | ||
advertisingId: 'trackMeId', | ||
trackingStatus: 'authorized', | ||
}) as unknown as ContextDevice, | ||
}) as unknown as Context, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why not check the specific values inside
context.device
? (e.g. AdTrackingEnabled, AdvertisingId)device
context contains a lot more values than ATT so those might change and trigger a notifyConsentChange without necessarily being an ad tracking related thingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, that was how my original implementation worked but I feared that in case more metadata becomes subject of IDFA, we might forget to also update this plugin as well.
Most fields in
device
are static and very unlikely to updated during the runtime of the app.wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to constraint it to the specific fields.
It's more likely that we extend
context
with something not IDFA related and might be harder to spot that this has a side effect if it's not directly named. We also have to take into account that plugins can modify the context same as IDFA/AdvertisingID so we cannot control for what other devs are doing.