From 13011c3a15fd24e4c35a55ed4011940218b56a13 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Fri, 20 Dec 2024 10:59:10 +0000 Subject: [PATCH 1/4] 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..13aa95769d 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, currency: 'usd' }), + '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 a9d0206be6..60a056f8d3 100644 --- a/packages/app/lib/common/index.js +++ b/packages/app/lib/common/index.js @@ -119,6 +119,22 @@ const mapOfDeprecationReplacements = { CustomProvider: 'CustomProvider', }, }, + 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()', From 8335d057645fe30c4fac87992b993522bd9a2573 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Thu, 29 May 2025 15:32:16 +0100 Subject: [PATCH 2/4] chore: deprecate warning for more methods --- .../analytics/__tests__/analytics.test.ts | 276 +++++++++++++++++- packages/analytics/lib/modular/index.js | 13 +- packages/app/lib/common/index.js | 13 +- 3 files changed, 299 insertions(+), 3 deletions(-) diff --git a/packages/analytics/__tests__/analytics.test.ts b/packages/analytics/__tests__/analytics.test.ts index ef0f8a8053..9c4223ef14 100644 --- a/packages/analytics/__tests__/analytics.test.ts +++ b/packages/analytics/__tests__/analytics.test.ts @@ -1068,11 +1068,285 @@ describe('Analytics', function () { it('analytics.logAddPaymentInfo()', function () { const analytics = getAnalytics(); analyticsRefV9Deprecation( - // no corresponding method + // This is deprecated for both namespaced and modular. () => {}, () => analytics.logAddPaymentInfo({ value: 1, currency: 'usd' }), 'logAddPaymentInfo', ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => logAddPaymentInfo(analytics, { value: 1, currency: 'usd' }), + 'logAddPaymentInfo', + ); + }); + + it('analytics.logScreenView()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logScreenView({ + screen_class: 'ProductScreen', + screen_name: 'ProductScreen', + }), + 'logScreenView', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logScreenView(analytics, { + screen_class: 'ProductScreen', + screen_name: 'ProductScreen', + }), + 'logScreenView', + ); + }); + + it('analytics.logAddShippingInfo()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logAddShippingInfo({ + value: 100, + currency: 'usd', + }), + 'logAddShippingInfo', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logAddShippingInfo(analytics, { + value: 100, + currency: 'usd', + }), + 'logAddShippingInfo', + ); + }); + + it('analytics.logAddToCart()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logAddToCart({ + value: 100, + currency: 'usd', + }), + 'logAddToCart', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logAddToCart(analytics, { + value: 100, + currency: 'usd', + }), + 'logAddToCart', + ); + }); + + it('analytics.logAddToWishlist()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logAddToWishlist({ + value: 100, + currency: 'usd', + }), + 'logAddToWishlist', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logAddToWishlist(analytics, { + value: 100, + currency: 'usd', + }), + 'logAddToWishlist', + ); + }); + + it('analytics.logAppOpen()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => analytics.logAppOpen(), + 'logAppOpen', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => logAppOpen(analytics), + 'logAppOpen', + ); + }); + + it('analytics.logBeginCheckout()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logBeginCheckout({ + value: 100, + currency: 'usd', + }), + 'logBeginCheckout', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logBeginCheckout(analytics, { + value: 100, + currency: 'usd', + }), + 'logBeginCheckout', + ); + }); + + it('analytics.logCampaignDetails()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logCampaignDetails({ + source: 'email', + medium: 'cta_button', + campaign: 'newsletter', + }), + 'logCampaignDetails', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logCampaignDetails(analytics, { + source: 'email', + medium: 'cta_button', + campaign: 'newsletter', + }), + 'logCampaignDetails', + ); + }); + + it('analytics.logEarnVirtualCurrency()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logEarnVirtualCurrency({ + virtual_currency_name: 'coins', + value: 100, + }), + 'logEarnVirtualCurrency', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logEarnVirtualCurrency(analytics, { + virtual_currency_name: 'coins', + value: 100, + }), + 'logEarnVirtualCurrency', + ); + }); + + it('analytics.logGenerateLead()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logGenerateLead({ + currency: 'USD', + value: 123, + }), + 'logGenerateLead', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logGenerateLead(analytics, { + currency: 'USD', + value: 123, + }), + 'logGenerateLead', + ); + }); + + it('analytics.logJoinGroup()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logJoinGroup({ + group_id: '12345', + }), + 'logJoinGroup', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logJoinGroup(analytics, { + group_id: '12345', + }), + 'logJoinGroup', + ); + }); + + it('analytics.logLevelEnd()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logLevelEnd({ + level: 12, + success: 'true', + }), + 'logLevelEnd', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logLevelEnd(analytics, { + level: 12, + success: 'true', + }), + 'logLevelEnd', + ); }); }); }); diff --git a/packages/analytics/lib/modular/index.js b/packages/analytics/lib/modular/index.js index fc4060740a..879ee0b237 100644 --- a/packages/analytics/lib/modular/index.js +++ b/packages/analytics/lib/modular/index.js @@ -184,7 +184,7 @@ export function resetAnalyticsData(analytics) { * @returns {Promise} */ export function logAddPaymentInfo(analytics, params) { - // TODO - not sure if this should be deprecated. up to this point. + // This is deprecated for both namespaced and modular. return analytics.logAddPaymentInfo(params); } @@ -195,6 +195,7 @@ export function logAddPaymentInfo(analytics, params) { * @returns {Promise} */ export function logScreenView(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logScreenView(params); } @@ -205,6 +206,7 @@ export function logScreenView(analytics, params) { * @returns {Promise} */ export function logAddShippingInfo(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logAddShippingInfo(params); } @@ -215,6 +217,7 @@ export function logAddShippingInfo(analytics, params) { * @returns {Promise} */ export function logAddToCart(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logAddToCart(params); } @@ -225,6 +228,7 @@ export function logAddToCart(analytics, params) { * @returns {Promise} */ export function logAddToWishlist(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logAddToWishlist(params); } @@ -234,6 +238,7 @@ export function logAddToWishlist(analytics, params) { * @returns {Promise} */ export function logAppOpen(analytics) { + // This is deprecated for both namespaced and modular. return analytics.logAppOpen(); } @@ -244,6 +249,7 @@ export function logAppOpen(analytics) { * @returns {Promise} */ export function logBeginCheckout(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logBeginCheckout(params); } @@ -254,6 +260,7 @@ export function logBeginCheckout(analytics, params) { * @returns {Promise} */ export function logCampaignDetails(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logCampaignDetails(params); } @@ -264,6 +271,7 @@ export function logCampaignDetails(analytics, params) { * @returns {Promise} */ export function logEarnVirtualCurrency(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logEarnVirtualCurrency(params); } @@ -274,6 +282,7 @@ export function logEarnVirtualCurrency(analytics, params) { * @returns {Promise} */ export function logGenerateLead(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logGenerateLead(params); } @@ -284,6 +293,7 @@ export function logGenerateLead(analytics, params) { * @returns {Promise} */ export function logJoinGroup(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logJoinGroup(params); } @@ -294,6 +304,7 @@ export function logJoinGroup(analytics, params) { * @returns {Promise} */ export function logLevelEnd(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logLevelEnd(params); } diff --git a/packages/app/lib/common/index.js b/packages/app/lib/common/index.js index ef6bdbd55e..e84e23e54d 100644 --- a/packages/app/lib/common/index.js +++ b/packages/app/lib/common/index.js @@ -131,8 +131,19 @@ const mapOfDeprecationReplacements = { setUserProperties: 'setUserProperties()', resetAnalyticsData: 'resetAnalyticsData()', setConsent: 'setConsent()', - // TODO are we deprecating all modular methods for each specific event. e.g. `logAddPaymentInfo()` + // We're deprecating all helper methods for event. e.g. `logAddPaymentInfo()` from namespaced and modular. logAddPaymentInfo: 'logEvent()', + logScreenView: 'logEvent()', + logAddShippingInfo: 'logEvent()', + logAddToCart: 'logEvent()', + logAddToWishlist: 'logEvent()', + logAppOpen: 'logEvent()', + logBeginCheckout: 'logEvent()', + logCampaignDetails: 'logEvent()', + logEarnVirtualCurrency: 'logEvent()', + logGenerateLead: 'logEvent()', + logJoinGroup: 'logEvent()', + logLevelEnd: 'logEvent()', }, }, crashlytics: { From 1b4ed17bd6fca173ffa2861c043487a7dc57a9ae Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Fri, 30 May 2025 09:39:09 +0100 Subject: [PATCH 3/4] chore: deprecate the rest of analytics methods --- .../analytics/__tests__/analytics.test.ts | 574 ++++++++++++++++++ packages/analytics/lib/modular/index.js | 49 +- packages/app/lib/common/index.js | 31 + 3 files changed, 649 insertions(+), 5 deletions(-) diff --git a/packages/analytics/__tests__/analytics.test.ts b/packages/analytics/__tests__/analytics.test.ts index 9c4223ef14..438bdf1065 100644 --- a/packages/analytics/__tests__/analytics.test.ts +++ b/packages/analytics/__tests__/analytics.test.ts @@ -1348,6 +1348,580 @@ describe('Analytics', function () { 'logLevelEnd', ); }); + + it('analytics.logLevelStart()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logLevelStart({ + level: 12, + }), + 'logLevelStart', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logLevelStart(analytics, { + level: 12, + }), + 'logLevelStart', + ); + }); + + it('analytics.logLevelUp()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logLevelUp({ + level: 12, + }), + 'logLevelUp', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logLevelUp(analytics, { + level: 12, + }), + 'logLevelUp', + ); + }); + + it('analytics.logLogin()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logLogin({ + method: 'facebook.com', + }), + 'logLogin', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logLogin(analytics, { + method: 'facebook.com', + }), + 'logLogin', + ); + }); + + it('analytics.logPostScore()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logPostScore({ + score: 567334, + level: 3, + }), + 'logPostScore', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logPostScore(analytics, { + score: 567334, + level: 3, + }), + 'logPostScore', + ); + }); + + it('analytics.logSelectContent()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logSelectContent({ + content_type: 'clothing', + item_id: 'abcd', + }), + 'logSelectContent', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logSelectContent(analytics, { + content_type: 'clothing', + item_id: 'abcd', + }), + 'logSelectContent', + ); + }); + + it('analytics.logPurchase()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logPurchase({ + value: 100, + currency: 'usd', + }), + 'logPurchase', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logPurchase(analytics, { + value: 100, + currency: 'usd', + }), + 'logPurchase', + ); + }); + + it('analytics.logRefund()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logRefund({ + value: 100, + currency: 'usd', + }), + 'logRefund', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logRefund(analytics, { + value: 100, + currency: 'usd', + }), + 'logRefund', + ); + }); + + it('analytics.logRemoveFromCart()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logRemoveFromCart({ + value: 100, + currency: 'usd', + }), + 'logRemoveFromCart', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logRemoveFromCart(analytics, { + value: 100, + currency: 'usd', + }), + 'logRemoveFromCart', + ); + }); + + it('analytics.logSearch()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logSearch({ + search_term: 't-shirts', + }), + 'logSearch', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logSearch(analytics, { + search_term: 't-shirts', + }), + 'logSearch', + ); + }); + + it('analytics.logSelectItem()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logSelectItem({ + item_list_id: '54690834', + item_list_name: 't-shirts', + content_type: 'clothing', + }), + 'logSelectItem', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logSelectItem(analytics, { + item_list_id: '54690834', + item_list_name: 't-shirts', + content_type: 'clothing', + }), + 'logSelectItem', + ); + }); + + it('analytics.logSetCheckoutOption()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logSetCheckoutOption({ + checkout_step: 2, + checkout_option: 'false', + }), + 'logSetCheckoutOption', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logSetCheckoutOption(analytics, { + checkout_step: 2, + checkout_option: 'false', + }), + 'logSetCheckoutOption', + ); + }); + + it('analytics.logSelectPromotion()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logSelectPromotion({ + creative_name: 'the promotion', + creative_slot: 'evening', + location_id: 'london', + promotion_id: '230593', + promotion_name: 'summer sale', + }), + 'logSelectPromotion', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logSelectPromotion(analytics, { + creative_name: 'the promotion', + creative_slot: 'evening', + location_id: 'london', + promotion_id: '230593', + promotion_name: 'summer sale', + }), + 'logSelectPromotion', + ); + }); + + it('analytics.logShare()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logShare({ + content_type: 't-shirts', + item_id: '12345', + method: 'twitter.com', + }), + 'logShare', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logShare(analytics, { + content_type: 't-shirts', + item_id: '12345', + method: 'twitter.com', + }), + 'logShare', + ); + }); + + it('analytics.logSignUp()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logSignUp({ + method: 'facebook.com', + }), + 'logSignUp', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logSignUp(analytics, { + method: 'facebook.com', + }), + 'logSignUp', + ); + }); + + it('analytics.logSpendVirtualCurrency()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logSpendVirtualCurrency({ + item_name: 'battle_pass', + virtual_currency_name: 'coins', + value: 100, + }), + 'logSpendVirtualCurrency', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logSpendVirtualCurrency(analytics, { + item_name: 'battle_pass', + virtual_currency_name: 'coins', + value: 100, + }), + 'logSpendVirtualCurrency', + ); + }); + + it('analytics.logTutorialBegin()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => analytics.logTutorialBegin(), + 'logTutorialBegin', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => logTutorialBegin(analytics), + 'logTutorialBegin', + ); + }); + + it('analytics.logTutorialComplete()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => analytics.logTutorialComplete(), + 'logTutorialComplete', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => logTutorialComplete(analytics), + 'logTutorialComplete', + ); + }); + + it('analytics.logUnlockAchievement()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => analytics.logUnlockAchievement({ achievement_id: '12345' }), + 'logUnlockAchievement', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => logUnlockAchievement(analytics, { achievement_id: '12345' }), + 'logUnlockAchievement', + ); + }); + + it('analytics.logViewCart()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => analytics.logViewCart({ value: 100, currency: 'usd' }), + 'logViewCart', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => logViewCart(analytics, { value: 100, currency: 'usd' }), + 'logViewCart', + ); + }); + + it('analytics.logViewItem()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => analytics.logViewItem({ value: 100, currency: 'usd' }), + 'logViewItem', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => logViewItem(analytics, { value: 100, currency: 'usd' }), + 'logViewItem', + ); + }); + }); + + it('analytics.logViewPromotion()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logViewPromotion({ + creative_name: 'the promotion', + creative_slot: 'evening', + location_id: 'london', + promotion_id: '230593', + }), + 'logViewPromotion', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logViewPromotion(analytics, { + creative_name: 'the promotion', + creative_slot: 'evening', + location_id: 'london', + promotion_id: '230593', + }), + 'logViewPromotion', + ); + }); + + it('analytics.logViewSearchResults()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + analytics.logViewSearchResults({ + search_term: 'clothing', + }), + 'logViewSearchResults', + ); + + analyticsRefV9Deprecation( + // This is deprecated for both namespaced and modular. + () => {}, + () => + logViewSearchResults(analytics, { + search_term: 'clothing', + }), + 'logViewSearchResults', + ); + }); + + it('analytics.setDefaultEventParameters()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => + setDefaultEventParameters(analytics, { + search_term: 'clothing', + }), + () => + analytics.setDefaultEventParameters({ + search_term: 'clothing', + }), + 'setDefaultEventParameters', + ); + }); + + it('analytics.initiateOnDeviceConversionMeasurementWithEmailAddress()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => initiateOnDeviceConversionMeasurementWithEmailAddress(analytics, 'some@email.com'), + () => analytics.initiateOnDeviceConversionMeasurementWithEmailAddress('some@email.com'), + 'initiateOnDeviceConversionMeasurementWithEmailAddress', + ); + }); + + it('analytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => + initiateOnDeviceConversionMeasurementWithHashedEmailAddress(analytics, 'some@email.com'), + () => + analytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress('some@email.com'), + 'initiateOnDeviceConversionMeasurementWithHashedEmailAddress', + ); + }); + + it('analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => initiateOnDeviceConversionMeasurementWithPhoneNumber(analytics, '+1555321'), + () => analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber('+1555321'), + 'initiateOnDeviceConversionMeasurementWithPhoneNumber', + ); + }); + + it('analytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber()', function () { + const analytics = getAnalytics(); + analyticsRefV9Deprecation( + () => + initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( + analytics, + 'b1b1b3b0b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1', + ), + () => + analytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( + 'b1b1b3b0b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1b1', + ), + 'initiateOnDeviceConversionMeasurementWithHashedPhoneNumber', + ); }); }); }); diff --git a/packages/analytics/lib/modular/index.js b/packages/analytics/lib/modular/index.js index 879ee0b237..90e0138551 100644 --- a/packages/analytics/lib/modular/index.js +++ b/packages/analytics/lib/modular/index.js @@ -315,6 +315,7 @@ export function logLevelEnd(analytics, params) { * @returns {Promise} */ export function logLevelStart(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logLevelStart(params); } @@ -325,6 +326,7 @@ export function logLevelStart(analytics, params) { * @returns {Promise} */ export function logLevelUp(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logLevelUp(params); } @@ -335,6 +337,7 @@ export function logLevelUp(analytics, params) { * @returns {Promise} */ export function logLogin(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logLogin(params); } @@ -345,6 +348,7 @@ export function logLogin(analytics, params) { * @returns {Promise} */ export function logPostScore(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logPostScore(params); } @@ -355,6 +359,7 @@ export function logPostScore(analytics, params) { * @returns {Promise} */ export function logSelectContent(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logSelectContent(params); } @@ -365,6 +370,7 @@ export function logSelectContent(analytics, params) { * @returns {Promise} */ export function logPurchase(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logPurchase(params); } @@ -375,6 +381,7 @@ export function logPurchase(analytics, params) { * @returns {Promise} */ export function logRefund(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logRefund(params); } @@ -385,6 +392,7 @@ export function logRefund(analytics, params) { * @returns {Promise} */ export function logRemoveFromCart(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logRemoveFromCart(params); } @@ -395,6 +403,7 @@ export function logRemoveFromCart(analytics, params) { * @returns {Promise} */ export function logSearch(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logSearch(params); } @@ -405,6 +414,7 @@ export function logSearch(analytics, params) { * @returns {Promise} */ export function logSelectItem(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logSelectItem(params); } @@ -415,6 +425,7 @@ export function logSelectItem(analytics, params) { * @returns {Promise} */ export function logSetCheckoutOption(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logSetCheckoutOption(params); } @@ -425,6 +436,7 @@ export function logSetCheckoutOption(analytics, params) { * @returns {Promise} */ export function logSelectPromotion(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logSelectPromotion(params); } @@ -435,6 +447,7 @@ export function logSelectPromotion(analytics, params) { * @returns {Promise} */ export function logShare(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logShare(params); } @@ -445,6 +458,7 @@ export function logShare(analytics, params) { * @returns {Promise} */ export function logSignUp(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logSignUp(params); } @@ -455,6 +469,7 @@ export function logSignUp(analytics, params) { * @returns {Promise} */ export function logSpendVirtualCurrency(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logSpendVirtualCurrency(params); } @@ -464,6 +479,7 @@ export function logSpendVirtualCurrency(analytics, params) { * @returns {Promise} */ export function logTutorialBegin(analytics) { + // This is deprecated for both namespaced and modular. return analytics.logTutorialBegin(); } @@ -473,6 +489,7 @@ export function logTutorialBegin(analytics) { * @returns {Promise} */ export function logTutorialComplete(analytics) { + // This is deprecated for both namespaced and modular. return analytics.logTutorialComplete(); } @@ -483,6 +500,7 @@ export function logTutorialComplete(analytics) { * @returns {Promise} */ export function logUnlockAchievement(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logUnlockAchievement(params); } @@ -493,6 +511,7 @@ export function logUnlockAchievement(analytics, params) { * @returns {Promise} */ export function logViewCart(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logViewCart(params); } @@ -503,6 +522,7 @@ export function logViewCart(analytics, params) { * @returns {Promise} */ export function logViewItem(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logViewItem(params); } @@ -513,6 +533,7 @@ export function logViewItem(analytics, params) { * @returns {Promise} */ export function logViewItemList(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logViewItemList(params); } @@ -523,6 +544,7 @@ export function logViewItemList(analytics, params) { * @returns {Promise} */ export function logViewPromotion(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logViewPromotion(params); } @@ -533,6 +555,7 @@ export function logViewPromotion(analytics, params) { * @returns {Promise} */ export function logViewSearchResults(analytics, params) { + // This is deprecated for both namespaced and modular. return analytics.logViewSearchResults(params); } @@ -543,7 +566,7 @@ export function logViewSearchResults(analytics, params) { * @returns {Promise} */ export function setDefaultEventParameters(analytics, params = {}) { - return analytics.setDefaultEventParameters(params); + return analytics.setDefaultEventParameters.call(analytics, params, MODULAR_DEPRECATION_ARG); } /** @@ -554,7 +577,11 @@ export function setDefaultEventParameters(analytics, params = {}) { * @returns {Promise} */ export function initiateOnDeviceConversionMeasurementWithEmailAddress(analytics, emailAddress) { - return analytics.initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress); + return analytics.initiateOnDeviceConversionMeasurementWithEmailAddress.call( + analytics, + emailAddress, + MODULAR_DEPRECATION_ARG, + ); } /** @@ -570,7 +597,11 @@ export function initiateOnDeviceConversionMeasurementWithHashedEmailAddress( analytics, hashedEmailAddress, ) { - return analytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress(hashedEmailAddress); + return analytics.initiateOnDeviceConversionMeasurementWithHashedEmailAddress.call( + analytics, + hashedEmailAddress, + MODULAR_DEPRECATION_ARG, + ); } /** @@ -581,7 +612,11 @@ export function initiateOnDeviceConversionMeasurementWithHashedEmailAddress( * @returns {Promise} */ export function initiateOnDeviceConversionMeasurementWithPhoneNumber(analytics, phoneNumber) { - return analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber); + return analytics.initiateOnDeviceConversionMeasurementWithPhoneNumber.call( + analytics, + phoneNumber, + MODULAR_DEPRECATION_ARG, + ); } /** @@ -597,7 +632,11 @@ export function initiateOnDeviceConversionMeasurementWithHashedPhoneNumber( analytics, hashedPhoneNumber, ) { - return analytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(hashedPhoneNumber); + return analytics.initiateOnDeviceConversionMeasurementWithHashedPhoneNumber.call( + analytics, + hashedPhoneNumber, + MODULAR_DEPRECATION_ARG, + ); } /** diff --git a/packages/app/lib/common/index.js b/packages/app/lib/common/index.js index e84e23e54d..ab7e1e64aa 100644 --- a/packages/app/lib/common/index.js +++ b/packages/app/lib/common/index.js @@ -130,6 +130,15 @@ const mapOfDeprecationReplacements = { setUserProperty: 'setUserProperty()', setUserProperties: 'setUserProperties()', resetAnalyticsData: 'resetAnalyticsData()', + setDefaultEventParameters: 'setDefaultEventParameters()', + initiateOnDeviceConversionMeasurementWithEmailAddress: + 'initiateOnDeviceConversionMeasurementWithEmailAddress()', + initiateOnDeviceConversionMeasurementWithHashedEmailAddress: + 'initiateOnDeviceConversionMeasurementWithHashedEmailAddress()', + initiateOnDeviceConversionMeasurementWithPhoneNumber: + 'initiateOnDeviceConversionMeasurementWithPhoneNumber()', + initiateOnDeviceConversionMeasurementWithHashedPhoneNumber: + 'initiateOnDeviceConversionMeasurementWithHashedPhoneNumber()', setConsent: 'setConsent()', // We're deprecating all helper methods for event. e.g. `logAddPaymentInfo()` from namespaced and modular. logAddPaymentInfo: 'logEvent()', @@ -144,6 +153,28 @@ const mapOfDeprecationReplacements = { logGenerateLead: 'logEvent()', logJoinGroup: 'logEvent()', logLevelEnd: 'logEvent()', + logLevelStart: 'logEvent()', + logLevelUp: 'logEvent()', + logLogin: 'logEvent()', + logPostScore: 'logEvent()', + logSelectContent: 'logEvent()', + logPurchase: 'logEvent()', + logRefund: 'logEvent()', + logRemoveFromCart: 'logEvent()', + logSearch: 'logEvent()', + logSelectItem: 'logEvent()', + logSetCheckoutOption: 'logEvent()', + logSelectPromotion: 'logEvent()', + logShare: 'logEvent()', + logSignUp: 'logEvent()', + logSpendVirtualCurrency: 'logEvent()', + logTutorialBegin: 'logEvent()', + logTutorialComplete: 'logEvent()', + logUnlockAchievement: 'logEvent()', + logViewCart: 'logEvent()', + logViewItem: 'logEvent()', + logViewPromotion: 'logEvent()', + logViewSearchResults: 'logEvent()', }, }, crashlytics: { From 4a9d77afd68d5b927c2370efbd23c09c9b258621 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Mon, 2 Jun 2025 12:20:27 +0100 Subject: [PATCH 4/4] test: moved API deprecated for modular and namespaced into own test group to quieten deprecation warnings --- packages/analytics/e2e/analytics.e2e.js | 678 ++++++++++++------------ 1 file changed, 345 insertions(+), 333 deletions(-) diff --git a/packages/analytics/e2e/analytics.e2e.js b/packages/analytics/e2e/analytics.e2e.js index 3c371753af..e89e51b7fb 100644 --- a/packages/analytics/e2e/analytics.e2e.js +++ b/packages/analytics/e2e/analytics.e2e.js @@ -592,460 +592,472 @@ describe('analytics()', function () { }); }); - describe('setSessionTimeoutDuration()', function () { - it('default duration', async function () { - const { getAnalytics, setSessionTimeoutDuration } = analyticsModular; - await setSessionTimeoutDuration(getAnalytics()); + describe('tests that are for deprecated API for modular and namespace', function () { + beforeEach(async function beforeEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; }); - xit('custom duration', async function () { - const { getAnalytics, setSessionTimeoutDuration } = analyticsModular; - // TODO: worked on Detox v17, causes crash after transition to v18. Why? - await setSessionTimeoutDuration(getAnalytics(), 13371337); + afterEach(async function afterEachTest() { + // @ts-ignore + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; }); - }); - describe('getAppInstanceId()', function () { - it('calls native fn without error', async function () { - const { getAnalytics, getAppInstanceId } = analyticsModular; - await getAppInstanceId(getAnalytics()); + describe('logScreenView()', function () { + it('calls logScreenView', async function () { + const { getAnalytics, logScreenView } = analyticsModular; + await logScreenView(getAnalytics(), { + screen_name: 'invertase screen', + screen_class: 'invertase class', + }); + }); }); - }); - describe('getSessionId()', function () { - it('calls native fn without error', async function () { - const { getAnalytics, getSessionId } = analyticsModular; - await getSessionId(getAnalytics()); + describe('logAddPaymentInfo()', function () { + it('calls logAddPaymentInfo', async function () { + const { getAnalytics, logAddPaymentInfo } = analyticsModular; + await logAddPaymentInfo(getAnalytics(), { + value: 123, + currency: 'USD', + items: [], + }); + }); }); - it('returns a non empty session ID', async function () { - if (Platform.other) { - this.skip(); - } - const { getAnalytics, getSessionId } = analyticsModular; - let sessionId = await getSessionId(getAnalytics()); - // On iOS it can take ~ 3 minutes for the session ID to be generated - // Otherwise, `Analytics uninitialized` error will be thrown - const retries = 240; - while (!sessionId && retries > 0) { - await Utils.sleep(1000); - sessionId = await getSessionId(getAnalytics()); - } - - if (!sessionId) { - return Promise.reject( - new Error('Firebase SDK did not return a session ID after 4 minutes'), - ); - } - - sessionId.should.not.equal(0); + describe('logAddToCart()', function () { + it('calls logAddToCart', async function () { + const { getAnalytics, logAddToCart } = analyticsModular; + await logAddToCart(getAnalytics(), { + value: 123, + currency: 'GBP', + }); + }); }); - it('returns a null value if session expires', async function () { - const { getAnalytics, getSessionId, setSessionTimeoutDuration } = analyticsModular; - // Set session duration to 1 millisecond - setSessionTimeoutDuration(getAnalytics(), 1); - // Wait 100 millisecond to ensure session expires - await Utils.sleep(100); - const sessionId = await getSessionId(getAnalytics()); - should.equal(sessionId, null); + describe('logAddShippingInfo()', function () { + it('calls logAddShippingInfo', async function () { + const { getAnalytics, logAddShippingInfo } = analyticsModular; + await logAddShippingInfo(getAnalytics(), { + value: 123, + currency: 'GBP', + }); + }); }); - }); - describe('setUserId()', function () { - it('allows a null values to be set', async function () { - const { getAnalytics, setUserId } = analyticsModular; - await setUserId(getAnalytics(), null); + describe('logAddToWishlist()', function () { + it('calls logAddToWishlist', async function () { + const { getAnalytics, logAddToWishlist } = analyticsModular; + await logAddToWishlist(getAnalytics(), { + items: [ + { + item_id: 'foo', + item_name: 'foo', + item_category: 'foo', + item_location_id: 'foo', + quantity: 5, + }, + ], + value: 123, + currency: 'GBP', + }); + }); }); - it('accepts string values', async function () { - const { getAnalytics, setUserId } = analyticsModular; - await setUserId(getAnalytics(), 'rn-firebase'); + describe('logAppOpen()', function () { + it('calls logAppOpen', async function () { + const { getAnalytics, logAppOpen } = analyticsModular; + await logAppOpen(getAnalytics()); + }); }); - }); - describe('setUserProperty()', function () { - it('allows a null values to be set', async function () { - const { getAnalytics, setUserProperty } = analyticsModular; - await setUserProperty(getAnalytics(), 'invertase', null); + describe('logBeginCheckout()', function () { + it('calls logBeginCheckout', async function () { + const { getAnalytics, logBeginCheckout } = analyticsModular; + await logBeginCheckout(getAnalytics()); + }); }); - it('accepts string values', async function () { - const { getAnalytics, setUserProperty } = analyticsModular; - await setUserProperty(getAnalytics(), 'invertase2', 'rn-firebase'); + describe('logCampaignDetails()', function () { + it('calls logCampaignDetails', async function () { + const { getAnalytics, logCampaignDetails } = analyticsModular; + await logCampaignDetails(getAnalytics(), { + source: 'foo', + medium: 'bar', + campaign: 'baz', + }); + }); }); - }); - describe('setUserProperties()', function () { - it('allows null values to be set', async function () { - const { getAnalytics, setUserProperties } = analyticsModular; - await setUserProperties(getAnalytics(), { invertase2: null }); + describe('logEarnVirtualCurrency()', function () { + it('calls logEarnVirtualCurrency', async function () { + const { getAnalytics, logEarnVirtualCurrency } = analyticsModular; + await logEarnVirtualCurrency(getAnalytics(), { + virtual_currency_name: 'foo', + value: 123, + }); + }); }); - it('accepts string values', async function () { - const { getAnalytics, setUserProperties } = analyticsModular; - await setUserProperties(getAnalytics(), { invertase3: 'rn-firebase' }); + describe('logPurchase()', function () { + it('calls logPurchase', async function () { + const { getAnalytics, logPurchase } = analyticsModular; + await logPurchase(getAnalytics(), { + currency: 'USD', + value: 123, + affiliation: 'affiliation', + }); + }); }); - }); - describe('logScreenView()', function () { - it('calls logScreenView', async function () { - const { getAnalytics, logScreenView } = analyticsModular; - await logScreenView(getAnalytics(), { - screen_name: 'invertase screen', - screen_class: 'invertase class', + describe('logViewPromotion()', function () { + it('calls logViewPromotion', async function () { + const { getAnalytics, logViewPromotion } = analyticsModular; + await logViewPromotion(getAnalytics(), { + creative_name: 'creative_name', + creative_slot: 'creative_slot', + }); }); }); - }); - describe('logAddPaymentInfo()', function () { - it('calls logAddPaymentInfo', async function () { - const { getAnalytics, logAddPaymentInfo } = analyticsModular; - await logAddPaymentInfo(getAnalytics(), { - value: 123, - currency: 'USD', - items: [], + describe('logGenerateLead()', function () { + it('calls logGenerateLead', async function () { + const { getAnalytics, logGenerateLead } = analyticsModular; + await logGenerateLead(getAnalytics(), { + currency: 'USD', + value: 123, + }); }); }); - }); - describe('logAddToCart()', function () { - it('calls logAddToCart', async function () { - const { getAnalytics, logAddToCart } = analyticsModular; - await logAddToCart(getAnalytics(), { - value: 123, - currency: 'GBP', + describe('logJoinGroup()', function () { + it('calls logJoinGroup', async function () { + const { getAnalytics, logJoinGroup } = analyticsModular; + await logJoinGroup(getAnalytics(), { + group_id: '123', + }); }); }); - }); - describe('logAddShippingInfo()', function () { - it('calls logAddShippingInfo', async function () { - const { getAnalytics, logAddShippingInfo } = analyticsModular; - await logAddShippingInfo(getAnalytics(), { - value: 123, - currency: 'GBP', + describe('logLevelEnd()', function () { + it('calls logLevelEnd', async function () { + const { getAnalytics, logLevelEnd } = analyticsModular; + await logLevelEnd(getAnalytics(), { + level: 123, + success: 'yes', + }); }); }); - }); - describe('logAddToWishlist()', function () { - it('calls logAddToWishlist', async function () { - const { getAnalytics, logAddToWishlist } = analyticsModular; - await logAddToWishlist(getAnalytics(), { - items: [ - { - item_id: 'foo', - item_name: 'foo', - item_category: 'foo', - item_location_id: 'foo', - quantity: 5, - }, - ], - value: 123, - currency: 'GBP', + describe('logLevelStart()', function () { + it('calls logLevelEnd', async function () { + const { getAnalytics, logLevelStart } = analyticsModular; + await logLevelStart(getAnalytics(), { + level: 123, + }); }); }); - }); - describe('logAppOpen()', function () { - it('calls logAppOpen', async function () { - const { getAnalytics, logAppOpen } = analyticsModular; - await logAppOpen(getAnalytics()); + describe('logLevelUp()', function () { + it('calls logLevelUp', async function () { + const { getAnalytics, logLevelUp } = analyticsModular; + await logLevelUp(getAnalytics(), { + level: 123, + character: 'foo', + }); + }); }); - }); - describe('logBeginCheckout()', function () { - it('calls logBeginCheckout', async function () { - const { getAnalytics, logBeginCheckout } = analyticsModular; - await logBeginCheckout(getAnalytics()); + describe('logLogin()', function () { + it('calls logLogin', async function () { + const { getAnalytics, logLogin } = analyticsModular; + await logLogin(getAnalytics(), { + method: 'facebook.com', + }); + }); }); - }); - describe('logCampaignDetails()', function () { - it('calls logCampaignDetails', async function () { - const { getAnalytics, logCampaignDetails } = analyticsModular; - await logCampaignDetails(getAnalytics(), { - source: 'foo', - medium: 'bar', - campaign: 'baz', + describe('logPostScore()', function () { + it('calls logPostScore', async function () { + const { getAnalytics, logPostScore } = analyticsModular; + await logPostScore(getAnalytics(), { + score: 123, + }); }); }); - }); - describe('logEarnVirtualCurrency()', function () { - it('calls logEarnVirtualCurrency', async function () { - const { getAnalytics, logEarnVirtualCurrency } = analyticsModular; - await logEarnVirtualCurrency(getAnalytics(), { - virtual_currency_name: 'foo', - value: 123, + describe('logRemoveFromCart()', function () { + it('calls logRemoveFromCart', async function () { + const { getAnalytics, logRemoveFromCart } = analyticsModular; + await logRemoveFromCart(getAnalytics(), { + value: 123, + currency: 'USD', + }); }); }); - }); - describe('logPurchase()', function () { - it('calls logPurchase', async function () { - const { getAnalytics, logPurchase } = analyticsModular; - await logPurchase(getAnalytics(), { - currency: 'USD', - value: 123, - affiliation: 'affiliation', + describe('logSearch()', function () { + it('calls logSearch', async function () { + const { getAnalytics, logSearch } = analyticsModular; + await logSearch(getAnalytics(), { + search_term: 'foo', + }); }); }); - }); - describe('logViewPromotion()', function () { - it('calls logViewPromotion', async function () { - const { getAnalytics, logViewPromotion } = analyticsModular; - await logViewPromotion(getAnalytics(), { - creative_name: 'creative_name', - creative_slot: 'creative_slot', + describe('logSetCheckoutOption()', function () { + it('calls logSelectContent', async function () { + const { getAnalytics, logSetCheckoutOption } = analyticsModular; + await logSetCheckoutOption(getAnalytics(), { + checkout_step: 123, + checkout_option: 'foo', + }); }); }); - }); - describe('logGenerateLead()', function () { - it('calls logGenerateLead', async function () { - const { getAnalytics, logGenerateLead } = analyticsModular; - await logGenerateLead(getAnalytics(), { - currency: 'USD', - value: 123, + describe('logSelectItem()', function () { + it('calls logSelectItem', async function () { + const { getAnalytics, logSelectItem } = analyticsModular; + await logSelectItem(getAnalytics(), { + item_list_id: 'foo', + item_list_name: 'foo', + content_type: 'foo', + }); }); }); - }); - describe('logJoinGroup()', function () { - it('calls logJoinGroup', async function () { - const { getAnalytics, logJoinGroup } = analyticsModular; - await logJoinGroup(getAnalytics(), { - group_id: '123', + describe('logShare()', function () { + it('calls logShare', async function () { + const { getAnalytics, logShare } = analyticsModular; + await logShare(getAnalytics(), { + content_type: 'foo', + item_id: 'foo', + method: 'foo', + }); }); }); - }); - describe('logLevelEnd()', function () { - it('calls logLevelEnd', async function () { - const { getAnalytics, logLevelEnd } = analyticsModular; - await logLevelEnd(getAnalytics(), { - level: 123, - success: 'yes', + describe('logSignUp()', function () { + it('calls logSignUp', async function () { + const { getAnalytics, logSignUp } = analyticsModular; + await logSignUp(getAnalytics(), { + method: 'facebook.com', + }); }); }); - }); - describe('logLevelStart()', function () { - it('calls logLevelEnd', async function () { - const { getAnalytics, logLevelStart } = analyticsModular; - await logLevelStart(getAnalytics(), { - level: 123, + describe('logSpendVirtualCurrency()', function () { + it('calls logSpendVirtualCurrency', async function () { + const { getAnalytics, logSpendVirtualCurrency } = analyticsModular; + await logSpendVirtualCurrency(getAnalytics(), { + item_name: 'foo', + virtual_currency_name: 'foo', + value: 123, + }); }); }); - }); - describe('logLevelUp()', function () { - it('calls logLevelUp', async function () { - const { getAnalytics, logLevelUp } = analyticsModular; - await logLevelUp(getAnalytics(), { - level: 123, - character: 'foo', + describe('logTutorialBegin()', function () { + it('calls logTutorialBegin', async function () { + const { getAnalytics, logTutorialBegin } = analyticsModular; + await logTutorialBegin(getAnalytics()); }); }); - }); - describe('logLogin()', function () { - it('calls logLogin', async function () { - const { getAnalytics, logLogin } = analyticsModular; - await logLogin(getAnalytics(), { - method: 'facebook.com', + describe('logTutorialComplete()', function () { + it('calls logTutorialComplete', async function () { + const { getAnalytics, logTutorialComplete } = analyticsModular; + await logTutorialComplete(getAnalytics()); }); }); - }); - describe('logPostScore()', function () { - it('calls logPostScore', async function () { - const { getAnalytics, logPostScore } = analyticsModular; - await logPostScore(getAnalytics(), { - score: 123, + describe('logUnlockAchievement()', function () { + it('calls logUnlockAchievement', async function () { + const { getAnalytics, logUnlockAchievement } = analyticsModular; + await logUnlockAchievement(getAnalytics(), { + achievement_id: 'foo', + }); }); }); - }); - describe('logRemoveFromCart()', function () { - it('calls logRemoveFromCart', async function () { - const { getAnalytics, logRemoveFromCart } = analyticsModular; - await logRemoveFromCart(getAnalytics(), { - value: 123, - currency: 'USD', + describe('logViewCart()', function () { + it('calls logViewCart', async function () { + const { getAnalytics, logViewCart } = analyticsModular; + await logViewCart(getAnalytics()); }); }); - }); - describe('logSearch()', function () { - it('calls logSearch', async function () { - const { getAnalytics, logSearch } = analyticsModular; - await logSearch(getAnalytics(), { - search_term: 'foo', + describe('logViewItem()', function () { + it('calls logViewItem', async function () { + const { getAnalytics, logViewItem } = analyticsModular; + await logViewItem(getAnalytics(), { + items: [ + { + item_id: 'foo', + item_name: 'foo', + item_category: 'foo', + item_location_id: 'foo', + }, + ], + value: 123, + currency: 'GBP', + }); }); }); - }); - describe('logSetCheckoutOption()', function () { - it('calls logSelectContent', async function () { - const { getAnalytics, logSetCheckoutOption } = analyticsModular; - await logSetCheckoutOption(getAnalytics(), { - checkout_step: 123, - checkout_option: 'foo', + describe('logViewItemList()', function () { + it('calls logViewItemList', async function () { + const { getAnalytics, logViewItemList } = analyticsModular; + await logViewItemList(getAnalytics(), { + item_list_name: 'foo', + items: [ + { + item_id: 'foo', + item_name: 'foo', + item_category: 'foo', + item_location_id: 'foo', + price: 123, + }, + ], + }); }); }); - }); - describe('logSelectItem()', function () { - it('calls logSelectItem', async function () { - const { getAnalytics, logSelectItem } = analyticsModular; - await logSelectItem(getAnalytics(), { - item_list_id: 'foo', - item_list_name: 'foo', - content_type: 'foo', + describe('logRefund()', function () { + it('calls logRefund', async function () { + const { getAnalytics, logRefund } = analyticsModular; + await logRefund(getAnalytics(), { + affiliation: 'affiliation', + coupon: 'coupon', + }); }); }); - }); - describe('logShare()', function () { - it('calls logShare', async function () { - const { getAnalytics, logShare } = analyticsModular; - await logShare(getAnalytics(), { - content_type: 'foo', - item_id: 'foo', - method: 'foo', + describe('logSelectContent()', function () { + it('calls logSelectContent', async function () { + const { getAnalytics, logSelectContent } = analyticsModular; + await logSelectContent(getAnalytics(), { + content_type: 'clothing', + item_id: 'abcd', + }); }); }); - }); - describe('logSignUp()', function () { - it('calls logSignUp', async function () { - const { getAnalytics, logSignUp } = analyticsModular; - await logSignUp(getAnalytics(), { - method: 'facebook.com', + describe('logSelectPromotion()', function () { + it('calls logSelectPromotion', async function () { + const { getAnalytics, logSelectPromotion } = analyticsModular; + await logSelectPromotion(getAnalytics(), { + creative_name: 'string', + creative_slot: 'string', + location_id: 'string', + promotion_id: 'string', + promotion_name: 'string', + }); }); }); - }); - describe('logSpendVirtualCurrency()', function () { - it('calls logSpendVirtualCurrency', async function () { - const { getAnalytics, logSpendVirtualCurrency } = analyticsModular; - await logSpendVirtualCurrency(getAnalytics(), { - item_name: 'foo', - virtual_currency_name: 'foo', - value: 123, + describe('logViewSearchResults()', function () { + it('calls logViewSearchResults', async function () { + const { getAnalytics, logViewSearchResults } = analyticsModular; + await logViewSearchResults(getAnalytics(), { + search_term: 'promotion', + }); }); }); }); - describe('logTutorialBegin()', function () { - it('calls logTutorialBegin', async function () { - const { getAnalytics, logTutorialBegin } = analyticsModular; - await logTutorialBegin(getAnalytics()); + describe('setSessionTimeoutDuration()', function () { + it('default duration', async function () { + const { getAnalytics, setSessionTimeoutDuration } = analyticsModular; + await setSessionTimeoutDuration(getAnalytics()); }); - }); - describe('logTutorialComplete()', function () { - it('calls logTutorialComplete', async function () { - const { getAnalytics, logTutorialComplete } = analyticsModular; - await logTutorialComplete(getAnalytics()); + xit('custom duration', async function () { + const { getAnalytics, setSessionTimeoutDuration } = analyticsModular; + // TODO: worked on Detox v17, causes crash after transition to v18. Why? + await setSessionTimeoutDuration(getAnalytics(), 13371337); }); }); - describe('logUnlockAchievement()', function () { - it('calls logUnlockAchievement', async function () { - const { getAnalytics, logUnlockAchievement } = analyticsModular; - await logUnlockAchievement(getAnalytics(), { - achievement_id: 'foo', - }); + describe('getAppInstanceId()', function () { + it('calls native fn without error', async function () { + const { getAnalytics, getAppInstanceId } = analyticsModular; + await getAppInstanceId(getAnalytics()); }); }); - describe('logViewCart()', function () { - it('calls logViewCart', async function () { - const { getAnalytics, logViewCart } = analyticsModular; - await logViewCart(getAnalytics()); + describe('getSessionId()', function () { + it('calls native fn without error', async function () { + const { getAnalytics, getSessionId } = analyticsModular; + await getSessionId(getAnalytics()); }); - }); - describe('logViewItem()', function () { - it('calls logViewItem', async function () { - const { getAnalytics, logViewItem } = analyticsModular; - await logViewItem(getAnalytics(), { - items: [ - { - item_id: 'foo', - item_name: 'foo', - item_category: 'foo', - item_location_id: 'foo', - }, - ], - value: 123, - currency: 'GBP', - }); + it('returns a non empty session ID', async function () { + if (Platform.other) { + this.skip(); + } + const { getAnalytics, getSessionId } = analyticsModular; + let sessionId = await getSessionId(getAnalytics()); + // On iOS it can take ~ 3 minutes for the session ID to be generated + // Otherwise, `Analytics uninitialized` error will be thrown + const retries = 240; + while (!sessionId && retries > 0) { + await Utils.sleep(1000); + sessionId = await getSessionId(getAnalytics()); + } + + if (!sessionId) { + return Promise.reject( + new Error('Firebase SDK did not return a session ID after 4 minutes'), + ); + } + + sessionId.should.not.equal(0); }); - }); - describe('logViewItemList()', function () { - it('calls logViewItemList', async function () { - const { getAnalytics, logViewItemList } = analyticsModular; - await logViewItemList(getAnalytics(), { - item_list_name: 'foo', - items: [ - { - item_id: 'foo', - item_name: 'foo', - item_category: 'foo', - item_location_id: 'foo', - price: 123, - }, - ], - }); + it('returns a null value if session expires', async function () { + const { getAnalytics, getSessionId, setSessionTimeoutDuration } = analyticsModular; + // Set session duration to 1 millisecond + setSessionTimeoutDuration(getAnalytics(), 1); + // Wait 100 millisecond to ensure session expires + await Utils.sleep(100); + const sessionId = await getSessionId(getAnalytics()); + should.equal(sessionId, null); }); }); - describe('logRefund()', function () { - it('calls logRefund', async function () { - const { getAnalytics, logRefund } = analyticsModular; - await logRefund(getAnalytics(), { - affiliation: 'affiliation', - coupon: 'coupon', - }); + describe('setUserId()', function () { + it('allows a null values to be set', async function () { + const { getAnalytics, setUserId } = analyticsModular; + await setUserId(getAnalytics(), null); }); - }); - describe('logSelectContent()', function () { - it('calls logSelectContent', async function () { - const { getAnalytics, logSelectContent } = analyticsModular; - await logSelectContent(getAnalytics(), { - content_type: 'clothing', - item_id: 'abcd', - }); + it('accepts string values', async function () { + const { getAnalytics, setUserId } = analyticsModular; + await setUserId(getAnalytics(), 'rn-firebase'); }); }); - describe('logSelectPromotion()', function () { - it('calls logSelectPromotion', async function () { - const { getAnalytics, logSelectPromotion } = analyticsModular; - await logSelectPromotion(getAnalytics(), { - creative_name: 'string', - creative_slot: 'string', - location_id: 'string', - promotion_id: 'string', - promotion_name: 'string', - }); + describe('setUserProperty()', function () { + it('allows a null values to be set', async function () { + const { getAnalytics, setUserProperty } = analyticsModular; + await setUserProperty(getAnalytics(), 'invertase', null); + }); + + it('accepts string values', async function () { + const { getAnalytics, setUserProperty } = analyticsModular; + await setUserProperty(getAnalytics(), 'invertase2', 'rn-firebase'); }); }); - describe('logViewSearchResults()', function () { - it('calls logViewSearchResults', async function () { - const { getAnalytics, logViewSearchResults } = analyticsModular; - await logViewSearchResults(getAnalytics(), { - search_term: 'promotion', - }); + describe('setUserProperties()', function () { + it('allows null values to be set', async function () { + const { getAnalytics, setUserProperties } = analyticsModular; + await setUserProperties(getAnalytics(), { invertase2: null }); + }); + + it('accepts string values', async function () { + const { getAnalytics, setUserProperties } = analyticsModular; + await setUserProperties(getAnalytics(), { invertase3: 'rn-firebase' }); }); });