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() {
diff --git a/example/src/LaunchArgs.ts b/example/src/LaunchArgs.ts
index fdcbcfc..610fe9f 100644
--- a/example/src/LaunchArgs.ts
+++ b/example/src/LaunchArgs.ts
@@ -1,4 +1,7 @@
-import type { SPCampaigns } from '@sourcepoint/react-native-cmp';
+import type {
+ SPCampaigns,
+ SPBuildOptions
+} from '@sourcepoint/react-native-cmp';
export type LaunchArgs = {
config?: {
@@ -8,6 +11,7 @@ export type LaunchArgs = {
gdprPMId?: string;
usnatPMId?: string;
campaigns?: SPCampaigns;
+ buildOptions?: SPBuildOptions;
};
authId?: string;
clearData?: boolean;
diff --git a/ios/RNSourcepointCmp.swift b/ios/RNSourcepointCmp.swift
index f762939..2b842e2 100644
--- a/ios/RNSourcepointCmp.swift
+++ b/ios/RNSourcepointCmp.swift
@@ -9,6 +9,16 @@ import ConsentViewController
import Foundation
import React
+@objcMembers public class RNBuildOptions: NSObject {
+ public let language: String
+ public let messageTimeout: Int
+
+ @objc public init(language: String, messageTimeout: Int) {
+ self.language = language
+ self.messageTimeout = messageTimeout
+ }
+}
+
@objcMembers public class RNAction: NSObject {
public let type: RNSourcepointActionType
public let customActionId: String?
@@ -80,7 +90,14 @@ import React
UIApplication.shared.delegate?.window??.rootViewController
}
- public func build(_ accountId: Int, propertyId: Int, propertyName: String, campaigns: RNSPCampaigns, delegate: ReactNativeCmpImplDelegate?) {
+ public func build(
+ accountId: Int,
+ propertyId: Int,
+ propertyName: String,
+ campaigns: RNSPCampaigns,
+ options: RNBuildOptions,
+ delegate: ReactNativeCmpImplDelegate?
+ ) {
let manager = SPConsentManager(
accountId: accountId,
propertyId: propertyId,
@@ -89,7 +106,8 @@ import React
delegate: Self.objcDelegate
)
self.delegate = delegate
- manager.messageTimeoutInSeconds = 10
+ manager.messageLanguage = SPMessageLanguage.init(rawValue: options.language) ?? .English
+ manager.messageTimeoutInSeconds = TimeInterval(options.messageTimeout)
Self.shared?.consentManager = manager
}
diff --git a/ios/ReactNativeCmp.mm b/ios/ReactNativeCmp.mm
index 825942e..2a43a4c 100644
--- a/ios/ReactNativeCmp.mm
+++ b/ios/ReactNativeCmp.mm
@@ -6,7 +6,7 @@ @implementation ReactNativeCmp {
}
RCT_EXPORT_MODULE(ReactNativeCmpImpl)
-- (void)build:(double)accountId propertyId:(double)propertyId propertyName:(nonnull NSString *)propertyName campaigns:(JS::NativeReactNativeCmp::SPCampaigns &)campaigns {
+- (void)build:(double)accountId propertyId:(double)propertyId propertyName:(nonnull NSString *)propertyName campaigns:(JS::NativeReactNativeCmp::SPCampaigns &)campaigns options:(JS::NativeReactNativeCmp::SPBuildOptions &)options {
if (sdk == nil) {
sdk = [[ReactNativeCmpImpl alloc] init];
}
@@ -61,11 +61,18 @@ - (void)build:(double)accountId propertyId:(double)propertyId propertyName:(nonn
globalcmp: globalcmp
environment:RNSPCampaignEnvPublic];
+ RNBuildOptions *buildOptions = [
+ [RNBuildOptions alloc]
+ initWithLanguage: options.language()
+ messageTimeout: options.messageTimeoutInSeconds().has_value() ? (NSInteger)options.messageTimeoutInSeconds().value(): 30
+ ];
+
[sdk
- build:(NSInteger)accountId
+ buildWithAccountId:(NSInteger)accountId
propertyId:(NSInteger)propertyId
propertyName:propertyName
campaigns: internalCampaigns
+ options: buildOptions
delegate: self
];
}
diff --git a/lefthook.yml b/lefthook.yml
deleted file mode 100644
index 9695c12..0000000
--- a/lefthook.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-pre-commit:
- parallel: true
- commands:
- lint:
- glob: "*.{js,ts,jsx,tsx}"
- run: npx eslint {staged_files}
- types:
- glob: "*.{js,ts, jsx, tsx}"
- run: npx tsc
-commit-msg:
- parallel: true
- commands:
- commitlint:
- run: npx commitlint --edit
diff --git a/package.json b/package.json
index 81bf04f..9a76878 100644
--- a/package.json
+++ b/package.json
@@ -74,7 +74,6 @@
"@eslint/compat": "^1.2.7",
"@eslint/eslintrc": "^3.3.0",
"@eslint/js": "^9.22.0",
- "@evilmartians/lefthook": "^1.5.0",
"@react-native-community/cli": "15.0.0-alpha.2",
"@react-native/babel-preset": "0.79.2",
"@react-native/eslint-config": "^0.78.0",
diff --git a/src/NativeReactNativeCmp.ts b/src/NativeReactNativeCmp.ts
index 62ad4b5..6ab2aa0 100644
--- a/src/NativeReactNativeCmp.ts
+++ b/src/NativeReactNativeCmp.ts
@@ -13,6 +13,60 @@ export const enum SPCampaignEnvironment {
Stage = 'Stage',
}
+export const enum SPMessageLanguage {
+ ALBANIAN = 'sq',
+ ARABIC = 'ar',
+ BASQUE = 'eu',
+ BOSNIAN_LATIN = 'bs',
+ BULGARIAN = 'bg',
+ CATALAN = 'ca',
+ CHINESE_SIMPLIFIED = 'zh',
+ CHINESE_TRADITIONAL = 'zh-hant',
+ CROATIAN = 'hr',
+ CZECH = 'cs',
+ DANISH = 'da',
+ DUTCH = 'nl',
+ ENGLISH = 'en',
+ ESTONIAN = 'et',
+ FINNISH = 'fi',
+ FRENCH = 'fr',
+ GALICIAN = 'gl',
+ GEORGIAN = 'ka',
+ GERMAN = 'de',
+ GREEK = 'el',
+ HEBREW = 'he',
+ HINDI = 'hi',
+ HUNGARIAN = 'hu',
+ INDONESIAN = 'id',
+ ITALIAN = 'it',
+ JAPANESE = 'ja',
+ KOREAN = 'ko',
+ LATVIAN = 'lv',
+ LITHUANIAN = 'lt',
+ MACEDONIAN = 'mk',
+ MALAY = 'ms',
+ MALTESE = 'mt',
+ NORWEGIAN = 'no',
+ POLISH = 'pl',
+ PORTUGUESE_BRAZIL = 'pt-br',
+ PORTUGUESE_PORTUGAL = 'pt-pt',
+ ROMANIAN = 'ro',
+ RUSSIAN = 'ru',
+ SERBIAN_CYRILLIC = 'sr-cyrl',
+ SERBIAN_LATIN = 'sr-latn',
+ SLOVAK = 'sk',
+ SLOVENIAN = 'sl',
+ SPANISH = 'es',
+ SWAHILI = 'sw',
+ SWEDISH = 'sv',
+ TAGALOG = 'tl',
+ THAI = 'th',
+ TURKISH = 'tr',
+ UKRAINIAN = 'uk',
+ VIETNAMESE = 'vi',
+ WELSH = 'cy',
+}
+
export const enum SPActionType {
acceptAll = 'acceptAll',
rejectAll = 'rejectAll',
@@ -141,12 +195,18 @@ export type PreferencesConsent = {
rejectedStatus: PreferencesStatus[];
};
+export type SPBuildOptions = {
+ language?: SPMessageLanguage;
+ messageTimeoutInSeconds?: number;
+}
+
export interface Spec extends TurboModule {
build(
accountId: number,
propertyId: number,
propertyName: string,
- campaigns: SPCampaigns
+ campaigns: SPCampaigns,
+ options?: SPBuildOptions,
): void;
getUserData(): Promise;
loadMessage(params?: LoadMessageParams): void;
diff --git a/src/index.tsx b/src/index.tsx
index 3b00d1c..4b5835d 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -4,20 +4,27 @@ import type {
SPUserData,
LoadMessageParams,
SPAction,
+ SPBuildOptions,
} from './NativeReactNativeCmp';
-import ReactNativeCmp from './NativeReactNativeCmp';
+import ReactNativeCmp, { SPMessageLanguage } from './NativeReactNativeCmp';
import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
export * from './NativeReactNativeCmp';
+const defaultBuildOptions: SPBuildOptions = {
+ language: SPMessageLanguage.ENGLISH,
+ messageTimeoutInSeconds: 30,
+}
+
export default class SPConsentManager implements Spec {
build(
accountId: number,
propertyId: number,
propertyName: string,
- campaigns: SPCampaigns
+ campaigns: SPCampaigns,
+ options: SPBuildOptions = defaultBuildOptions,
) {
- ReactNativeCmp.build(accountId, propertyId, propertyName, campaigns);
+ ReactNativeCmp.build(accountId, propertyId, propertyName, campaigns, options);
}
getUserData(): Promise {
diff --git a/yarn.lock b/yarn.lock
index 5561ad7..85d790a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1836,16 +1836,6 @@ __metadata:
languageName: node
linkType: hard
-"@evilmartians/lefthook@npm:^1.5.0":
- version: 1.11.13
- resolution: "@evilmartians/lefthook@npm:1.11.13"
- bin:
- lefthook: bin/index.js
- checksum: 94d85f52e85c80094f0128e76ae18785e7d7b4950a11de1203f33d9deea14964c86db04d4d6f673ff96cd36d9376d4f231758e8afcce4caf06efdb5552c20a03
- conditions: (os=darwin | os=linux | os=win32) & (cpu=x64 | cpu=arm64 | cpu=ia32)
- languageName: node
- linkType: hard
-
"@flatten-js/interval-tree@npm:^1.1.2":
version: 1.1.3
resolution: "@flatten-js/interval-tree@npm:1.1.3"
@@ -3188,7 +3178,6 @@ __metadata:
"@eslint/compat": ^1.2.7
"@eslint/eslintrc": ^3.3.0
"@eslint/js": ^9.22.0
- "@evilmartians/lefthook": ^1.5.0
"@react-native-community/cli": 15.0.0-alpha.2
"@react-native/babel-preset": 0.79.2
"@react-native/eslint-config": ^0.78.0