Skip to content

Commit 1396dab

Browse files
Adding functinality to set location in init. Fixes for a few issues. Merge pull request #24 from Countly/dev-junaid
sertLocationInit Added iOS/Android SDK's version updated Application set for config on Android side Automatic view tracking removed iOS recordNetworkTrace issue fixed
2 parents 5b9693d + 5bbaa38 commit 1396dab

File tree

11 files changed

+122
-63
lines changed

11 files changed

+122
-63
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## 20.4.6
2+
* Adding APM calls
3+
* Adding functionality to enable attribution
4+
* Added call to retrieve the currently used device ID
5+
* Updated "init" call to async
6+
* Added "setLoggingEnabled" call
7+
* Added call to set location during init time
8+
* Fixed issues related to location tracking
9+
* Fixed issue where ios crash handling was enabled without enabling it
10+
* Deprecated "enableLogging" and "disableLogging" calls
11+
* Updated underlying android SDK to 20.04.5
12+
* Updated underlying ios SDK to 20.04.3
13+
14+
## 20.4.5
15+
* Fixed "onNotification" listener
16+
* Fixed a few issues with setting location
17+
* Fixed bug with push messaging modes
18+
* Reworked android push notifications (!! PREVIOUS ANDROID PUSH SETUP SHOULD BE REMOVED AFTER UPDATE !!)
19+
* Adding android star rating callback
20+
* Tweaked android push notifications to show up only in the notification bar
21+
* Fixed SDK version and SDK name metrics to show not the bridged SDK values but the ones from the react native SDK
22+
23+
* Please refer to this documentation for released work https://support.count.ly/hc/en-us/articles/360037813231-React-Native-Bridge-

Countly.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,6 @@ Countly.recordView = function(recordView, segments){
117117
CountlyReactNative.recordView(args);
118118
};
119119

