Skip to content

Commit 1ce9eb6

Browse files
authored
refactor(supported-platforms): Remove React Native Support (#364)
* refactor(supported-platforms): Remove React Native Support BREAKING CHANGES: Removed support for React Native We recently released an entirely new SDK focused entirely on React Native support, this can be found at https://github.com/amplitude/Amplitude-ReactNative. We will be writing a migration guide for users looking to move to the new React Native SDK. * docs(platform-support): Fix nits in documentation * docs: Add migration guide for react native to readme
1 parent 777dead commit 1ce9eb6

14 files changed

+71
-549
lines changed

.eslintrc.json

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"mocha/no-exclusive-tests": "error"
1313
},
1414
"globals": {
15-
"BUILD_COMPAT_REACT_NATIVE": "readonly",
1615
"BUILD_COMPAT_LOCAL_STORAGE": "readonly",
1716
"BUILD_COMPAT_SNIPPET": "readonly",
1817
"BUILD_COMPAT_2_0": "readonly",

.github/ISSUE_TEMPLATE/Bug_report.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ labels: 'bug'
1616
<!--- (Not obligatory) Suggest a fix/reason -->
1717

1818
## Steps to Reproduce
19-
<!--- Please provide a clear sequence of steps to reproduce this bug -->
19+
<!--- Please provide a clear sequence of steps to reproduce this bug -->
2020
<!--- Include code and images, if relevant -->
2121
1.
2222
2.
@@ -26,4 +26,4 @@ labels: 'bug'
2626
## Environment
2727
- JS SDK Version: <!--- E.g. 7.1.0 -->
2828
- Installation Method: <!-- I.e. NPM/Yarn or <script> import -->
29-
- Browser and Version or React Native and Device: <!-- E.g. Chrome 84, React Native@0.63 iPhone SE-->
29+
- Browser and Version: <!-- E.g. Chrome 84-->

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ amplitude.js
1010
amplitude.esm.js
1111
amplitude.min.js
1212
amplitude-snippet.min.js
13-
amplitude.native.js
1413
amplitude-segment-snippet.min.js
1514
.watchmanconfig
1615
package-lock.json

Makefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ README.md: $(SNIPPET_OUT) version
6363
# Target for `amplitude.js` file.
6464
#
6565

66-
$(OUT): node_modules $(SRC) package.json rollup.config.js rollup.min.js rollup.native.js rollup.esm.js rollup.umd.js rollup.umd.min.js
66+
$(OUT): node_modules $(SRC) package.json rollup.config.js rollup.min.js rollup.esm.js rollup.umd.js rollup.umd.min.js
6767
@NODE_ENV=production $(ROLLUP) --config rollup.config.js # is the snippet build config
6868
@NODE_ENV=production $(ROLLUP) --config rollup.esm.js # does not concat dependencies, only has module and dependencies
6969
@NODE_ENV=production $(ROLLUP) --config rollup.umd.js # generates npm version, also usable in require js app
70-
@NODE_ENV=production $(ROLLUP) --config rollup.native.js # generates react native build
7170
@NODE_ENV=production $(ROLLUP) --config rollup.umd.min.js
7271
@NODE_ENV=production $(ROLLUP) --config rollup.min.js
7372

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ A JavaScript SDK for tracking events and revenue to [Amplitude](https://www.ampl
2626
* A [demo page](https://github.com/amplitude/GTM-Web-Demo) demonstrating a potential integration with Google Tag Manager.
2727

2828

29-
## React Native
30-
This library now supports react-native. It has two dependencies on react-native modules you will have to install yourself:
29+
## Deprecated - React Native
30+
As of >= v8.0.0, this SDK no longer has support for React Native. We recently released a new SDK focused on providing a React Native first approach to using Amplitude in cross-platform projects. [Amplitude React Native SDK](https://github.com/amplitude/Amplitude-ReactNative)
3131

32-
* [react-native-device-info](https://www.npmjs.com/package/react-native-device-info) Tested with version 3.1.4
33-
* [@react-native-async-storage/async-storage](https://www.npmjs.com/package/@react-native-async-storage/async-storage) Tested with version 1.6.2
32+
Previously used amplitude-js and looking to migrate to @amplitude/react-native?
33+
* Please follow the steps detailed in our [migration guide](https://github.com/amplitude/Amplitude-ReactNative/blob/main/MIGRATION_GUIDE.md)
3434

3535
## Node.js
3636
Please visit [Amplitude-Node](https://github.com/amplitude/Amplitude-Node) for our Node SDK.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"url": "https://github.com/amplitude/amplitude-javascript.git"
1414
},
1515
"main": "amplitude.umd.js",
16-
"react-native": "amplitude.native.js",
1716
"dependencies": {
1817
"@amplitude/ua-parser-js": "0.7.24",
1918
"@amplitude/utils": "^1.0.5",

rollup.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export default {
2727
BUILD_COMPAT_SNIPPET: 'true',
2828
BUILD_COMPAT_LOCAL_STORAGE: 'true',
2929
BUILD_COMPAT_2_0: 'true',
30-
BUILD_COMPAT_REACT_NATIVE: 'false',
3130
}),
3231
commonjs(),
3332
],

rollup.esm.js

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export default {
2424
BUILD_COMPAT_SNIPPET: 'false',
2525
BUILD_COMPAT_LOCAL_STORAGE: 'true',
2626
BUILD_COMPAT_2_0: 'true',
27-
BUILD_COMPAT_REACT_NATIVE: 'false',
2827
}),
2928
commonjs({
3029
include: "node_modules/**"

rollup.native.js

-31
This file was deleted.

rollup.umd.js

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export default {
2727
BUILD_COMPAT_SNIPPET: 'true',
2828
BUILD_COMPAT_LOCAL_STORAGE: 'true',
2929
BUILD_COMPAT_2_0: 'true',
30-
BUILD_COMPAT_REACT_NATIVE: 'false',
3130
}),
3231
commonjs(),
3332
],

src/amplitude-client.js

+21-163
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ import DEFAULT_OPTIONS from './options';
1919
import getHost from './get-host';
2020
import baseCookie from './base-cookie';
2121

22-
let AsyncStorage;
23-
let Platform;
24-
let DeviceInfo;
25-
if (BUILD_COMPAT_REACT_NATIVE) {
26-
const reactNative = require('react-native');
27-
AsyncStorage = require('@react-native-async-storage/async-storage').default;
28-
Platform = reactNative.Platform;
29-
DeviceInfo = require('react-native-device-info');
30-
}
31-
3222
/**
3323
* AmplitudeClient SDK API - instance constructor.
3424
* The Amplitude class handles creation of client instances, all you need to do is call amplitude.getInstance()
@@ -203,75 +193,18 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
203193
this._isInitialized = true;
204194
};
205195

206-
if (AsyncStorage) {
207-
this._migrateUnsentEvents(() => {
208-
Promise.all([
209-
AsyncStorage.getItem(this._storageSuffix),
210-
AsyncStorage.getItem(this.options.unsentKey + this._storageSuffix),
211-
AsyncStorage.getItem(this.options.unsentIdentifyKey + this._storageSuffix),
212-
])
213-
.then((values) => {
214-
if (values[0]) {
215-
const cookieData = JSON.parse(values[0]);
216-
if (cookieData) {
217-
_loadCookieDataProps(this, cookieData);
218-
}
219-
}
220-
if (this.options.saveEvents) {
221-
this._unsentEvents = this._parseSavedUnsentEventsString(values[1])
222-
.map((event) => ({ event }))
223-
.concat(this._unsentEvents);
224-
this._unsentIdentifys = this._parseSavedUnsentEventsString(values[2])
225-
.map((event) => ({ event }))
226-
.concat(this._unsentIdentifys);
227-
}
228-
if (DeviceInfo) {
229-
Promise.all([
230-
DeviceInfo.getCarrier(),
231-
DeviceInfo.getModel(),
232-
DeviceInfo.getManufacturer(),
233-
DeviceInfo.getVersion(),
234-
DeviceInfo.getUniqueId(),
235-
])
236-
.then((values) => {
237-
this.deviceInfo = {
238-
carrier: values[0],
239-
model: values[1],
240-
manufacturer: values[2],
241-
version: values[3],
242-
};
243-
initFromStorage(values[4]);
244-
this.runQueuedFunctions();
245-
if (type(opt_callback) === 'function') {
246-
opt_callback(this);
247-
}
248-
})
249-
.catch((err) => {
250-
this.options.onError(err);
251-
});
252-
} else {
253-
initFromStorage();
254-
this.runQueuedFunctions();
255-
}
256-
})
257-
.catch((err) => {
258-
this.options.onError(err);
259-
});
260-
});
261-
} else {
262-
if (this.options.saveEvents) {
263-
this._unsentEvents = this._loadSavedUnsentEvents(this.options.unsentKey)
264-
.map((event) => ({ event }))
265-
.concat(this._unsentEvents);
266-
this._unsentIdentifys = this._loadSavedUnsentEvents(this.options.unsentIdentifyKey)
267-
.map((event) => ({ event }))
268-
.concat(this._unsentIdentifys);
269-
}
270-
initFromStorage();
271-
this.runQueuedFunctions();
272-
if (type(opt_callback) === 'function') {
273-
opt_callback(this);
274-
}
196+
if (this.options.saveEvents) {
197+
this._unsentEvents = this._loadSavedUnsentEvents(this.options.unsentKey)
198+
.map((event) => ({ event }))
199+
.concat(this._unsentEvents);
200+
this._unsentIdentifys = this._loadSavedUnsentEvents(this.options.unsentIdentifyKey)
201+
.map((event) => ({ event }))
202+
.concat(this._unsentIdentifys);
203+
}
204+
initFromStorage();
205+
this.runQueuedFunctions();
206+
if (type(opt_callback) === 'function') {
207+
opt_callback(this);
275208
}
276209
} catch (err) {
277210
utils.log.error(err);
@@ -341,53 +274,6 @@ const _validateUnsentEventQueue = (queue) => {
341274
}
342275
};
343276

344-
/**
345-
* @private
346-
*/
347-
AmplitudeClient.prototype._migrateUnsentEvents = function _migrateUnsentEvents(cb) {
348-
Promise.all([AsyncStorage.getItem(this.options.unsentKey), AsyncStorage.getItem(this.options.unsentIdentifyKey)])
349-
.then((values) => {
350-
if (this.options.saveEvents) {
351-
var unsentEventsString = values[0];
352-
var unsentIdentifyKey = values[1];
353-
354-
var itemsToSet = [];
355-
var itemsToRemove = [];
356-
357-
if (unsentEventsString) {
358-
itemsToSet.push(
359-
AsyncStorage.setItem(this.options.unsentKey + this._storageSuffix, JSON.stringify(unsentEventsString)),
360-
);
361-
itemsToRemove.push(AsyncStorage.removeItem(this.options.unsentKey));
362-
}
363-
364-
if (unsentIdentifyKey) {
365-
itemsToSet.push(
366-
AsyncStorage.setItem(
367-
this.options.unsentIdentifyKey + this._storageSuffix,
368-
JSON.stringify(unsentIdentifyKey),
369-
),
370-
);
371-
itemsToRemove.push(AsyncStorage.removeItem(this.options.unsentIdentifyKey));
372-
}
373-
374-
if (itemsToSet.length > 0) {
375-
Promise.all(itemsToSet)
376-
.then(() => {
377-
Promise.all(itemsToRemove);
378-
})
379-
.catch((err) => {
380-
this.options.onError(err);
381-
});
382-
}
383-
}
384-
})
385-
.then(cb)
386-
.catch((err) => {
387-
this.options.onError(err);
388-
});
389-
};
390-
391277
/**
392278
* @private
393279
*/
@@ -721,9 +607,6 @@ var _saveCookieData = function _saveCookieData(scope) {
721607
identifyId: scope._identifyId,
722608
sequenceNumber: scope._sequenceNumber,
723609
};
724-
if (AsyncStorage) {
725-
AsyncStorage.setItem(scope._storageSuffix, JSON.stringify(cookieData));
726-
}
727610

728611
if (scope._useOldCookie) {
729612
scope.cookieStorage.set(scope.options.cookieName + scope._storageSuffix, cookieData);
@@ -872,21 +755,13 @@ AmplitudeClient.prototype.saveEvents = function saveEvents() {
872755
try {
873756
const serializedUnsentEvents = JSON.stringify(this._unsentEvents.map(({ event }) => event));
874757

875-
if (AsyncStorage) {
876-
AsyncStorage.setItem(this.options.unsentKey + this._storageSuffix, serializedUnsentEvents);
877-
} else {
878-
this._setInStorage(localStorage, this.options.unsentKey, serializedUnsentEvents);
879-
}
758+
this._setInStorage(localStorage, this.options.unsentKey, serializedUnsentEvents);
880759
} catch (e) {} /* eslint-disable-line no-empty */
881760

882761
try {
883762
const serializedIdentifys = JSON.stringify(this._unsentIdentifys.map((unsentIdentify) => unsentIdentify.event));
884763

885-
if (AsyncStorage) {
886-
AsyncStorage.setItem(this.options.unsentIdentifyKey + this._storageSuffix, serializedIdentifys);
887-
} else {
888-
this._setInStorage(localStorage, this.options.unsentIdentifyKey, serializedIdentifys);
889-
}
764+
this._setInStorage(localStorage, this.options.unsentIdentifyKey, serializedIdentifys);
890765
} catch (e) {} /* eslint-disable-line no-empty */
891766
};
892767

@@ -1260,9 +1135,8 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
12601135
timestamp,
12611136
callback,
12621137
) {
1263-
if (!BUILD_COMPAT_REACT_NATIVE) {
1264-
_loadCookieData(this); // reload cookie before each log event to sync event meta-data between windows and tabs
1265-
}
1138+
_loadCookieData(this); // reload cookie before each log event to sync event meta-data between windows and tabs
1139+
12661140
if (!eventType) {
12671141
if (type(callback) === 'function') {
12681142
callback(0, 'No request sent', { reason: 'Missing eventType' });
@@ -1291,23 +1165,9 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
12911165
this._lastEventTime = eventTime;
12921166
_saveCookieData(this);
12931167

1294-
let osName = this._ua.browser.name;
1295-
let osVersion = this._ua.browser.major;
1296-
let deviceModel = this._ua.os.name;
1297-
let deviceManufacturer;
1298-
1299-
let versionName;
1300-
let carrier;
1301-
if (BUILD_COMPAT_REACT_NATIVE) {
1302-
osName = Platform.OS;
1303-
osVersion = Platform.Version;
1304-
if (this.deviceInfo) {
1305-
carrier = this.deviceInfo.carrier;
1306-
deviceManufacturer = this.deviceInfo.manufacturer;
1307-
deviceModel = this.deviceInfo.model;
1308-
versionName = this.deviceInfo.version;
1309-
}
1310-
}
1168+
const osName = this._ua.browser.name;
1169+
const osVersion = this._ua.browser.major;
1170+
const deviceModel = this._ua.os.name;
13111171

13121172
userProperties = userProperties || {};
13131173
var trackingOptions = { ...this._apiPropertiesTrackingOptions };
@@ -1322,20 +1182,18 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
13221182
event_id: eventId,
13231183
session_id: this._sessionId || -1,
13241184
event_type: eventType,
1325-
version_name: _shouldTrackField(this, 'version_name') ? this.options.versionName || versionName || null : null,
1185+
version_name: this.options.versionName || null,
13261186
platform: _shouldTrackField(this, 'platform') ? this.options.platform : null,
13271187
os_name: _shouldTrackField(this, 'os_name') ? osName || null : null,
13281188
os_version: _shouldTrackField(this, 'os_version') ? osVersion || null : null,
13291189
device_model: _shouldTrackField(this, 'device_model') ? deviceModel || null : null,
1330-
device_manufacturer: _shouldTrackField(this, 'device_manufacturer') ? deviceManufacturer || null : null,
13311190
language: _shouldTrackField(this, 'language') ? this.options.language : null,
1332-
carrier: _shouldTrackField(this, 'carrier') ? carrier || null : null,
13331191
api_properties: apiProperties,
13341192
event_properties: utils.truncate(utils.validateProperties(eventProperties)),
13351193
user_properties: utils.truncate(utils.validateProperties(userProperties)),
13361194
uuid: UUID(),
13371195
library: {
1338-
name: BUILD_COMPAT_REACT_NATIVE ? 'amplitude-react-native' : 'amplitude-js',
1196+
name: 'amplitude-js',
13391197
version: version,
13401198
},
13411199
sequence_number: sequenceNumber, // for ordering events and identifys

src/metadata-storage.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ class MetadataStorage {
3535

3636
this.cookieDomain = '';
3737

38-
if (!BUILD_COMPAT_REACT_NATIVE) {
39-
const writableTopDomain = topDomain(getLocation().href);
40-
this.cookieDomain = domain || (writableTopDomain ? '.' + writableTopDomain : null);
41-
}
38+
const writableTopDomain = topDomain(getLocation().href);
39+
this.cookieDomain = domain || (writableTopDomain ? '.' + writableTopDomain : null);
4240

4341
if (storageOptionExists[storage]) {
4442
this.storage = storage;

0 commit comments

Comments
 (0)