diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpModule.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpModule.kt index 4d372d9..356b8d6 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpModule.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/RNSourcepointCmpModule.kt @@ -20,6 +20,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.cmplibrary.model.MessageLanguage import com.sourcepoint.reactnativecmp.consents.RNSPUserData import org.json.JSONObject @@ -38,7 +39,7 @@ class RNSourcepointCmpModule internal constructor(context: ReactApplicationConte override fun getName() = NAME @ReactMethod - override fun build(accountId: Int, propertyId: Int, propertyName: String, campaigns: ReadableMap) { + override fun build(accountId: Int, propertyId: Int, propertyName: String, campaigns: ReadableMap, messageLanguage: String) { val convertedCampaigns = campaigns.SPCampaigns() val config = SpConfigDataBuilder().apply { @@ -46,6 +47,11 @@ class RNSourcepointCmpModule internal constructor(context: ReactApplicationConte addPropertyName(propertyName) addPropertyId(propertyId) addMessageTimeout(30000) + + if (messageLanguage.isNotBlank()) { + addMessageLanguage(getMessageLanguage(messageLanguage)) + } + convertedCampaigns.gdpr?.let { addCampaign(campaignType = CampaignType.GDPR, params = it.targetingParams, groupPmId = null) } @@ -66,6 +72,10 @@ class RNSourcepointCmpModule internal constructor(context: ReactApplicationConte } } + private fun getMessageLanguage(languageCode: String?): MessageLanguage { + return MessageLanguage.values().firstOrNull { it.value == languageCode } ?: MessageLanguage.ENGLISH + } + private fun runOnMainThread(runnable: () -> Unit) { reactApplicationContext.runOnUiQueueThread(runnable) } diff --git a/android/src/oldarch/RNSourcepointCmpSpec.kt b/android/src/oldarch/RNSourcepointCmpSpec.kt index d908f7e..678de43 100644 --- a/android/src/oldarch/RNSourcepointCmpSpec.kt +++ b/android/src/oldarch/RNSourcepointCmpSpec.kt @@ -8,7 +8,7 @@ import com.facebook.react.bridge.ReadableMap abstract class RNSourcepointCmpSpec internal constructor(context: ReactApplicationContext) : ReactContextBaseJavaModule(context) { - abstract fun build(accountId: Int, propertyId: Int, propertyName: String, campaigns: ReadableMap) + abstract fun build(accountId: Int, propertyId: Int, propertyName: String, campaigns: ReadableMap, messageLanguage: String) abstract fun loadMessage(params: ReadableMap?) abstract fun clearLocalData() abstract fun getUserData(promise: Promise) diff --git a/ios/RNSourcepointCmp.h b/ios/RNSourcepointCmp.h index 2613651..7b49fc7 100644 --- a/ios/RNSourcepointCmp.h +++ b/ios/RNSourcepointCmp.h @@ -9,7 +9,7 @@ @interface RCT_EXTERN_MODULE(RNSourcepointCmp, RCTEventEmitter) -RCT_EXTERN_METHOD(build:(int)accountId propertyId:(int)propertyId propertyName:(NSString *)propertyName campaigns:(SPCampaigns*)campaigns) +RCT_EXTERN_METHOD(build:(int)accountId propertyId:(int)propertyId propertyName:(NSString *)propertyName campaigns:(SPCampaigns*)campaigns messageLanguage:(NSString *)messageLanguage) RCT_EXTERN_METHOD(loadMessage: (SPLoadMessageParams *)params) RCT_EXTERN_METHOD(clearLocalData) diff --git a/ios/RNSourcepointCmp.swift b/ios/RNSourcepointCmp.swift index 9029bca..234fde2 100644 --- a/ios/RNSourcepointCmp.swift +++ b/ios/RNSourcepointCmp.swift @@ -28,7 +28,7 @@ import React resolve(RNSPUserData(from: consentManager?.userData).toDictionary()) } - func build(_ accountId: Int, propertyId: Int, propertyName: String, campaigns: SPCampaigns) { + func build(_ accountId: Int, propertyId: Int, propertyName: String, campaigns: SPCampaigns, messageLanguage: String) { let manager = SPConsentManager( accountId: accountId, propertyId: propertyId, @@ -36,6 +36,11 @@ import React campaigns: campaigns, delegate: self ) + + if !messageLanguage.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { + manager.messageLanguage = SPMessageLanguage(rawValue: messageLanguage) ?? SPMessageLanguage.English + } + manager.messageTimeoutInSeconds = 30 RNSourcepointCmp.shared?.consentManager = manager } diff --git a/package.json b/package.json index 394ec57..2c3b4ab 100644 --- a/package.json +++ b/package.json @@ -95,9 +95,6 @@ "react": "*", "react-native": "*" }, - "workspaces": [ - "example" - ], "packageManager": "yarn@3.6.1", "jest": { "preset": "react-native", diff --git a/src/index.ts b/src/index.ts index 0a9af95..4b09c52 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,8 @@ import type { SPActionType, } from './types'; +import { Language } from './types'; + const LINKING_ERROR = `The package '@sourcepoint/react-native-cmp' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + @@ -42,9 +44,10 @@ export class SPConsentManager implements Spec { accountId: number, propertyId: number, propertyName: string, - campaigns: SPCampaigns + campaigns: SPCampaigns, + messageLanguage?: Language ) { - RNSourcepointCmp.build(accountId, propertyId, propertyName, campaigns); + RNSourcepointCmp.build(accountId, propertyId, propertyName, campaigns, messageLanguage || ''); } getUserData(): Promise { diff --git a/src/types.ts b/src/types.ts index 26ac3d8..7c3684a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,46 @@ import type { TurboModule } from 'react-native'; +export enum Language { + BULGARIAN = "BG", + CATALAN = "CA", + CHINESE = "ZH", + CROATIAN = "HR", + CZECH = "CS", + DANISH = "DA", + DUTCH = "NL", + ENGLISH = "EN", + ESTONIAN = "ET", + FINNISH = "FI", + FRENCH = "FR", + GAELIC = "GD", + GERMAN = "DE", + GREEK = "EL", + HEBREW = "HE", + HUNGARIAN = "HU", + ICELANDIC = "IS", + INDONESIAN = "ID", + ITALIAN = "IT", + JAPANESE = "JA", + KOREAN = "KO", + LATVIAN = "LV", + LITHUANIAN = "LT", + MACEDONIAN = "MK", + MALAY = "MS", + NORWEGIAN = "NO", + POLISH = "PL", + PORTUGUESE = "PT", + ROMANIAN = "RO", + RUSSIAN = "RU", + SERBIAN_CYRILLIC = "SR-CYRL", + SERBIAN_LATIN = "SR-LATN", + SLOVAKIAN = "SK", + SLOVENIAN = "SL", + SPANISH = "ES", + SWEDISH = "SV", + TAGALOG = "TL", + TURKISH = "TR" +}; + export type SPCampaign = { targetingParams?: Object; supportLegacyUSPString?: boolean; @@ -105,7 +146,8 @@ export interface Spec extends TurboModule { accountId: number, propertyId: number, propertyName: string, - campaigns: SPCampaigns + campaigns: SPCampaigns, + messageLanguage?: Language ): void; getUserData(): Promise; loadMessage(params?: LoadMessageParams): void;