GuidesDiscussions
Log In
Guides

Opt-in/out

Optional opt-in and out from Ads

Step 19 : Opt-In / Opt-Out settings [OPTIONAL] :

The host application can provide an option to the users to Opt-In and Opt-Out of the Ads services. The same can be accomplished via the following methods to access or update the Status.

19.1 : Update Opt-In Status for Monetization

// import Module from IU lib
import { NativeModules } from 'react-native';
const { IuLibraryModule } = NativeModules;
const App: () => Node = () => {
	....
    // Start of Updating Opt in value

    const [switchValue, setSwitchValue] = useState(false);

    const toggleSwitch = (value) => {
        //To handle switch toggle
        setSwitchValue(value);
        IuLibraryModule.updateOptInStatus(value);
        //State changes according to switch
    };
    // End of Updating Opt in value
    ...
}

The method accepts boolean value. When TRUE is passed, the user is Opted-In to the Ad services and when FALSE is passed, the user is Opted-Out of the Ad Service.

19.2 : Get Opt-In status for Monetization

// import Module from IU lib
import { NativeModules } from 'react-native';
const { IuLibraryModule } = NativeModules;
const App: () => Node = () => {
  ....
  // Start of Getting Opt in value
	useEffect(() => {
    IuLibraryModule.getOptInStatus(
      (status) => {
        console.log('Result ',status);
        console.log("Opt In Value from JS: " + status)
        setSwitchValue(status);
      })
  }, []);
  // End of Getting Opt in value
  ....
}

The method returns boolean value. If TRUE is returned, the user has Opted-In to the Ad Services and when FALSE the user is Opted-Out of the Ad Services.

19.3: Update Opt-In Status for Engagement

The host application can provide an option to the users to Opt-In and Opt-Out of the Engagement Ads services. The same can be accomplished via the following methods to access or update the Status.

IuLibraryModule.updateOptInStatusForEngagement(true);

The method accepts boolean value. When TRUE is passed, the user is Opted-In to the Ad services and when FALSE is passed, the user is Opted-Out of the Ad Service.

19.4: Get Opt-In Status for Engagement

IuLibraryModule.getOptInStatusForEngagement((status) => console.log(status));