Skip to content

Commit c32b6b4

Browse files
getDeviceIDType (#189)
* getDeviceIDType * getDeviceIDType * requested changes * remove function name * removed meessage where not needed * fixed ios bug * added changelog * fixed temporary device id after init * added temp device id const * Update CHANGELOG.md * fixed message bug * minor bug --------- Co-authored-by: ArtursKadikis <[email protected]>
1 parent addeebb commit c32b6b4

File tree

5 files changed

+102
-46
lines changed

5 files changed

+102
-46
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
## 23.02.0
22
* Added a new SDK initialization call 'initWithConfig', and a configuration object to configure it.
33
* Added 'recordDirectAttribution' and 'recordIndirectAttribution' calls.
4+
* Added 'getDeviceIDType' call to fetch the device ID type.
5+
* Fixed a bug in IOS SDK that failed to correctly process temporary device id.
46
* Deprecated the following SDK calls:
57
- 'init'
68
- 'pushTokenType'

Countly.js

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Countly.serverUrl = '';
1616
Countly.appKey = '';
1717
let _isInitialized = false;
1818
let _isPushInitialized = false;
19+
const DeviceIdType = {
20+
DEVELOPER_SUPPLIED: 'DEVELOPER_SUPPLIED',
21+
SDK_GENERATED: 'SDK_GENERATED',
22+
TEMPORARY_ID: 'TEMPORARY_ID',
23+
};
24+
1925
/*
2026
* Listener for rating widget callback, when callback recieve we will remove the callback using listener.
2127
*/
@@ -39,6 +45,7 @@ Countly.messagingMode = { 'DEVELOPMENT': '1', 'PRODUCTION': '0', 'ADHOC': '2' };
3945
if (Platform.OS.match('android')) {
4046
Countly.messagingMode.DEVELOPMENT = '2';
4147
}
48+
Countly.TemporaryDeviceIDString = 'TemporaryDeviceID';
4249

4350
/**
4451
* Initialize Countly
@@ -355,19 +362,16 @@ Countly.configureIntentRedirectionCheck = function (allowedIntentClassNames = []
355362
return message;
356363
}
357364
if (!Array.isArray(allowedIntentClassNames)) {
358-
var message = `Ignoring, unsupported data type '${typeof allowedIntentClassNames}' 'allowedIntentClassNames' should be an array of String`;
359-
Countly.logWarning('configureIntentRedirectionCheck', message);
365+
Countly.logWarning('configureIntentRedirectionCheck', `Ignoring, unsupported data type '${typeof allowedIntentClassNames}' 'allowedIntentClassNames' should be an array of String`);
360366
allowedIntentClassNames = [];
361367
}
362368
if (!Array.isArray(allowedIntentPackageNames)) {
363-
var message = `Ignoring, unsupported data type '${typeof allowedIntentPackageNames}' 'allowedIntentPackageNames' should be an array of String`;
364-
Countly.logWarning('configureIntentRedirectionCheck', message);
369+
Countly.logWarning('configureIntentRedirectionCheck', `Ignoring, unsupported data type '${typeof allowedIntentPackageNames}' 'allowedIntentPackageNames' should be an array of String`);
365370
allowedIntentPackageNames = [];
366371
}
367372

368373
if (typeof useAdditionalIntentRedirectionChecks !== 'boolean') {
369-
var message = `Ignoring, unsupported data type '${typeof useAdditionalIntentRedirectionChecks}' 'useAdditionalIntentRedirectionChecks' should be a boolean`;
370-
Countly.logWarning('configureIntentRedirectionCheck', message);
374+
Countly.logWarning('configureIntentRedirectionCheck', `Ignoring, unsupported data type '${typeof useAdditionalIntentRedirectionChecks}' 'useAdditionalIntentRedirectionChecks' should be a boolean`);
371375
useAdditionalIntentRedirectionChecks = true;
372376
}
373377

@@ -498,6 +502,42 @@ Countly.getCurrentDeviceId = async function () {
498502
return result;
499503
};
500504

505+
_getDeviceIdType = function (deviceIdType) {
506+
let result = null;
507+
switch (deviceIdType) {
508+
case 'DS':
509+
result = DeviceIdType.DEVELOPER_SUPPLIED;
510+
break;
511+
case 'TID':
512+
result = DeviceIdType.TEMPORARY_ID;
513+
break;
514+
case 'SG':
515+
result = DeviceIdType.SDK_GENERATED;
516+
break;
517+
}
518+
if (result == null) {
519+
Countly.logError('_getDeviceIdType', "unexpected deviceIdType [" + deviceIdType.toString() + "] from native side");
520+
return null;
521+
}
522+
return result;
523+
};
524+
/**
525+
* Get currently used device Id type.
526+
* Should be called after Countly init
527+
* */
528+
Countly.getDeviceIDType = async function () {
529+
if (!_isInitialized) {
530+
Countly.logError('getDeviceIDType', "'init' must be called before 'getDeviceIDType'");
531+
return null;
532+
}
533+
const result = await CountlyReactNative.getDeviceIDType();
534+
if (result == null || result == "") {
535+
Countly.logError('getDeviceIDType', "'getDeviceIDType' unexpected null value from native side");
536+
return null;
537+
}
538+
return _getDeviceIdType(result);
539+
};
540+
501541
Countly.changeDeviceId = async function (newDeviceID, onServer) {
502542
if (!_isInitialized) {
503543
const msg = "'init' must be called before 'changeDeviceId'";
@@ -790,8 +830,7 @@ Countly.setUserData = async function (userData) {
790830
const args = [];
791831
for (const key in userData) {
792832
if (typeof userData[key] !== 'string' && key.toString() != 'byear') {
793-
message = `skipping value for key '${key.toString()}', due to unsupported data type '${typeof userData[key]}', its data type should be 'string'`;
794-
Countly.logWarning('setUserData', message);
833+
Countly.logWarning('setUserData', `skipping value for key '${key.toString()}', due to unsupported data type '${typeof userData[key]}', its data type should be 'string'`);
795834
}
796835
}
797836

@@ -1014,8 +1053,7 @@ Countly.userDataBulk.setUserProperties = async function (customAndPredefined) {
10141053
}
10151054
for (const key in customAndPredefined) {
10161055
if (typeof customAndPredefined[key] !== 'string' && key.toString() != 'byear') {
1017-
message = `skipping value for key '${key.toString()}', due to unsupported data type '${typeof customAndPredefined[key]}', its data type should be 'string'`;
1018-
Countly.logWarning('setUserProperties', message);
1056+
Countly.logWarning('setUserProperties', `skipping value for key '${key.toString()}', due to unsupported data type '${typeof customAndPredefined[key]}', its data type should be 'string'`);
10191057
}
10201058
}
10211059

@@ -1260,8 +1298,7 @@ Countly.giveConsentInit = async function (args) {
12601298
} else if (Array.isArray(args)) {
12611299
features = args;
12621300
} else {
1263-
const message = `unsupported data type '${typeof args}'`;
1264-
Countly.logWarning('giveConsentInit', message);
1301+
Countly.logWarning('giveConsentInit', `unsupported data type '${typeof args}'`);
12651302
}
12661303
await CountlyReactNative.giveConsentInit(features);
12671304
};
@@ -1838,8 +1875,7 @@ Countly.validateUserDataValue = async (stringValue, stringName, functionName) =>
18381875
}
18391876

18401877
// validating that value should be parceable to int.
1841-
message = await Countly.validateParseInt(stringValue, stringName, functionName);
1842-
return message;
1878+
return await Countly.validateParseInt(stringValue, stringName, functionName);
18431879
};
18441880

18451881
/**
@@ -1856,8 +1892,7 @@ Countly.validateUserDataType = async (stringValue, stringName, functionName) =>
18561892
return null;
18571893
}
18581894
if (typeof stringValue === 'string') {
1859-
message = `unsupported data type '${typeof stringValue}', its data type should be 'number'`;
1860-
Countly.logWarning(functionName, message);
1895+
Countly.logWarning(functionName, `unsupported data type '${typeof stringValue}', its data type should be 'number'`);
18611896
return null;
18621897
}
18631898

android/src/main/java/ly/count/android/sdk/react/CountlyReactNative.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,25 @@ public void getCurrentDeviceId(Promise promise) {
353353
}
354354

355355
@ReactMethod
356-
public void getDeviceIdAuthor(ReadableArray args, final Callback myCallback) {
356+
public void getDeviceIDType(Promise promise){
357357
DeviceIdType deviceIDType = Countly.sharedInstance().deviceId().getType();
358-
if (deviceIDType == null) {
359-
log("getDeviceIdAuthor, deviceIdAuthorNotFound", LogLevel.DEBUG);
360-
myCallback.invoke("deviceIdAuthorNotFound");
361-
} else {
362-
log("getDeviceIdAuthor: " + deviceIDType, LogLevel.DEBUG);
363-
if (deviceIDType == DeviceIdType.DEVELOPER_SUPPLIED) {
364-
myCallback.invoke("developerProvided");
365-
} else {
366-
myCallback.invoke("sdkGenerated");
367-
}
358+
String deviceIDTypeString = null;
359+
switch (deviceIDType) {
360+
case DEVELOPER_SUPPLIED:
361+
deviceIDTypeString = "DS";
362+
break;
363+
case TEMPORARY_ID:
364+
deviceIDTypeString = "TID";
365+
break;
366+
case OPEN_UDID:
367+
case ADVERTISING_ID:
368+
deviceIDTypeString = "SG";
369+
break;
370+
default:
371+
deviceIDTypeString = "";
372+
break;
368373
}
374+
promise.resolve(deviceIDTypeString);
369375
}
370376

371377
@ReactMethod

ios/src/CountlyReactNative.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ typedef void (^Result)(id _Nullable result);
1616
- (void)enableCrashReporting;
1717
- (void)addCrashLog:(NSArray *_Nullable)arguments;
1818

19-
- (void)getDeviceIdAuthor:(NSArray *_Nullable)arguments callback:(RCTResponseSenderBlock _Nullable)callback;
2019
- (void)changeDeviceId:(NSArray *_Nullable)arguments;
2120
- (void)enableParameterTamperingProtection:(NSArray *_Nullable)arguments;
2221
- (void)pinnedCertificates:(NSArray *_Nullable)arguments;

ios/src/CountlyReactNative.m

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,17 @@ - (void) populateConfig:(id) json {
112112
NSString *serverurl = json[@"serverURL"];
113113
NSString *appkey = json[@"appKey"];
114114
NSString *deviceID = json[@"deviceID"];
115-
if (deviceID != nil && deviceID != (NSString *)[NSNull null] && ![deviceID isEqual:@""]) {
116-
config.deviceID = deviceID;
117-
}
118115
config.appKey = appkey;
119116
config.host = serverurl;
120117

118+
if (deviceID != nil && deviceID != (NSString *)[NSNull null] && ![deviceID isEqual:@""]) {
119+
if ([deviceID isEqual:@"TemporaryDeviceID"]) {
120+
config.deviceID = CLYTemporaryDeviceID;
121+
} else {
122+
config.deviceID = deviceID;
123+
}
124+
}
125+
121126
if (json[@"loggingEnabled"]) {
122127
config.enableDebug = YES;
123128
config.internalLogLevel = CLYInternalLogLevelVerbose;
@@ -378,27 +383,36 @@ + (void)log:(NSString *)theMessage {
378383
});
379384
}
380385

381-
RCT_EXPORT_METHOD(getDeviceIdAuthor : (NSArray *)arguments callback : (RCTResponseSenderBlock)callback) {
386+
RCT_REMAP_METHOD(getDeviceIDType, getDeviceIDTypeWithResolver : (RCTPromiseResolveBlock)resolve rejecter : (RCTPromiseRejectBlock)reject) {
382387
dispatch_async(dispatch_get_main_queue(), ^{
383-
id value = [Countly.sharedInstance deviceIDType];
384-
if (value) {
385-
callback(@[ value ]);
386-
} else {
387-
NSString *value = @"deviceIDAuthorNotFound";
388-
callback(@[ value ]);
389-
}
388+
CLYDeviceIDType deviceIDType = [Countly.sharedInstance deviceIDType];
389+
NSString *deviceIDTypeString = NULL;
390+
if ([deviceIDType isEqualToString:CLYDeviceIDTypeCustom]) {
391+
deviceIDTypeString = @"DS";
392+
} else if ([deviceIDType isEqualToString:CLYDeviceIDTypeIDFV]) {
393+
deviceIDTypeString = @"SG";
394+
} else if ([deviceIDType isEqualToString:CLYDeviceIDTypeTemporary]) {
395+
deviceIDTypeString = @"TID";
396+
} else {
397+
deviceIDTypeString = @"";
398+
}
399+
resolve(deviceIDTypeString);
390400
});
391401
}
392402

393403
RCT_EXPORT_METHOD(changeDeviceId : (NSArray *)arguments) {
394404
dispatch_async(dispatch_get_main_queue(), ^{
395-
NSString *newDeviceID = [arguments objectAtIndex:0];
396-
NSString *onServerString = [arguments objectAtIndex:1];
397-
if ([onServerString isEqual:@"1"]) {
398-
[Countly.sharedInstance setNewDeviceID:newDeviceID onServer:YES];
399-
} else {
400-
[Countly.sharedInstance setNewDeviceID:newDeviceID onServer:NO];
401-
}
405+
NSString *newDeviceID = [arguments objectAtIndex:0];
406+
if ([newDeviceID isEqual:@"TemporaryDeviceID"]) {
407+
newDeviceID = CLYTemporaryDeviceID;
408+
}
409+
410+
NSString *onServerString = [arguments objectAtIndex:1];
411+
if ([onServerString isEqual:@"1"]) {
412+
[Countly.sharedInstance setNewDeviceID:newDeviceID onServer:YES];
413+
} else {
414+
[Countly.sharedInstance setNewDeviceID:newDeviceID onServer:NO];
415+
}
402416
});
403417
}
404418

0 commit comments

Comments
 (0)