120-
/**
121-
* Enable automatic view tracking
122-
* Should be call before Countly init
123-
* @param enabled Expected value is boolean
124-
*/
125-
Countly.setViewTracking = async function(enabled = true){
126-
if(typeof enabled !== 'boolean' && typeof enabled !== 'string') {
127-
if(await CountlyReactNative.isLoggingEnabled()) {
128-
console.warn("setViewTracking, unsupported data type [" + typeof enabled+ "]");
129-
}
130-
return;
131-
}
132-
if(typeof enabled === 'string') {
133-
enabled = (enabled === "true"); // Typecast from string to boolean
134-
}
135-
CountlyReactNative.setAutomaticViewTracking([enabled]);
136-
}
137-
138120
/**
139121
*
140122
* Set Push notification messaging mode and callbacks for push notifications
@@ -150,7 +132,6 @@ Countly.pushTokenType = function(tokenType, channelName, channelDescription){
150132
Countly.sendPushToken = function(options){
151133
var args = [];
152134
args.push(options.token || "");
153-
args.push((options.messagingMode || "").toString());
154135
CountlyReactNative.sendPushToken(args);
155136
}
156137

@@ -226,6 +207,24 @@ Countly.demo = function(){
226207

227208
}
228209

210+
/**
211+
* Set user initial location
212+
* Should be call before init
213+
* @param {ISO Country code for the user's country} countryCode
214+
* @param {Name of the user's city} city
215+
* @param {comma separate lat and lng values. For example, "56.42345,123.45325"} location
216+
* @param {IP address of user's} ipAddress
217+
* */
218+
219+
Countly.setLocationInit = function(countryCode, city, location, ipAddress){
220+
var args = [];
221+
args.push(countryCode || "null");
222+
args.push(city || "null");
223+
args.push(location || "null");
224+
args.push(ipAddress || "null");
225+
CountlyReactNative.setLocationInit(args);
226+
}
227+
229228
Countly.setLocation = function(countryCode, city, location, ipAddress){
230229
var args = [];
231230
args.push(countryCode || "null");

CountlyReactNative.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ Pod::Spec.new do |s|
4646
end
4747

4848
s.dependency "React"
49-
s.dependency "Countly", '20.04.2'
49+
s.dependency "Countly", '20.04.3'
5050
end

android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ def safeExtGet(prop, fallback) {
1616
}
1717

1818
android {
19-
compileSdkVersion safeExtGet('compileSdkVersion', 28)
19+
compileSdkVersion safeExtGet('compileSdkVersion', 29)
2020

2121
defaultConfig {
22-
minSdkVersion safeExtGet('minSdkVersion', 16)
23-
targetSdkVersion safeExtGet('targetSdkVersion', 28)
22+
minSdkVersion safeExtGet('minSdkVersion', 17)
23+
targetSdkVersion safeExtGet('targetSdkVersion', 29)
2424

2525
versionCode 2
2626
versionName "1.1"
@@ -44,7 +44,7 @@ repositories {
4444

4545
dependencies {
4646
implementation "com.facebook.react:react-native:${safeExtGet('reactNativeVersion', '+')}"
47-
implementation 'ly.count.android:sdk:20.04.4'
47+
implementation 'ly.count.android:sdk:20.04.5'
4848

4949
//if any version higher than 18.0.0 is used then it forces AndroidX
5050
implementation 'com.google.firebase:firebase-messaging:18.0.0'

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

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public String toString(){
6565
}
6666

6767
public class CountlyReactNative extends ReactContextBaseJavaModule {
68-
private String COUNTLY_RN_SDK_VERSION_STRING = "20.04.5";
68+
private String COUNTLY_RN_SDK_VERSION_STRING = "20.04.6";
6969
private String COUNTLY_RN_SDK_NAME = "js-rnb-android";
7070

7171
private static CountlyConfig config = new CountlyConfig();
@@ -117,6 +117,8 @@ public void init(ReadableArray args, Promise promise){
117117
Countly.sharedInstance().COUNTLY_SDK_VERSION_STRING = COUNTLY_RN_SDK_VERSION_STRING;
118118

119119
this.config.setContext(_reactContext);
120+
Activity activity = getCurrentActivity();
121+
this.config.setApplication(activity.getApplication());
120122
if(deviceId == null || "".equals(deviceId)){
121123
}else{
122124
if(deviceId.equals("TemporaryDeviceID")){
@@ -250,6 +252,27 @@ public void pinnedCertificates(ReadableArray args){
250252
return new String[]{};
251253
}
252254

255+
@ReactMethod
256+
public void setLocationInit(ReadableArray args){
257+
String countryCode = args.getString(0);
258+
String city = args.getString(1);
259+
String location = args.getString(2);
260+
String ipAddress = args.getString(3);
261+
if("null".equals(countryCode)){
262+
countryCode = null;
263+
}
264+
if("null".equals(city)){
265+
city = null;
266+
}
267+
if("null".equals(location)){
268+
location = null;
269+
}
270+
if("null".equals(ipAddress)){
271+
ipAddress = null;
272+
}
273+
this.config.setLocation(countryCode, city, location, ipAddress);
274+
}
275+
253276
@ReactMethod
254277
public void setLocation(ReadableArray args){
255278
String countryCode = args.getString(0);
@@ -403,12 +426,6 @@ public void recordView(ReadableArray args){
403426
Countly.sharedInstance().recordView(viewName, segmentation);
404427
}
405428

406-
@ReactMethod
407-
public void setAutomaticViewTracking(ReadableArray args){
408-
Boolean flag = args.getBoolean(0);
409-
this.config.setViewTracking(flag);
410-
}
411-
412429
@ReactMethod
413430
public void setUserData(ReadableArray args){
414431
Map<String, String> bundle = new HashMap<String, String>();
@@ -428,16 +445,7 @@ public void setUserData(ReadableArray args){
428445
@ReactMethod
429446
public void sendPushToken(ReadableArray args){
430447
String pushToken = args.getString(0);
431-
int messagingMode = Integer.parseInt(args.getString(1));
432-
433-
Countly.CountlyMessagingMode mode = null;
434-
if(messagingMode == 0){
435-
mode = Countly.CountlyMessagingMode.PRODUCTION;
436-
}
437-
else{
438-
mode = Countly.CountlyMessagingMode.TEST;
439-
}
440-
Countly.sharedInstance().onRegistrationId(pushToken, mode);
448+
CountlyPush.onTokenRefresh(pushToken);
441449
}
442450

443451
@ReactMethod
@@ -668,12 +676,12 @@ public void removeConsent(ReadableArray featureNames){
668676

669677
@ReactMethod
670678
public void giveAllConsent(){
671-
Countly.sharedInstance().consent().giveConsent(validConsentFeatureNames.toArray(new String[validConsentFeatureNames.size()]));
679+
Countly.sharedInstance().consent().giveConsentAll();
672680
}
673681

674682
@ReactMethod
675683
public void removeAllConsent(){
676-
Countly.sharedInstance().consent().removeConsent(validConsentFeatureNames.toArray(new String[validConsentFeatureNames.size()]));
684+
Countly.sharedInstance().consent().removeConsentAll();
677685
}
678686

679687

example/Example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Example extends Component {
4545
Countly.setLoggingEnabled(true); // Enable countly internal debugging logs
4646
Countly.enableCrashReporting(); // Enable crash reporting to report unhandled crashes to Countly
4747
Countly.setRequiresConsent(true); // Set that consent should be required for features to work.
48-
Countly.setViewTracking(true); // Enable automatic view tracking
48+
Countly.setLocationInit("TR", "Istanbul", "41.0082,28.9784", "10.2.33.12"); // Set user initial location.
4949

5050
/** Optional settings for Countly initialisation */
5151
Countly.enableParameterTamperingProtection("salt"); // Set the optional salt to be used for calculating the checksum of requested data which will be sent with each request

example/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rm App.js
1111
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/App.js --output App.js
1212
curl https://raw.githubusercontent.com/Countly/countly-sdk-react-native-bridge/master/example/Example.js --output Example.js
1313

14-
14+
1515

1616
cd ./ios
1717
pod install

ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ platform :ios, '8.0'
22

33
target 'countly-sdk-react-native-bridge' do
44
use_frameworks!
5-
pod 'Countly', "20.04.2"
5+
pod 'Countly', "20.04.3"
66
end

ios/src/CountlyReactNative.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ typedef void (^Result)(id _Nullable result);
1212
- (void)recordView:(NSArray*_Nullable)arguments;
1313

1414
- (void)setHttpPostForced:(NSArray*_Nullable)arguments;
15+
- (void)setLocationInit:(NSArray*_Nullable)arguments;
1516
- (void)setLocation:(NSArray*_Nullable)arguments;
1617
- (void)enableCrashReporting;
1718
- (void)addCrashLog:(NSArray*_Nullable)arguments;

ios/src/CountlyReactNative.m

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#import "CountlyRemoteConfig.h"
1212
#import "CountlyCommon.h"
1313

14-
NSString* const kCountlyReactNativeSDKVersion = @"20.04.5";
14+
NSString* const kCountlyReactNativeSDKVersion = @"20.04.6";
1515
NSString* const kCountlyReactNativeSDKName = @"js-rnb-ios";
1616

1717
CountlyConfig* config = nil;
@@ -120,18 +120,6 @@ @implementation CountlyReactNative
120120
});
121121
}
122122

123-
RCT_EXPORT_METHOD(setAutomaticViewTracking:(NSArray*)arguments)
124-
{
125-
BOOL boolean = [[arguments objectAtIndex:0] boolValue];
126-
if(boolean) {
127-
[self addCountlyFeature:CLYAutoViewTracking];
128-
}
129-
else {
130-
[self removeCountlyFeature:CLYAutoViewTracking];
131-
}
132-
[Countly.sharedInstance setIsAutoViewTrackingActive:boolean];
133-
}
134-
135123
RCT_EXPORT_METHOD(setLoggingEnabled:(NSArray*)arguments)
136124
{
137125
dispatch_async(dispatch_get_main_queue(), ^ {
@@ -179,7 +167,10 @@ @implementation CountlyReactNative
179167
dispatch_async(dispatch_get_main_queue(), ^ {
180168

181169
NSString* token = [arguments objectAtIndex:0];
182-
NSString* messagingMode = [arguments objectAtIndex:1];
170+
NSString* messagingMode = @"1";
171+
if(config.pushTestMode == nil || [config.pushTestMode isEqual: @""] || [config.pushTestMode isEqualToString:@"CLYPushTestModeTestFlightOrAdHoc"]) {
172+
messagingMode = @"0";
173+
}
183174
NSString *urlString = [ @"" stringByAppendingFormat:@"%@?device_id=%@&app_key=%@&token_session=1&test_mode=%@&ios_token=%@", config.host, [Countly.sharedInstance deviceID], config.appKey, messagingMode, token];
184175
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
185176
[request setHTTPMethod:@"GET"];
@@ -433,6 +424,43 @@ + (void) log: (NSString *) theMessage{
433424
});
434425
}
435426

427+
RCT_EXPORT_METHOD(setLocationInit:(NSArray*)arguments)
428+
{
429+
dispatch_async(dispatch_get_main_queue(), ^ {
430+
if (config == nil){
431+
config = CountlyConfig.new;
432+
}
433+
NSString* countryCode = [arguments objectAtIndex:0];
434+
NSString* city = [arguments objectAtIndex:1];
435+
NSString* locationString = [arguments objectAtIndex:2];
436+
NSString* ipAddress = [arguments objectAtIndex:3];
437+
438+
if(locationString != nil && ![locationString isEqualToString:@"null"] && [locationString containsString:@","]){
439+
@try{
440+
NSArray *locationArray = [locationString componentsSeparatedByString:@","];
441+
NSString* latitudeString = [locationArray objectAtIndex:0];
442+
NSString* longitudeString = [locationArray objectAtIndex:1];
443+
444+
double latitudeDouble = [latitudeString doubleValue];
445+
double longitudeDouble = [longitudeString doubleValue];
446+
config.location = (CLLocationCoordinate2D){latitudeDouble,longitudeDouble};
447+
}
448+
@catch(NSException *exception){
449+
NSLog(@"[Countly] Invalid location: %@", locationString);
450+
}
451+
}
452+
if(city != nil && ![city isEqualToString:@"null"]) {
453+
config.city = city;
454+
}
455+
if(countryCode != nil && ![countryCode isEqualToString:@"null"]) {
456+
config.ISOCountryCode = countryCode;
457+
}
458+
if(ipAddress != nil && ![ipAddress isEqualToString:@"null"]) {
459+
config.IP = ipAddress;
460+
}
461+
});
462+
}
463+
436464
RCT_EXPORT_METHOD(setLocation:(NSArray*)arguments)
437465
{
438466
dispatch_async(dispatch_get_main_queue(), ^ {
@@ -886,8 +914,8 @@ + (void) log: (NSString *) theMessage{
886914
int responseCode = [[arguments objectAtIndex:1] intValue];
887915
int requestPayloadSize = [[arguments objectAtIndex:2] intValue];
888916
int responsePayloadSize = [[arguments objectAtIndex:3] intValue];
889-
int startTime = [[arguments objectAtIndex:4] intValue];
890-
int endTime = [[arguments objectAtIndex:5] intValue];
917+
long long startTime = [[arguments objectAtIndex:4] longLongValue];
918+
long long endTime = [[arguments objectAtIndex:5] longLongValue];
891919
[Countly.sharedInstance recordNetworkTrace: networkTraceKey requestPayloadSize: requestPayloadSize responsePayloadSize: responsePayloadSize responseStatusCode: responseCode startTime: startTime endTime: endTime];
892920

893921
});

0 commit comments

Comments
 (0)