https://github.com/alex-mobvantage/react-native-gaid
React Native plugin for fetching the Google Advertising ID
https://github.com/alex-mobvantage/react-native-gaid
google-advertising-id plugin react react-native
Last synced: over 1 year ago
JSON representation
React Native plugin for fetching the Google Advertising ID
- Host: GitHub
- URL: https://github.com/alex-mobvantage/react-native-gaid
- Owner: alex-mobvantage
- License: mit
- Created: 2016-12-07T00:00:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-05-24T20:53:56.000Z (about 4 years ago)
- Last Synced: 2024-08-10T20:34:03.898Z (almost 2 years ago)
- Topics: google-advertising-id, plugin, react, react-native
- Language: Java
- Homepage:
- Size: 3.91 KB
- Stars: 7
- Watchers: 1
- Forks: 24
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-gaid
Gets the Google Advertising ID for [React Native](https://github.com/facebook/react-native)
## Install
```shell
npm install --save react-native-gaid
```
## Automatically link
#### With React Native 0.27+
```shell
react-native link react-native-gaid
```
#### With older versions of React Native
You need [`rnpm`](https://github.com/rnpm/rnpm) (`npm install -g rnpm`)
```shell
rnpm link react-native-gaid
```
## Manually link
- in `android/app/build.gradle`:
```diff
dependencies {
...
compile "com.facebook.react:react-native:+" // From node_modules
+ compile project(':react-native-gaid')
}
```
- in `android/settings.gradle`:
```diff
...
include ':app'
+ include ':react-native-gaid'
+ project(':react-native-gaid').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gaid/android')
```
#### With React Native 0.29+
- in `MainApplication.java`:
```diff
+ import com.mobvantage.react.gaid.RNGaidPackage;
public class MainApplication extends Application implements ReactApplication {
//......
@Override
protected List getPackages() {
return Arrays.asList(
+ new RNGaidPackage(),
new MainReactPackage()
);
}
......
}
```
#### With older versions of React Native:
- in `MainActivity.java`:
```diff
+ import com.mobvantage.react.gaid.RNGaidPackage;
public class MainActivity extends ReactActivity {
......
@Override
protected List getPackages() {
return Arrays.asList(
+ new RNGaidPackage(),
new MainReactPackage()
);
}
}
```
## Example
```js
import GAID from 'react-native-gaid';
GAID.getAdvertisingInfo().then(info => {
console.log('Google Advertising ID', info.advertisingId);
console.log('Is Limit Ad Tracking Enabled', info.isLimitAdTrackingEnabled);
})
.catch(err => {
console.log('Something went wrong', err);
});
```