Skip to content

Commit

Permalink
chore: fix iOS apps user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Oct 16, 2024
1 parent 94ea526 commit 6ffc179
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CustomerIOReactNativeModule(
}.getOrNull()

@ReactMethod
fun initialize(configJson: ReadableMap, logLevelRawValue: String) {
fun initialize(configJson: ReadableMap, sdkArgs: ReadableMap) {
try {
val packageConfig = configJson.toMap()
val cdpApiKey = packageConfig.getTypedValue<String>(
Expand All @@ -48,7 +48,7 @@ class CustomerIOReactNativeModule(
applicationContext = reactApplicationContext.applicationContext as Application,
cdpApiKey = cdpApiKey
).apply {
logLevel(CioLogLevel.getLogLevel(logLevelRawValue))
logLevel(CioLogLevel.getLogLevel(packageConfig.getTypedValue<String>(Keys.Config.LOG_LEVEL)))
regionRawValue?.let { region(region) }

packageConfig.getTypedValue<Boolean>(Keys.Config.AUTO_TRACK_DEVICE_ATTRIBUTES)
Expand Down
2 changes: 1 addition & 1 deletion ios/wrappers/CioRctWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@interface RCT_EXTERN_REMAP_MODULE(NativeCustomerIO, CioRctWrapper, NSObject)

RCT_EXTERN_METHOD(initialize:(id)config logLevel:(NSString *)logLevel)
RCT_EXTERN_METHOD(initialize:(id)config args:(id)args)
RCT_EXTERN_METHOD(identify:(NSString *)identify traits:(NSDictionary *)traits)
RCT_EXTERN_METHOD(clearIdentify)
RCT_EXTERN_METHOD(track:(NSString *)name properties:(NSDictionary *)properties)
Expand Down
15 changes: 11 additions & 4 deletions ios/wrappers/CioRctWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ class CioRctWrapper: NSObject {
@objc var moduleRegistry: RCTModuleRegistry!
private let logger: CioInternalCommon.Logger = DIGraphShared.shared.logger

@objc
func initialize(_ configJson: AnyObject, logLevel: String) {
@objc(initialize:args:)
func initialize(_ configJson: AnyObject, _ sdkArgs: AnyObject?) {
do {
guard let sdkConfig = configJson as? [String: Any?] else {
logger.error("Initializing Customer.io SDK failed with error: Invalid config format")
return
}
let sdkParams = sdkArgs as? [String: Any?]
let packageSource = sdkParams?["packageSource"] as? String
let packageVersion = sdkParams?["packageVersion"] as? String

logger.debug("Initializing Customer.io SDK (\(String(describing: packageSource)) \(String(describing: packageVersion))) with config: \(configJson)")
if let source = packageSource, let sdkVersion = packageVersion {
DIGraphShared.shared.override(value: CustomerIOSdkClient(source: source, sdkVersion: sdkVersion), forType: SdkClient.self)
}

logger.debug("Initializing Customer.io SDK with config: \(configJson)")
let sdkConfigBuilder = try SDKConfigBuilder.create(from: sdkConfig)
CustomerIO.initialize(withConfig: sdkConfigBuilder.build())

Expand All @@ -41,7 +48,7 @@ class CioRctWrapper: NSObject {
if let traitsJson = try? JSON(traits as Any) {
CustomerIO.shared.identify(traits: traitsJson)
} else {
logger.error("Unable to parse traits to JSON: \(traits)")
logger.error("Unable to parse traits to JSON: \(String(describing: traits))")
}
} else {
logger.error("Provide id or traits to identify a user profile.")
Expand Down
18 changes: 16 additions & 2 deletions src/customerio-cdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { CustomerIOInAppMessaging } from './customerio-inapp';
import { CustomerIOPushMessaging } from './customerio-push';
import { NativeLoggerListener } from './native-logger-listener';

const packageJson = require('customerio-reactnative/package.json');

const LINKING_ERROR =
`The package 'customerio-reactnative' doesn't seem to be linked. Make sure: ` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
Expand All @@ -29,8 +31,20 @@ export class CustomerIO {
if (config.logLevel && config.logLevel !== CioLogLevel.None) {
NativeLoggerListener.initialize();
}
let logLevel = config.logLevel?.valueOf() ?? CioLogLevel.Error.valueOf();
NativeCustomerIO.initialize(config, logLevel);

const packageVersion = packageJson.version ?? '';
const args = {
packageSource: "ReactNative",
packageVersion: packageVersion
};

const expoVersion = packageJson.expoVersion ?? '';
if (expoVersion !== '') {
args.packageSource = "Expo";
args.packageVersion = expoVersion;
}

NativeCustomerIO.initialize(config, args);
CustomerIO.initialized = true;
};

Expand Down

0 comments on commit 6ffc179

Please sign in to comment.