Gets the Google Advertising ID for React Native
npm install --save react-native-gaidreact-native link react-native-gaidYou need rnpm (npm install -g rnpm)
rnpm link react-native-gaid- in
android/app/build.gradle:
dependencies {
...
compile "com.facebook.react:react-native:+" // From node_modules
+ compile project(':react-native-gaid')
}- in
android/settings.gradle:
...
include ':app'
+ include ':react-native-gaid'
+ project(':react-native-gaid').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gaid/android')- in
MainApplication.java:
+ import com.mobvantage.react.gaid.RNGaidPackage;
public class MainApplication extends Application implements ReactApplication {
//......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNGaidPackage(),
new MainReactPackage()
);
}
......
}- in
MainActivity.java:
+ import com.mobvantage.react.gaid.RNGaidPackage;
public class MainActivity extends ReactActivity {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
+ new RNGaidPackage(),
new MainReactPackage()
);
}
}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);
});