diff --git a/README.md b/README.md index 90f11e9..d539928 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,8 @@ useEffect(() => { config.accountId, config.propertyId, config.propertyName, - config.campaigns + config.campaigns, + config.buildOptions ); return () => { @@ -64,6 +65,7 @@ The following attributes should be replaced with your organization's details: | `config.propertyId` | Number | ID for property found in the Sourcepoint portal | | `config.propertyName` | String | Name of property found in the Sourcepoint portal | | `config.campaigns` | Object | Campaigns launched on the property through the Sourcepoint portal. Accepts `gdpr: {}`, `usnat: {}`, `preferences: {}` and `globalcmp: {}`. See table below for information on each campaign type. | +| `config.buildOptions` | Object? | Check `SPBuildOptions` type for more information. | Refer to the table below regarding the different campaigns that can be implemented: @@ -210,7 +212,7 @@ In the example below, you can find a fully configured example in React: ```jsx import React, { useState, useEffect, useRef } from 'react'; -import { View, Text, SafeAreaView } from 'react-native'; +import { View, Text, SafeAreaView, SPMessageLanguage } from 'react-native'; import SPConsentManager, { SPCampaignEnvironment, SPUserData } from '@sourcepoint/react-native-cmp'; @@ -231,6 +233,12 @@ export default function App() { // usnat: {}, // preferences: {}, // globalcmp: {} + }, + { + // in order to override the message language, make sure the option "Use Browser Default" + // is disabled in the Sourcepoint dashboard + language: SPMessageLanguage.ENGLISH, + messageTimeoutInSeconds: 20, } ); diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt index 4418bda..553087b 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt @@ -19,6 +19,7 @@ import com.sourcepoint.cmplibrary.model.ConsentAction import com.sourcepoint.cmplibrary.model.exposed.SPConsents import com.sourcepoint.cmplibrary.util.clearAllData import com.sourcepoint.cmplibrary.util.userConsents +import com.sourcepoint.reactnativecmp.arguments.BuildOptions import com.sourcepoint.reactnativecmp.consents.RNSPUserData import org.json.JSONObject @@ -38,14 +39,17 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN accountId: Double, propertyId: Double, propertyName: String, - campaigns: ReadableMap + campaigns: ReadableMap, + options: ReadableMap?, ) { val convertedCampaigns = campaigns.SPCampaigns() + val parsedOptions = BuildOptions(options) val config = SpConfigDataBuilder().apply { addAccountId(accountId.toInt()) addPropertyName(propertyName) addPropertyId(propertyId.toInt()) - addMessageTimeout(30000) + addMessageTimeout(parsedOptions.messageTimeoutInSeconds) + addMessageLanguage(parsedOptions.language) convertedCampaigns.gdpr?.let { addCampaign(campaignType = GDPR, params = it.targetingParams, groupPmId = it.groupPmId) } diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt index 06c971a..7efd7e6 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt @@ -1,6 +1,7 @@ package com.sourcepoint.reactnativecmp.arguments import com.facebook.react.bridge.Arguments +import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableArray import com.facebook.react.bridge.WritableMap import kotlinx.serialization.json.JsonArray @@ -158,3 +159,10 @@ fun WritableMap.putArray(name: String, value: Iterable<*>) { value.forEach { this.pushAny(it) } }) } + +fun ReadableMap.getLongOrNull(name: String) = + if (hasKey(name) && !isNull(name)) { + getLong(name) + } else { + null + } diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt new file mode 100644 index 0000000..d9db26f --- /dev/null +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt @@ -0,0 +1,15 @@ +package com.sourcepoint.reactnativecmp.arguments + +import com.facebook.react.bridge.ReadableMap +import com.sourcepoint.cmplibrary.model.MessageLanguage +import com.sourcepoint.cmplibrary.model.MessageLanguage.ENGLISH + +data class BuildOptions( + val language: MessageLanguage, + val messageTimeoutInSeconds: Long, +) { + constructor(options: ReadableMap?) : this( + language = MessageLanguage.entries.find { it.value == options?.getString("language") } ?: ENGLISH, + messageTimeoutInSeconds = options?.getLongOrNull("messageTimeoutInSeconds") ?: 30000 + ) +} diff --git a/example/src/App.tsx b/example/src/App.tsx index 2602b2b..1f74f40 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -11,6 +11,7 @@ import { LaunchArguments } from 'react-native-launch-arguments'; import SPConsentManager, { SPCampaignEnvironment, + SPMessageLanguage, } from '@sourcepoint/react-native-cmp'; import type { SPCampaigns, SPUserData } from '@sourcepoint/react-native-cmp'; import type { LaunchArgs } from './LaunchArgs'; @@ -31,6 +32,12 @@ const config = { accountId: 22, propertyId: 16893, propertyName: 'mobile.multicampaign.demo', + buildOptions: { + // in order to override the message language, make sure the option "Use Browser Default" + // is disabled in the Sourcepoint dashboard + language: SPMessageLanguage.ENGLISH, + messageTimeoutInSeconds: 20, + }, gdprPMId: '488393', usnatPMId: '988851', globalCmpPMId: '1323762', @@ -58,7 +65,8 @@ export default function App() { config.accountId, config.propertyId, config.propertyName, - config.campaigns + config.campaigns, + config.buildOptions ); if (launchArgs.clearData === true) { @@ -127,7 +135,8 @@ export default function App() { config.accountId, config.propertyId, config.propertyName, - config.campaigns + config.campaigns, + config.buildOptions ); setUserData({}); }, []); @@ -159,22 +168,22 @@ export default function App() {