Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: made deviceId collection configurable and de-coupled anonymousid and deviceId #232

Merged
Merged
8 changes: 4 additions & 4 deletions apps/example/ios/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
572899A5661046CED23B3DC6 /* libPods-Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2846C63330CECB73DE262FD5 /* libPods-Example.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
8C690C862A69005300E631F0 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8C690C852A69005300E631F0 /* GoogleService-Info.plist */; };
8CBF2B652A9E372400A58EFF /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8CBF2B642A9E372400A58EFF /* GoogleService-Info.plist */; };
FECB4DA94BF95A215192377D /* libPods-Example-ExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CB256E5F615F81481C8756EE /* libPods-Example-ExampleTests.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -41,7 +41,7 @@
2846C63330CECB73DE262FD5 /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
57C1791C2982A27EC162ADDA /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = Example/LaunchScreen.storyboard; sourceTree = "<group>"; };
8C690C852A69005300E631F0 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
8CBF2B642A9E372400A58EFF /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
BFB8B5DECB5F049E1E8B8C65 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = "<group>"; };
CB256E5F615F81481C8756EE /* libPods-Example-ExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Example-ExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -88,7 +88,7 @@
13B07FAE1A68108700A75B9A /* Example */ = {
isa = PBXGroup;
children = (
8C690C852A69005300E631F0 /* GoogleService-Info.plist */,
8CBF2B642A9E372400A58EFF /* GoogleService-Info.plist */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.mm */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
Expand Down Expand Up @@ -247,7 +247,7 @@
files = (
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
8C690C862A69005300E631F0 /* GoogleService-Info.plist in Resources */,
8CBF2B652A9E372400A58EFF /* GoogleService-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
18 changes: 9 additions & 9 deletions apps/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ PODS:
- AppCenter/Core (5.0.3)
- AppCenter/Crashes (5.0.3):
- AppCenter/Core
- AppsFlyerFramework (6.12.1):
- AppsFlyerFramework/Main (= 6.12.1)
- AppsFlyerFramework/Main (6.12.1)
- AppsFlyerFramework (6.12.2):
- AppsFlyerFramework/Main (= 6.12.2)
- AppsFlyerFramework/Main (6.12.2)
- boost (1.76.0)
- CleverTap-iOS-SDK (4.2.2):
- SDWebImage (~> 5.11)
Expand Down Expand Up @@ -510,15 +510,15 @@ PODS:
- React-perflogger (= 0.71.4)
- RNCAsyncStorage (1.18.0):
- React-Core
- RNRudderSdk (1.8.0):
- RNRudderSdk (1.8.1):
- React
- Rudder (~> 1.13)
- Rudder (< 2.0.0, >= 1.9.2)
- RNScreens (3.20.0):
- React-Core
- React-RCTImage
- RNSVG (13.8.0):
- React-Core
- Rudder (1.19.1):
- Rudder (1.19.2):
- MetricsReporter (= 1.0.0)
- Rudder-Amplitude (1.1.1):
- Amplitude (= 8.16.0)
Expand Down Expand Up @@ -803,7 +803,7 @@ SPEC CHECKSUMS:
AnalyticsConnector: eccd7e1cd3dd18e6bd09ac2506e37d4ed43ba3f4
Appboy-iOS-SDK: 2fc5b290fe1caa85718b811a19b303d45caea975
AppCenter: a4070ec3d4418b5539067a51f57155012e486ebd
AppsFlyerFramework: e29b63fc5441400a38a31c5501c1da500b9d53d0
AppsFlyerFramework: 6eb4d89d2eb9a6632317f1055b359d9fd85fd5ff
boost: 57d2868c099736d80fcd648bf211b4431e51a558
CleverTap-iOS-SDK: 36c21b8a671d87a0f9c7b389b339d02528bbe4d7
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
Expand Down Expand Up @@ -863,10 +863,10 @@ SPEC CHECKSUMS:
React-runtimeexecutor: 8fa50b38df6b992c76537993a2b0553d3b088004
ReactCommon: 1fed1243105330aa50ad7051207b61656f5e570b
RNCAsyncStorage: a46ee6bf15cf1ba863d0a47287236f9c95d5b213
RNRudderSdk: b8cbccae069ea1a16ae1fd93e1b1072c1f1b7af7
RNRudderSdk: 8dfb5b5a38bd98f95c205ba59a9f7be6539b752d
RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f
RNSVG: c1e76b81c76cdcd34b4e1188852892dc280eb902
Rudder: 187a8fc060057605b6e78fb8077b4d989943d804
Rudder: 26a9b6756628cb953f3151d835104ac9f5635861
Rudder-Amplitude: a353ca07ba381d23ae587f2f74ea79a6c1563145
Rudder-AppCenter: 9eca9241e3707a0e9610714dd91dc8da4bae7e1f
Rudder-Appsflyer: 8108ad9e323a5c0e9aeecdbfc4fa2dfe68497146
Expand Down
15 changes: 9 additions & 6 deletions apps/example/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const initRudderReactNativeSDK = async () => {
const config = {
dataPlaneUrl: TEST_DATAPLANE_URL,
autoCollectAdvertId: true,
collectDeviceId: false,
recordScreenViews: false,
logLevel: RUDDER_LOG_LEVEL.VERBOSE,
sessionTimeout: 0,
Expand Down Expand Up @@ -133,7 +134,6 @@ const App = () => {
<Stack.Screen name="Home" component={HomeScreen} options={{ title: 'Welcome' }} />
<Stack.Screen name="Profile" component={ProfileScreen} />
</Stack.Navigator>
<RudderEvents />
</NavigationContainer>
);
};
Expand All @@ -158,16 +158,19 @@ const HomeScreen = ({ navigation }) => {
return (
<>
<Text>Dataplane: {TEST_DATAPLANE_URL}</Text>
<Text>Write key: {TEST_WRITE_KEY}</Text>
<Button
title="Go to Jane's profile"
onPress={() => navigation.navigate('Profile', { name: 'Jane' })}
/>
<Text>
Write key: {TEST_WRITE_KEY} {'\n'}
</Text>
<Button
testID="init_btn"
title="Initialization"
onPress={async () => await initialization()}
/>
<RudderEvents />
<Button
title="Go to Jane's profile"
onPress={() => navigation.navigate('Profile', { name: 'Jane' })}
/>
</>
);
};
Expand Down
2 changes: 1 addition & 1 deletion apps/example/src/app/RudderEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const RudderEvents = () => {
};

const reset = () => {
rudderClient.reset();
rudderClient.reset(true);
};

return (
Expand Down
4 changes: 1 addition & 3 deletions libs/sdk/CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## [1.8.1](https://github.com/rudderlabs/rudder-sdk-react-native/compare/rudder-sdk-react-native@1.8.0...rudder-sdk-react-native@1.8.1) (2023-08-24)


### Bug Fixes

* ios module compilation error ([#233](https://github.com/rudderlabs/rudder-sdk-react-native/issues/233)) ([5ff512f](https://github.com/rudderlabs/rudder-sdk-react-native/commit/5ff512fff9c260936542f92571859b83367af3d6))

- ios module compilation error ([#233](https://github.com/rudderlabs/rudder-sdk-react-native/issues/233)) ([5ff512f](https://github.com/rudderlabs/rudder-sdk-react-native/commit/5ff512fff9c260936542f92571859b83367af3d6))
2 changes: 1 addition & 1 deletion libs/sdk/RNRudderSdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Pod::Spec.new do |s|
s.requires_arc = true

s.dependency "React"
s.dependency "Rudder", "~> 1.13"
s.dependency "Rudder", '>= 1.9.2', '< 2.0.0'
end


2 changes: 1 addition & 1 deletion libs/sdk/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ repositories {
dependencies {
compileOnly 'com.facebook.react:react-native:+'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.rudderstack.android.sdk:core:[1.13.0, 2.0.0)'
implementation 'com.rudderstack.android.sdk:core:[1.18.0, 2.0.0)'
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ private RudderConfig.Builder buildConfig() {
if (config.hasKey("logLevel")) {
configBuilder.withLogLevel(config.getInt("logLevel"));
}
if (config.hasKey("collectDeviceId")) {
configBuilder.withCollectDeviceId(config.getBoolean("collectDeviceId"));
}
return configBuilder;
}

Expand All @@ -81,4 +84,4 @@ private void disableAutoConfigFlagsForNativeSDK(RudderConfig.Builder configBuild
configBuilder.withTrackLifecycleEvents(false);
configBuilder.withAutoSessionTracking(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ public void getRudderContext(Promise promise) throws JSONException {
}

@ReactMethod
public void reset() {
public void reset(boolean clearAnonymousId) {
if (!isRudderClientInitializedAndReady()) {
return;
}
rudderClient.reset();
rudderClient.reset(clearAnonymousId);
}

@ReactMethod
Expand Down
5 changes: 4 additions & 1 deletion libs/sdk/ios/RNParamsConfigurator.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ - (instancetype) initWithConfig:(NSDictionary*)config {
self = [super init];
if (self) {
self->config = config;

// Default values
self.trackLifeCycleEvents = true;
self.recordScreenViews = false;
Expand Down Expand Up @@ -78,6 +78,9 @@ -(RSConfigBuilder*)buildConfig {
if ([config objectForKey:@"logLevel"]) {
[configBuilder withLoglevel:[config[@"logLevel"] intValue]];
}
if ([config objectForKey:@"collectDeviceId"]) {
[configBuilder withCollectDeviceId:[config[@"collectDeviceId"] boolValue]];
}
return configBuilder;
}

Expand Down
22 changes: 11 additions & 11 deletions libs/sdk/ios/RNRudderSdkModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ - (dispatch_queue_t)methodQueue
if (rsClient == nil) {
self->configParams = [[RNParamsConfigurator alloc] initWithConfig:config];
RSConfigBuilder *configBuilder = [self->configParams handleConfig];

[RSLogger logDebug:@"setup: Initiating RNPreferenceManager"];
self->preferenceManager = [RNPreferenceManager getInstance];

rsClient = [RSClient getInstance:self->configParams.writeKey config:[RNRudderAnalytics buildWithIntegrations:configBuilder] options:[self getRudderOptionsObject:_options]];

[RSLogger logDebug:@"setup: Initiating RNUserSessionPlugin"];
self->session = [[RNUserSessionPlugin alloc] initWithAutomaticSessionTrackingStatus:self->configParams.autoSessionTracking withLifecycleEventsTrackingStatus:self->configParams.trackLifeCycleEvents withSessionTimeout:self->configParams.sessionTimeout];
[self->session handleSessionTracking];

[RSLogger logDebug:@"setup: Initiating RNBackGroundModeManager"];
self->backGroundModeManager = [[RNBackGroundModeManager alloc] initWithEnableBackgroundMode:self->configParams.enableBackgroundMode];

[RSLogger logDebug:@"setup: Initiating RNApplicationLifeCycleManager"];
self->applicationLifeCycleManager = [[RNApplicationLifeCycleManager alloc] initWithTrackLifecycleEvents:self->configParams.trackLifeCycleEvents andBackGroundModeManager:self->backGroundModeManager withLaunchOptions:_bridge.launchOptions withSessionPlugin:self->session];
[self->applicationLifeCycleManager trackApplicationLifeCycle];

if (self->configParams.recordScreenViews) {
[RSLogger logDebug:@"setup: Enabling automatic recording of screen views"];
[self->applicationLifeCycleManager prepareScreenRecorder];
Expand Down Expand Up @@ -72,7 +72,7 @@ -(BOOL) isRudderClientInitializedAndReady {
[builder setEventName:_event];
[builder setPropertyDict:_properties];
[builder setRSOption:[self getRudderOptionsObject:_options]];

[[RSClient sharedInstance] trackWithBuilder:builder];
}
RCT_EXPORT_METHOD(screen:(NSString*)_event properties:(NSDictionary*)_properties options:(NSDictionary*)_options)
Expand All @@ -84,7 +84,7 @@ -(BOOL) isRudderClientInitializedAndReady {
// [builder setEventName:_event];
// [builder setPropertyDict:_properties];
// [builder setRSOption:[[RSOption alloc] init]];

[self->session saveEventTimestamp];
[[RSClient sharedInstance] screen:_event properties:_properties options:[self getRudderOptionsObject:_options]];
}
Expand Down Expand Up @@ -124,7 +124,7 @@ -(BOOL) isRudderClientInitializedAndReady {
}
if([_groupId isEqual:@""])
{
[RSLogger logWarn:@"Dropping the Group call as groupId can not be empty"];
[RSLogger logWarn:@"Dropping the Group call as groupId can not be empty"];
return;
}
[self->session saveEventTimestamp];
Expand All @@ -138,12 +138,12 @@ -(BOOL) isRudderClientInitializedAndReady {
}
}

RCT_EXPORT_METHOD(reset)
RCT_EXPORT_METHOD(reset:(BOOL) clearAnonymousId)
{
if (![self isRudderClientInitializedAndReady]) {
return;
}
[[RSClient sharedInstance] reset];
[[RSClient sharedInstance] reset:clearAnonymousId];
}

RCT_EXPORT_METHOD(flush)
Expand Down
1 change: 1 addition & 0 deletions libs/sdk/src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export const SDK_VERSION = '1.8.0';
export const AUTO_SESSION_TRACKING = true;
export const SESSION_TIMEOUT = 300000;
export const ENABLE_BACKGROUND_MODE = false;
export const COLLECT_DEVICE_ID = true;
3 changes: 2 additions & 1 deletion libs/sdk/src/NativeBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface Configuration {
autoSessionTracking?: boolean;
sessionTimeout?: number;
enableBackgroundMode?: boolean;
collectDeviceId?: boolean;
// eslint-disable-next-line @typescript-eslint/ban-types
withFactories?: Array<Record<string, unknown> | Function>;
}
Expand Down Expand Up @@ -41,7 +42,7 @@ export interface Bridge {
traits: Record<string, unknown> | null,
options: Record<string, unknown> | null,
): Promise<void>;
reset(): Promise<void>;
reset(clearAnonymousId: boolean): Promise<void>;
flush(): Promise<void>;
optOut(optOut: boolean): Promise<void>;
putDeviceToken(token: string): Promise<void>;
Expand Down
8 changes: 6 additions & 2 deletions libs/sdk/src/RudderClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function validateConfiguration(configuration: Configuration) {
logWarn("setup : 'enableBackgroundMode' must be a boolen. Falling back to the default value");
delete configuration.enableBackgroundMode;
}
if (configuration.collectDeviceId && typeof configuration.collectDeviceId != 'boolean') {
logWarn("setup : 'withCollectDeviceId' must be a boolen. Falling back to the default value");
desusai7 marked this conversation as resolved.
Show resolved Hide resolved
delete configuration.collectDeviceId;
}
}

// setup the RudderSDK with writeKey and Config
Expand Down Expand Up @@ -274,8 +278,8 @@ async function putAnonymousId(anonymousId: string) {
}
}

async function reset() {
bridge.reset();
async function reset(clearAnonymousId = false) {
bridge.reset(clearAnonymousId);
}

async function flush() {
Expand Down
3 changes: 3 additions & 0 deletions libs/sdk/src/RudderConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
AUTO_SESSION_TRACKING,
SESSION_TIMEOUT,
ENABLE_BACKGROUND_MODE,
COLLECT_DEVICE_ID,
} from './Constants';

export const configure = async (
Expand All @@ -31,6 +32,7 @@ export const configure = async (
autoCollectAdvertId = AUTO_COLLECT_ADVERT_ID,
trackAppLifecycleEvents = TRACK_LIFECYCLE_EVENTS,
recordScreenViews = RECORD_SCREEN_VIEWS,
collectDeviceId = COLLECT_DEVICE_ID,
withFactories = [],
}: Configuration,
): Promise<Configuration> => {
Expand Down Expand Up @@ -60,6 +62,7 @@ export const configure = async (
trackAppLifecycleEvents,
enableBackgroundMode,
recordScreenViews,
collectDeviceId,
};

return { ...config };
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading