@economist/react-native-consent
TypeScript icon, indicating that this package has built-in type declarations

0.15.0 • Public • Published

react-native-consent

Consent management for mobile

Installation

npm install @economist/react-native-consent

or

yarn add @economist/react-native-consent

Usage

Use it like a view, this gives you more flexibility, because you can integrate that view in any screen.

import { ConsentView } from '@economist/react-native-consent';

// ...

const onUserConsentReceived = React.useCallback((_userData: SPUserData, error: string | null) => {
  // ...
}, []);

<ConsentView
  onConsentReceived={onUserConsentReceived}
  config={{
    propertyName: 'mobile.multicampaign.demo',
    accountId: 22,
    privacyManagerId: "14967",
  }}
  // This prop is optional, once set to a truthy value, it will auto apply the consent for the specified vendors and call the `onConsentReceived`.
  autoApplyGdprConsent={{
    // Vendor and Category IDs can be found in Sourcepoint dashboard
    vendorIds: [
      '5f59ef68b07d032d081f78fa',
      '5f0f39014effda6e8bbd2006',
      '5ea2d4894e5aa15059fde8a0',
      '5ef5f16871012e14626a25e2',
    ],
    categoryIds: ['633c3d8a32ec04073bd0c4b4'],
  }}
  style={{ width: '100%', height: '100%' }}
  renderLoading=(() => <MyCustomLoadingIndicator>) // completely custom loading indicator
  loadingAccentColor={"blue"} // the color for the default loading indicator
/>;

Use the already defined native iOS / Android screens. This will a show transparent modal on iOS and a transparent not fullscreen activity on Android.

import {
  consentManagement,
  ConsentConfig,
  SPUserData,
} from '@economist/react-native-consent';

const onUserConsentReceived = React.useCallback(
  (_userData: SPUserData, error: string | null) => {
    Alert.alert('Consent received');
  },
  []
);

const onShowConsentPress = React.useCallback(() => {
  consentManagement.showConsentPopup({
    propertyName: 'mobile.multicampaign.demo',
    accountId: 22,
    privacyManagerId: '14967',
  });
}, []);

React.useEffect(() => {
  consentManagement.listenForConsentResponse(onUserConsentReceived);
}, []);

return (
  <View
    style={{
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
      backgroundColor: 'white',
    }}
  >
    <TouchableOpacity onPress={onShowConsentPress}>
      <Text>Show native consent popup</Text>
    </TouchableOpacity>
  </View>
);

For Android you also need to declare a new activity in your AndroidManifest.xml file.

 <activity
  android:name="com.consent.views.consentactivity.ConsentActivity"
  android:theme="@style/RNConsent.Theme.Transparent"
  android:exported="false" />

Utility functions

Get the current consent data saved in the local storage. Useful if you want to check if the consent was given or not.

let result: Promise<SPUserData> =
  await consentManagement.getUserConsentFromLocalStorage(config);

Clears the cache. Useful if you are switching the config.

consentManagement.clearAllData();

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

/@economist/react-native-consent/

    Package Sidebar

    Install

    npm i @economist/react-native-consent

    Weekly Downloads

    22

    Version

    0.15.0

    License

    MIT

    Unpacked Size

    231 kB

    Total Files

    132

    Last publish

    Collaborators

    • shubhameconomist
    • ajeet-singh024
    • benpeh
    • akshatrastogi01
    • shivpathak-teg
    • pvalentim
    • olumideosikomaiya
    • ninjanailseconomist
    • saurabhsatwani-teg
    • cristianpetre-teg
    • jakezachariahnixon
    • devrath-teg
    • econ.martinchan
    • jimc-teg
    • teenuburi
    • leahpatel
    • zeek01
    • paarthpuri
    • emilyblundellteg
    • aayushkumarecon
    • faiz-teg
    • benhalsteadteg
    • rorywebber
    • sahu-economist
    • romany-gl
    • johnfriend
    • josephc_100
    • robthomas72
    • rully-teg
    • irshadfareed
    • idudenkov
    • emiliawil
    • faisal1505
    • charlottecutler
    • petervoeconomist
    • ghazali-teg
    • yordan-teg
    • ykswra-teg
    • rambot
    • trankimtung-economist
    • rickmather
    • mikeecon
    • ovysotskaya
    • siva-teg
    • tayoja
    • gibbsy
    • karltaylor
    • virajvinodkumar
    • lenface
    • connorpayne
    • banguneco
    • vinnay0308
    • adjizulfiqarfauzi
    • afiefyr
    • tegalankf
    • endiirawaneco
    • elenafayethomas
    • rendyfebry.eco
    • hzeraat2
    • irfan2204
    • stevenleeeconomist
    • konrad.korczynski
    • chituruchinwah
    • chloemcmullan
    • ransomprofit
    • richard-frost
    • tgrisley
    • neilateconomist
    • solo-digital
    • yevdomin
    • fteoldi
    • nanjunda-teg
    • alexeco
    • rospearce
    • sangeeta-economist
    • mfiresky
    • larry4000
    • celltowertrees
    • chriscamplin
    • prateek.maheshwari
    • vishal-gholkar
    • wizbit77
    • danielmensah
    • raghu-teg
    • dwi-teg
    • rsmutch
    • ctheodoridou
    • cristiangutueconomist
    • edemeconomist
    • silvialazin
    • nam-econ
    • barneyward
    • uwajacques
    • lgordienko
    • liambird
    • kellybrocklehurst
    • sebastianchumaceiro
    • luketaylor
    • yousea2_economist
    • krishnapriyaelango
    • azzuhasan
    • simonwtaylor
    • jayyecm
    • kartik.saxena
    • nautiyalmanish
    • matthewarrowsmith
    • rmisyuk
    • cristian.v
    • kamil_p
    • jonleeeconomist
    • angelamaugey
    • farnaz.ostovari
    • grmnd
    • ov212
    • xaviergimenez
    • simmyd91
    • edwilliams
    • umairyounus
    • layo_titi
    • johnperagine
    • stevedrog
    • jimhuntyeconomist
    • cjallen88
    • ashrafiftekhar
    • v.potonya
    • evgenylyndin
    • tonygoodey
    • sugadev.durairaj
    • apoorv_srivastav_infosys
    • futuraprime
    • diana.carmen
    • economistrobot
    • economist-org-bot
    • withoutnations
    • karthikeyaninfy
    • debarshi-banerjee01
    • tuhindasinfy
    • adwaitmathkari
    • utkarsh_nayan
    • shubham20info
    • davidwong.economist.com
    • sumitinfy
    • a-w-l
    • mikeconway
    • jamespenrice
    • matt-hall-kcc
    • johnvannguyen
    • ferdousiqbal
    • alexselbyboothroyd
    • elliottmorris
    • stephanienedoklanova
    • gdunton
    • drinkataco
    • fceco
    • tothvoj
    • ecomorant
    • danaciocan
    • mattcouchman
    • kristynolan
    • johti
    • economist-web-team
    • mattpointblank
    • sukh-kinandcarta
    • otomogroove
    • samualdjpayne
    • impactyogi
    • lewtur
    • shahdotrahul
    • pedrito77
    • davidkelley87
    • stancek_globallogic
    • kevin-economist
    • matildealiffi
    • pads
    • dominik_secka
    • raynelle03
    • robmorgan-tab
    • forpet
    • jonh-econ
    • davidgoodchild
    • just_ak87
    • fadumoaideed
    • jaroslavhamrak
    • mloveday
    • irfanyasin_teg
    • mbrzek
    • igorshcherba
    • manunes
    • joeawillis
    • johnjameshodgins
    • ethancevans
    • jonny_kc