Skip to content

Commit

Permalink
chore(analytics): deprecation warnings for v8 API ahead of future maj…
Browse files Browse the repository at this point in the history
…or release
  • Loading branch information
russellwheatley committed Dec 20, 2024
1 parent 10e618f commit ac79ae1
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 11 deletions.
137 changes: 136 additions & 1 deletion packages/analytics/__tests__/analytics.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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',
);
});
});
});
});
27 changes: 17 additions & 10 deletions packages/analytics/lib/modular/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { firebase } from '..';
import { MODULAR_DEPRECATION_ARG } from '../../../app/lib/common';

/**
* @typedef {import('@firebase/app').FirebaseApp} FirebaseApp
Expand Down Expand Up @@ -73,7 +74,7 @@ export function initializeAnalytics(app, options) {
* @returns {Promise<void>}
*/
export function logEvent(analytics, name, params = {}, options = {}) {
return analytics.logEvent(name, params, options);
return analytics.logEvent.call(analytics, name, params, options, MODULAR_DEPRECATION_ARG);
}

/**
Expand All @@ -83,7 +84,7 @@ export function logEvent(analytics, name, params = {}, options = {}) {
* @returns {Promise<void>}
*/
export function setAnalyticsCollectionEnabled(analytics, enabled) {
return analytics.setAnalyticsCollectionEnabled(enabled);
return analytics.setAnalyticsCollectionEnabled.call(analytics, enabled, MODULAR_DEPRECATION_ARG);
}

/**
Expand All @@ -93,7 +94,8 @@ export function setAnalyticsCollectionEnabled(analytics, enabled) {
* @returns {Promise<void>}
*/
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);
}

/**
Expand All @@ -102,7 +104,8 @@ export function setSessionTimeoutDuration(analytics, milliseconds = 1800000) {
* @returns {Promise<string|null>} 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);
}

/**
Expand All @@ -112,7 +115,8 @@ export function getAppInstanceId(analytics) {
* @returns {Promise<string|null>} 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);
}

/**
Expand All @@ -122,7 +126,7 @@ export function getSessionId(analytics) {
* @returns {Promise<void>}
*/
export function setUserId(analytics, id) {
return analytics.setUserId(id);
return analytics.setUserId.call(analytics, id, MODULAR_DEPRECATION_ARG);
}

/**
Expand All @@ -133,7 +137,8 @@ export function setUserId(analytics, id) {
* @returns {Promise<void>}
*/
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);
}

/**
Expand All @@ -144,7 +149,7 @@ export function setUserProperty(analytics, name, value) {
* @returns {Promise<void>}
*/
export function setUserProperties(analytics, properties, options = {}) {
return analytics.setUserProperties(properties, options);
return analytics.setUserProperties.call(analytics, properties, options, MODULAR_DEPRECATION_ARG);
}

/**
Expand All @@ -153,7 +158,8 @@ export function setUserProperties(analytics, properties, options = {}) {
* @returns {Promise<void>}
*/
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);
}

/**
Expand All @@ -163,6 +169,7 @@ export function resetAnalyticsData(analytics) {
* @returns {Promise<void>}
*/
export function logAddPaymentInfo(analytics, params) {
// TODO - not sure if this should be deprecated. up to this point.
return analytics.logAddPaymentInfo(params);
}

Expand Down Expand Up @@ -586,7 +593,7 @@ export function isSupported() {
* @returns {Promise<void>}
*/
export function setConsent(analytics, consentSettings) {
return analytics.setConsent(consentSettings);
return analytics.setConsent.call(analytics, consentSettings, MODULAR_DEPRECATION_ARG);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions packages/app/lib/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()',
Expand Down

0 comments on commit ac79ae1

Please sign in to comment.