From ac79ae1ecbf777cb431d7dbf75838b4cbf75683d Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Fri, 20 Dec 2024 10:59:10 +0000 Subject: [PATCH] chore(analytics): deprecation warnings for v8 API ahead of future major release --- .../analytics/__tests__/analytics.test.ts | 137 +++++++++++++++++- packages/analytics/lib/modular/index.js | 27 ++-- packages/app/lib/common/index.js | 16 ++ 3 files changed, 169 insertions(+), 11 deletions(-) diff --git a/packages/analytics/__tests__/analytics.test.ts b/packages/analytics/__tests__/analytics.test.ts index 1453dc7f8b..de9943160e 100644 --- a/packages/analytics/__tests__/analytics.test.ts +++ b/packages/analytics/__tests__/analytics.test.ts @@ -1,4 +1,7 @@ -import { describe, expect, it, xit } from '@jest/globals'; +import { jest, describe, expect, it, xit, beforeEach } from '@jest/globals'; + +// @ts-ignore test +import FirebaseModule from '../../app/lib/internal/FirebaseModule'; import { firebase, @@ -58,6 +61,11 @@ import { settings, } from '../lib'; +import { + createCheckV9Deprecation, + CheckV9DeprecationFunction, +} from '../../app/lib/common/unitTestUtils'; + describe('Analytics', function () { describe('namespace', function () { it('accessible from firebase.app()', function () { @@ -924,4 +932,131 @@ describe('Analytics', function () { expect(settings).toBeDefined(); }); }); + + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { + let analyticsRefV9Deprecation: CheckV9DeprecationFunction; + + beforeEach(function () { + analyticsRefV9Deprecation = createCheckV9Deprecation(['analytics']); + + // @ts-ignore test + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { + return new Proxy( + {}, + { + get: () => + jest.fn().mockResolvedValue({ + source: 'cache', + changes: [], + documents: [], + metadata: {}, + path: 'foo', + } as never), + }, + ); + }); + }); + + describe('Analytics', function () { + it('analytics.logEvent()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => logEvent(analytics, 'invertase_event'), + () => analytics.logEvent('invertase_event'), + 'logEvent', + ); + }); + + it('analytics.setAnalyticsCollectionEnabled()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => setAnalyticsCollectionEnabled(analytics, true), + () => analytics.setAnalyticsCollectionEnabled(true), + 'setAnalyticsCollectionEnabled', + ); + }); + + it('analytics.setSessionTimeoutDuration()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => setSessionTimeoutDuration(analytics, 180000), + () => analytics.setSessionTimeoutDuration(180000), + 'setSessionTimeoutDuration', + ); + }); + + it('analytics.getAppInstanceId()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => getAppInstanceId(analytics), + () => analytics.getAppInstanceId(), + 'getAppInstanceId', + ); + }); + + it('analytics.getSessionId()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => getSessionId(analytics), + () => analytics.getSessionId(), + 'getSessionId', + ); + }); + + it('analytics.setUserId()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => setUserId(analytics, 'id'), + () => analytics.setUserId('id'), + 'setUserId', + ); + }); + + it('analytics.setUserProperty()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => setUserProperty(analytics, 'prop', 'value'), + () => analytics.setUserProperty('prop', 'value'), + 'setUserProperty', + ); + }); + + it('analytics.setUserProperties()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => setUserProperties(analytics, { prop: 'value' }), + () => analytics.setUserProperties({ prop: 'value' }), + 'setUserProperties', + ); + }); + + it('analytics.resetAnalyticsData()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => resetAnalyticsData(analytics), + () => analytics.resetAnalyticsData(), + 'resetAnalyticsData', + ); + }); + + it('analytics.setConsent()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => setConsent(analytics, { ad_storage: true }), + () => analytics.setConsent({ ad_storage: true }), + 'setConsent', + ); + }); + + it('analytics.logAddPaymentInfo()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // no corresponding method + () => {}, + () => analytics.logAddPaymentInfo({ value: 1 }), + 'logAddPaymentInfo', + ); + }); + }); + }); }); diff --git a/packages/analytics/lib/modular/index.js b/packages/analytics/lib/modular/index.js index ed69a32b3a..bd5a4a48ba 100644 --- a/packages/analytics/lib/modular/index.js +++ b/packages/analytics/lib/modular/index.js @@ -1,4 +1,5 @@ import { firebase } from '..'; +import { MODULAR_DEPRECATION_ARG } from '../../../app/lib/common'; /** * @typedef {import('@firebase/app').FirebaseApp} FirebaseApp @@ -73,7 +74,7 @@ export function initializeAnalytics(app, options) { * @returns {Promise} */ export function logEvent(analytics, name, params = {}, options = {}) { - return analytics.logEvent(name, params, options); + return analytics.logEvent.call(analytics, name, params, options, MODULAR_DEPRECATION_ARG); } /** @@ -83,7 +84,7 @@ export function logEvent(analytics, name, params = {}, options = {}) { * @returns {Promise} */ export function setAnalyticsCollectionEnabled(analytics, enabled) { - return analytics.setAnalyticsCollectionEnabled(enabled); + return analytics.setAnalyticsCollectionEnabled.call(analytics, enabled, MODULAR_DEPRECATION_ARG); } /** @@ -93,7 +94,8 @@ export function setAnalyticsCollectionEnabled(analytics, enabled) { * @returns {Promise} */ export function setSessionTimeoutDuration(analytics, milliseconds = 1800000) { - return analytics.setSessionTimeoutDuration(milliseconds); + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + return analytics.setSessionTimeoutDuration.call(analytics, milliseconds, MODULAR_DEPRECATION_ARG); } /** @@ -102,7 +104,8 @@ export function setSessionTimeoutDuration(analytics, milliseconds = 1800000) { * @returns {Promise} Returns the app instance id or null on android if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED and null on iOS if ConsentType.analyticsStorage has been set to ConsentStatus.denied. */ export function getAppInstanceId(analytics) { - return analytics.getAppInstanceId(); + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + return analytics.getAppInstanceId.call(analytics, MODULAR_DEPRECATION_ARG); } /** @@ -112,7 +115,8 @@ export function getAppInstanceId(analytics) { * @returns {Promise} Returns the session id or null if session is expired, null on android if FirebaseAnalytics.ConsentType.ANALYTICS_STORAGE has been set to FirebaseAnalytics.ConsentStatus.DENIED and null on iOS if ConsentType.analyticsStorage has been set to ConsentStatus.denied. */ export function getSessionId(analytics) { - return analytics.getSessionId(); + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + return analytics.getSessionId.call(analytics, MODULAR_DEPRECATION_ARG); } /** @@ -122,7 +126,7 @@ export function getSessionId(analytics) { * @returns {Promise} */ export function setUserId(analytics, id) { - return analytics.setUserId(id); + return analytics.setUserId.call(analytics, id, MODULAR_DEPRECATION_ARG); } /** @@ -133,7 +137,8 @@ export function setUserId(analytics, id) { * @returns {Promise} */ export function setUserProperty(analytics, name, value) { - return analytics.setUserProperty(name, value); + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + return analytics.setUserProperty.call(analytics, name, value, MODULAR_DEPRECATION_ARG); } /** @@ -144,7 +149,7 @@ export function setUserProperty(analytics, name, value) { * @returns {Promise} */ export function setUserProperties(analytics, properties, options = {}) { - return analytics.setUserProperties(properties, options); + return analytics.setUserProperties.call(analytics, properties, options, MODULAR_DEPRECATION_ARG); } /** @@ -153,7 +158,8 @@ export function setUserProperties(analytics, properties, options = {}) { * @returns {Promise} */ export function resetAnalyticsData(analytics) { - return analytics.resetAnalyticsData(); + // This doesn't exist on firebase-js-sdk, but probably should keep this for android & iOS + return analytics.resetAnalyticsData.call(analytics, MODULAR_DEPRECATION_ARG); } /** @@ -163,6 +169,7 @@ export function resetAnalyticsData(analytics) { * @returns {Promise} */ export function logAddPaymentInfo(analytics, params) { + // TODO - not sure if this should be deprecated. up to this point. return analytics.logAddPaymentInfo(params); } @@ -586,7 +593,7 @@ export function isSupported() { * @returns {Promise} */ export function setConsent(analytics, consentSettings) { - return analytics.setConsent(consentSettings); + return analytics.setConsent.call(analytics, consentSettings, MODULAR_DEPRECATION_ARG); } /** diff --git a/packages/app/lib/common/index.js b/packages/app/lib/common/index.js index 159ae0c40f..3517faeb6f 100644 --- a/packages/app/lib/common/index.js +++ b/packages/app/lib/common/index.js @@ -107,6 +107,22 @@ export function tryJSONStringify(data) { const NO_REPLACEMENT = true; const mapOfDeprecationReplacements = { + analytics: { + default: { + logEvent: 'logEvent()', + setAnalyticsCollectionEnabled: 'setAnalyticsCollectionEnabled()', + setSessionTimeoutDuration: 'setSessionTimeoutDuration()', + getAppInstanceId: 'getAppInstanceId()', + getSessionId: 'getSessionId()', + setUserId: 'setUserId()', + setUserProperty: 'setUserProperty()', + setUserProperties: 'setUserProperties()', + resetAnalyticsData: 'resetAnalyticsData()', + setConsent: 'setConsent()', + // TODO are we deprecating all modular methods for each specific event. e.g. `logAddPaymentInfo()` + logAddPaymentInfo: 'logEvent()', + }, + }, crashlytics: { default: { checkForUnsentReports: 'checkForUnsentReports()',