Skip to content

Commit d7cec12

Browse files
committed
Revert "Track appleAdsAttribution to reporting and firstOpenInfo cache"
This reverts commit a9c0c24.
1 parent b036210 commit d7cec12

File tree

2 files changed

+7
-102
lines changed

2 files changed

+7
-102
lines changed

src/actions/FirstOpenActions.tsx

Lines changed: 6 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
1-
import { getAttributionToken } from '@brigad/react-native-adservices'
21
import { asNumber, asObject, asOptional, asString, asValue } from 'cleaners'
32
import { makeReactNativeDisklet } from 'disklet'
4-
import { Platform } from 'react-native'
53

64
import { FIRST_OPEN } from '../constants/constantSettings'
75
import { makeUuid } from '../util/rnUtils'
8-
import { snooze } from '../util/utils'
96
import { getCountryCodeByIp } from './AccountReferralActions'
107

118
export const firstOpenDisklet = makeReactNativeDisklet()
129

13-
const asAppleAdsAttribution = asObject({
14-
campaignId: asOptional(asString),
15-
keywordId: asOptional(asString)
16-
})
17-
type AppleAdsAttribution = ReturnType<typeof asAppleAdsAttribution>
18-
19-
interface FirstOpenInfo {
20-
isFirstOpen: 'true' | 'false'
21-
deviceId: string
22-
firstOpenEpoch: number
23-
countryCode?: string
24-
appleAdsAttribution?: AppleAdsAttribution
25-
}
26-
type FirstOpenInfoFile = Omit<FirstOpenInfo, 'appleAdsAttribution'>
27-
28-
const asFirstOpenInfoFile = asObject<FirstOpenInfoFile>({
10+
const asFirstOpenInfo = asObject({
2911
isFirstOpen: asValue('true', 'false'),
3012
deviceId: asString,
3113
firstOpenEpoch: asNumber,
3214
countryCode: asOptional(asString)
3315
})
16+
type FirstOpenInfo = ReturnType<typeof asFirstOpenInfo>
3417

3518
let firstOpenInfo: FirstOpenInfo
3619
let firstLoadPromise: Promise<FirstOpenInfo> | undefined
@@ -57,19 +40,11 @@ const readFirstOpenInfoFromDisk = async (): Promise<FirstOpenInfo> => {
5740
let firstOpenText
5841
try {
5942
firstOpenText = await firstOpenDisklet.getText(FIRST_OPEN)
60-
// Parse the file data using the file-specific cleaner
61-
const fileData = asFirstOpenInfoFile(JSON.parse(firstOpenText))
62-
// Create the full in-memory object with attribution data
63-
firstOpenInfo = {
64-
...fileData,
65-
isFirstOpen: 'false',
66-
appleAdsAttribution: await getAppleAdsAttribution()
67-
}
43+
firstOpenInfo = asFirstOpenInfo(JSON.parse(firstOpenText))
44+
firstOpenInfo.isFirstOpen = 'false'
6845
} catch (error: unknown) {
6946
// Generate new values.
70-
71-
// Create file data object (without attribution)
72-
const fileData: FirstOpenInfoFile = {
47+
firstOpenInfo = {
7348
deviceId: await makeUuid(),
7449
firstOpenEpoch: Date.now(),
7550
countryCode: await getCountryCodeByIp(),
@@ -78,78 +53,11 @@ const readFirstOpenInfoFromDisk = async (): Promise<FirstOpenInfo> => {
7853
// date, just created an empty file.
7954
// Note that 'firstOpenEpoch' won't be accurate in this case, but at
8055
// least make a starting point.
81-
8256
isFirstOpen: firstOpenText != null ? 'false' : 'true'
8357
}
84-
85-
// Create the full in-memory object
86-
firstOpenInfo = {
87-
...fileData,
88-
appleAdsAttribution: await getAppleAdsAttribution()
89-
}
90-
91-
// Only save the file-specific data to disk
92-
await firstOpenDisklet.setText(FIRST_OPEN, JSON.stringify(fileData))
58+
await firstOpenDisklet.setText(FIRST_OPEN, JSON.stringify(firstOpenInfo))
9359
}
9460
}
9561

9662
return firstOpenInfo
9763
}
98-
99-
/**
100-
* Get Apple Search Ads attribution data using the AdServices framework
101-
* and make an API call to get the actual keywordId.
102-
*/
103-
export async function getAppleAdsAttribution(): Promise<AppleAdsAttribution> {
104-
if (Platform.OS !== 'ios') {
105-
return { campaignId: undefined, keywordId: undefined }
106-
}
107-
108-
// Get the attribution token from the device. This package also handles
109-
// checking for the required iOS version.
110-
const attributionToken = await getAttributionToken().catch(error => {
111-
console.log('Apple Ads attribution token unavailable:', error)
112-
return undefined
113-
})
114-
115-
// Send the token to Apple's API to retrieve the campaign and keyword IDs.
116-
if (attributionToken != null) {
117-
// Retry logic as recommended by Apple:
118-
// "A 404 response can occur if you make an API call too quickly after
119-
// receiving a valid token. A best practice is to initiate retries at
120-
// intervals of 5 seconds, with a maximum of three attempts."
121-
// https://developer.apple.com/documentation/adservices/aaattribution/attributiontoken()#Attribution-payload
122-
const maxRetries = 3
123-
const retryDelay = 5000 // 5 seconds
124-
125-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
126-
try {
127-
// Get the attribution data from Apple for the token
128-
const response = await fetch('https://api-adservices.apple.com/api/v1/', {
129-
method: 'POST',
130-
headers: {
131-
'Content-Type': 'text/plain'
132-
},
133-
body: attributionToken
134-
})
135-
136-
// If we get a 404, wait and retry as per Apple's recommendation
137-
if (response.status === 404 && attempt < maxRetries) {
138-
console.log(`Apple Ads attribution API returned 404, retrying in ${retryDelay}ms (attempt ${attempt}/${maxRetries})`)
139-
await snooze(retryDelay)
140-
continue
141-
}
142-
143-
if (!response.ok) throw new Error(`API call failed with status: ${response.status}`)
144-
145-
const data = await response.json()
146-
return asAppleAdsAttribution(data)
147-
} catch (apiError) {
148-
console.warn('Error fetching Apple Ads attribution data:', apiError)
149-
break
150-
}
151-
}
152-
}
153-
154-
return { campaignId: undefined, keywordId: undefined }
155-
}

src/util/tracking.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ export interface TrackingValues extends LoginTrackingValues {
139139
numAccounts?: number // Number of full accounts saved on the device
140140
surveyCategory2?: string // User's answer to a survey (first tier response)
141141
surveyResponse2?: string // User's answer to a survey
142-
appleAdsKeywordId?: string // Apple Search Ads attribution keyword ID
143142

144143
// Conversion values
145144
conversionValues?: DollarConversionValues | CryptoConversionValues | SellConversionValues | BuyConversionValues | SwapConversionValues
@@ -202,13 +201,12 @@ export function trackError(
202201
/**
203202
* Send a raw event to all backends.
204203
*/
205-
206204
export function logEvent(event: TrackingEventName, values: TrackingValues = {}): ThunkAction<void> {
207205
return async (dispatch, getState) => {
208206
getExperimentConfig()
209207
.then(async (experimentConfig: ExperimentConfig) => {
210208
// Persistent & Unchanged params:
211-
const { isFirstOpen, deviceId, firstOpenEpoch, appleAdsAttribution } = await getFirstOpenInfo()
209+
const { isFirstOpen, deviceId, firstOpenEpoch } = await getFirstOpenInfo()
212210

213211
const { error, createdWalletCurrencyCode, conversionValues, ...restValue } = values
214212
const params: any = {
@@ -217,7 +215,6 @@ export function logEvent(event: TrackingEventName, values: TrackingValues = {}):
217215
isFirstOpen,
218216
deviceId,
219217
firstOpenEpoch,
220-
appleAdsAttribution,
221218
...restValue
222219
}
223220

0 commit comments

Comments
 (0)