Skip to content

alex-mobvantage/react-native-gaid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-gaid

Gets the Google Advertising ID for React Native

Install

npm install --save react-native-gaid

Automatically link

With React Native 0.27+

react-native link react-native-gaid

With older versions of React Native

You need rnpm (npm install -g rnpm)

rnpm link react-native-gaid

Manually link

  • 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')

With React Native 0.29+

  • 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()
      );
    }

    ......
  }

With older versions of React Native:

  • 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()
      );
    }
  }

Example

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);
});

About

React Native plugin for fetching the Google Advertising ID

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published