diff --git a/packages/analytics/plugin/__tests__/__snapshots__/iosPlugin.test.ts.snap b/packages/analytics/plugin/__tests__/__snapshots__/iosPlugin.test.ts.snap index 8e0ea488f8..be03ea66f9 100644 --- a/packages/analytics/plugin/__tests__/__snapshots__/iosPlugin.test.ts.snap +++ b/packages/analytics/plugin/__tests__/__snapshots__/iosPlugin.test.ts.snap @@ -1,5 +1,18 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +exports[`Analytics Config Plugin iOS Tests adds the Podfile flag when googleAppMeasurementOnDeviceConversion is enabled 1`] = ` +"platform :ios, '15.0' + +prepare_react_native_project! +# @generated begin @react-native-firebase/analytics-googleAppMeasurementOnDeviceConversion - expo prebuild (DO NOT MODIFY) sync-6d1952a1f7b9ccb2d313cbd66659db4cdeae591f +$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true +# @generated end @react-native-firebase/analytics-googleAppMeasurementOnDeviceConversion + +target 'ReactNativeFirebaseDemo' do +end +" +`; + exports[`Analytics Config Plugin iOS Tests adds the Podfile flag when withoutAdIdSupport is enabled 1`] = ` "platform :ios, '15.0' diff --git a/packages/analytics/plugin/__tests__/iosPlugin.test.ts b/packages/analytics/plugin/__tests__/iosPlugin.test.ts index a2014345dc..c7940a54c7 100644 --- a/packages/analytics/plugin/__tests__/iosPlugin.test.ts +++ b/packages/analytics/plugin/__tests__/iosPlugin.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from '@jest/globals'; -import { setAnalyticsPodfileWithoutAdIdSupport } from '../src/ios/podfile'; +import { setAnalyticsPodfileWithoutAdIdSupport, setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion } from '../src/ios/podfile'; const podfileFixture = `platform :ios, '15.0' @@ -29,4 +29,23 @@ describe('Analytics Config Plugin iOS Tests', function () { expect(restored).toEqual(podfileFixture); }); + + it('adds the Podfile flag when googleAppMeasurementOnDeviceConversion is enabled', function () { + const result = setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion(podfileFixture, true); + expect(result).toMatchSnapshot(); + }); + + it('is idempotent when the ODM Podfile flag is already present', function () { + const onceModified = setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion(podfileFixture, true); + const twiceModified = setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion(onceModified, true); + + expect(twiceModified).toEqual(onceModified); + }); + + it('removes the generated Podfile flag when googleAppMeasurementOnDeviceConversion is disabled', function () { + const onceModified = setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion(podfileFixture, true); + const restored = setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion(onceModified, false); + + expect(restored).toEqual(podfileFixture); + }); }); diff --git a/packages/analytics/plugin/src/index.ts b/packages/analytics/plugin/src/index.ts index fb2cd5e10a..66ae941ee4 100644 --- a/packages/analytics/plugin/src/index.ts +++ b/packages/analytics/plugin/src/index.ts @@ -1,6 +1,6 @@ import { ConfigPlugin, withPlugins, createRunOncePlugin } from '@expo/config-plugins'; -import { withIosWithoutAdIdSupport } from './ios'; +import { withIosWithoutAdIdSupport, withIosGoogleAppMeasurementOnDeviceConversion } from './ios'; import { PluginConfigType } from './pluginConfig'; /** @@ -10,6 +10,7 @@ const withRnFirebaseAnalytics: ConfigPlugin = (config, props) return withPlugins(config, [ // iOS [withIosWithoutAdIdSupport, props], + [withIosGoogleAppMeasurementOnDeviceConversion, props], ]); }; diff --git a/packages/analytics/plugin/src/ios/index.ts b/packages/analytics/plugin/src/ios/index.ts index b63d644c3b..e642d277ac 100644 --- a/packages/analytics/plugin/src/ios/index.ts +++ b/packages/analytics/plugin/src/ios/index.ts @@ -1,3 +1,3 @@ -import { withIosWithoutAdIdSupport } from './podfile'; +import { withIosWithoutAdIdSupport, withIosGoogleAppMeasurementOnDeviceConversion } from './podfile'; -export { withIosWithoutAdIdSupport }; +export { withIosWithoutAdIdSupport, withIosGoogleAppMeasurementOnDeviceConversion }; diff --git a/packages/analytics/plugin/src/ios/podfile.ts b/packages/analytics/plugin/src/ios/podfile.ts index 0d3e2f4cbf..dea728b17b 100644 --- a/packages/analytics/plugin/src/ios/podfile.ts +++ b/packages/analytics/plugin/src/ios/podfile.ts @@ -9,6 +9,8 @@ import { PluginConfigType } from '../pluginConfig'; const TAG = '@react-native-firebase/analytics-withoutAdIdSupport'; const ANCHOR = /prepare_react_native_project!/; const FLAG = '$RNFirebaseAnalyticsWithoutAdIdSupport = true'; +const TAG_ODM = '@react-native-firebase/analytics-googleAppMeasurementOnDeviceConversion'; +const FLAG_ODM = '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true'; export function setAnalyticsPodfileWithoutAdIdSupport( src: string, @@ -28,6 +30,35 @@ export function setAnalyticsPodfileWithoutAdIdSupport( }).contents; } +export function setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion( + src: string, + enabled: boolean = false, +): string { + if (!enabled) { + return removeGeneratedContents(src, TAG_ODM) ?? src; + } + + return mergeContents({ + src, + newSrc: FLAG_ODM, + tag: TAG_ODM, + anchor: ANCHOR, + offset: 1, + comment: '#', + }).contents; +} + +export const withIosGoogleAppMeasurementOnDeviceConversion: ConfigPlugin = (config, props) => { + return withPodfile(config, config => { + config.modResults.contents = setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion( + config.modResults.contents, + props?.ios?.googleAppMeasurementOnDeviceConversion === true, + ); + + return config; + }); +}; + export const withIosWithoutAdIdSupport: ConfigPlugin = (config, props) => { return withPodfile(config, config => { config.modResults.contents = setAnalyticsPodfileWithoutAdIdSupport( diff --git a/packages/analytics/plugin/src/pluginConfig.ts b/packages/analytics/plugin/src/pluginConfig.ts index 29aa84c79a..b8856086f3 100644 --- a/packages/analytics/plugin/src/pluginConfig.ts +++ b/packages/analytics/plugin/src/pluginConfig.ts @@ -4,4 +4,8 @@ export interface PluginConfigType { export interface PluginConfigTypeIos { withoutAdIdSupport?: boolean; + /** + * @platform ios iOS + */ + googleAppMeasurementOnDeviceConversion?: boolean; }