Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

[sdk-184] APM changes implemented for app_start, foreground and background. #80

Merged
merged 7 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## 20.11.0
* !! Consent change !! To use remote config, you now need to give "remote-config" consent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there should be a lot more entries in this changelog.

* !! Push breaking changes !! Google play vulnerability issue fixed due to broadcast receiver for android push notification
* Added Surveys and NPS feedback widgets
* Added replaceAllAppKeysInQueueWithCurrentAppKey method to replace all app keys in queue with the current app key
* Added removeDifferentAppKeysFromQueue method to remove all different app keys from the queue
* Added setStarRatingDialogTexts method to set text's for different fields of star rating dialog
* Updated underlying android SDK to 20.11.2
* Updated underlying ios SDK to 20.11.1

## 20.4.0
20 changes: 17 additions & 3 deletions Countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ Countly.appKey = "";
Countly.ready = false;
Countly.version = "20.11.0";
Countly.isDebug = false;
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if (/android/i.test(userAgent)) {
if (window.cordova.platformId == "android") {
Countly.isAndroid = true;
Countly.messagingMode = {"TEST": "2", "PRODUCTION": "0"};
}
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
if (window.cordova.platformId == "ios") {
Countly.isiOS = true;
Countly.messagingMode = {"TEST": "1", "PRODUCTION": "0", "ADHOC": "2"};
}
Expand Down Expand Up @@ -520,6 +519,21 @@ Countly.askForFeedback = function(widgetId, buttonText){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","askForFeedback",[widgetId, buttonText || ""]);
}

// Call this function when app is loaded, so that the app launch duration can be recorded.
// Should be call after init.
Countly.appLoadingFinished = async function(){
Countly.isInitialized().then((result) => {
if(result != "true") {
if(Countly.isDebug){
console.warn('[CountlyCordova] appLoadingFinished, init must be called before appLoadingFinished');
}
return;
}
},(err) => {
console.error(err);
});
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","appLoadingFinished",[]);

/**
* Get a list of available feedback widgets for this device ID
*/
Expand Down
34 changes: 0 additions & 34 deletions change.log

This file was deleted.

4 changes: 2 additions & 2 deletions hooks/createService.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ module.exports = function(context) {
});

var countlyFiles = [
__dirname +'/../../../platforms/ios/Pods/Countly/' +'CountlyNotificationService.h',
__dirname +'/../../../platforms/ios/Pods/Countly/' +'CountlyNotificationService.m'
__dirname +'/../../../platforms/ios/Pods/CountlyPod/' +'CountlyNotificationService.h',
__dirname +'/../../../platforms/ios/Pods/CountlyPod/' +'CountlyNotificationService.m'
];
extFiles.push(countlyFiles[0]);
extFiles.push(countlyFiles[1]);
Expand Down
14 changes: 10 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
<title>Countly Cordova Demo App</title>
</head>

<body>
<body onload="onBodyLoad()">
<div class="app">
<h1 class="ui center aligned header">Countly Cordova Demo App</h1>
<img class="ui centered medium image" src="http://try.count.ly/images/dashboard/countly_logo.svg">
<button onclick="app.init()" class="fluid ui green button">Init</button>
<button onclick="app.start()" class="fluid ui green button">Start</button>
<button onclick="app.stop()" class="fluid ui red button">Stop</button>
<button onclick="app.halt()" class="fluid ui red button">Halt</button>
Expand Down Expand Up @@ -147,12 +146,18 @@ <h1 class="ui center aligned header">Countly Cordova Demo App</h1>

</div>
<script type="text/javascript">
document.addEventListener("deviceready", function(){
function onBodyLoad() {
console.log("[CountlyCordova] onBodyLoad");
document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
console.log("[CountlyCordova] deviceready");
Countly.onNotification(function(theNotification){
console.log("[CountlyCordova] onNotification : " + JSON.stringify(theNotification));
});
});
app.init();
}
app = {};
function makeid() {
var text = "";
Expand Down Expand Up @@ -188,6 +193,7 @@ <h1 class="ui center aligned header">Countly Cordova Demo App</h1>
Countly.pushTokenType(Countly.messagingMode.TEST); // Set messaging mode for push notifications

Countly.init("https://try.count.ly", "YOUR_API_KEY").then((result) => {
Countly.appLoadingFinished();
ijunaid marked this conversation as resolved.
Show resolved Hide resolved
Countly.setStarRatingDialogTexts("Title", "Message", "Dismiss");
/**
* Push notifications settings
Expand Down
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<config-file target="res/xml/config.xml" parent="/*">
<feature name="CountlyCordova">
<param name="android-package" value="ly.count.android.sdk.CountlyCordova" />
<param name="onload" value="true" />
ijunaid marked this conversation as resolved.
Show resolved Hide resolved
</feature>
<preference name="GradlePluginGoogleServicesEnabled" value="true" />
<preference name="GradlePluginGoogleServicesVersion" value="4.2.0" />
Expand Down
32 changes: 31 additions & 1 deletion src/android/CountlyCordova.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,23 @@ public enum CountlyMessagingMode {
TEST,
PRODUCTION,
}
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
Context context = this.cordova.getActivity().getApplicationContext();
if(countlyNative == null){
countlyNative = new CountlyNative( this.cordova.getActivity(), this.cordova.getActivity().getApplicationContext());
}
}

@Override
public void pluginInitialize() {
ijunaid marked this conversation as resolved.
Show resolved Hide resolved

}
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
Context context = this.cordova.getActivity().getApplicationContext();

if ("init".equals(action)) {
callbackContext.success(countlyNative.init(args));
}
Expand Down Expand Up @@ -230,6 +241,9 @@ public void callback(String result) {
}
});
}
else if("appLoadingFinished".equals(action)){
callbackContext.success(countlyNative.appLoadingFinished(args));
}
else if ("getFeedbackWidgets".equals(action)) {
countlyNative.getFeedbackWidgets(args, new CountlyNative.JSONObjectCallback() {
@Override
Expand Down Expand Up @@ -292,4 +306,20 @@ else if("enableApm".equals(action)){
return true;
}

@Override
public void onResume(boolean multitasking) {
super.onResume(multitasking);
countlyNative.onHostResume();
}

@Override
public void onPause(boolean multitasking) {
super.onPause(multitasking);
countlyNative.onHostPause();
}

@Override
public void onStart() {
super.onStart();
}
}
25 changes: 24 additions & 1 deletion src/android/CountlyNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class CountlyNative {
private CountlyConfig config = new CountlyConfig();
private static Callback notificationListener = null;
private static String lastStoredNotification = null;

private final Set<String> validConsentFeatureNames = new HashSet<String>(Arrays.asList(
Countly.CountlyFeatureNames.sessions,
Countly.CountlyFeatureNames.events,
Expand All @@ -63,6 +64,9 @@ public class CountlyNative {
public CountlyNative(Activity _activity, Context _context){
this.activity = _activity;
this.context = _context;
Countly.sharedInstance();
this.config.enableManualAppLoadedTrigger();
this.config.enableManualForegroundBackgroundTriggerAPM();
}
public static void onNotification(Map<String, String> notification){
JSONObject json = new JSONObject(notification);
Expand Down Expand Up @@ -113,6 +117,8 @@ public String init(JSONArray args){
this.config.setApplication(activity.getApplication());
}
Countly.sharedInstance().init(this.config);
Countly.sharedInstance().apm().triggerForeground();

return "initialized: success";
}catch (JSONException jsonException){
return jsonException.toString();
Expand Down Expand Up @@ -904,6 +910,11 @@ public String askForStarRating(JSONArray args){
return "askForStarRating success.";
}

public String appLoadingFinished(JSONArray args){
this.log("appLoadingFinished", args);
Countly.sharedInstance().apm().setAppIsLoaded();
return "appLoadingFinished success!";
}
public String getFeedbackWidgets(JSONArray args, final JSONObjectCallback theCallback){
Countly.sharedInstance().feedback().getAvailableFeedbackWidgets(new RetrieveFeedbackWidgets() {
@Override
Expand Down Expand Up @@ -1066,7 +1077,7 @@ public String recordNetworkTrace(JSONArray args){

public String enableApm(JSONArray args){
this.log("enableApm", args);
this.config.setRecordAppStartTime(false);
this.config.setRecordAppStartTime(true);
return "enableApm success.";
}

Expand Down Expand Up @@ -1098,5 +1109,17 @@ static void log(String message, Throwable tr, LogLevel logLevel) {
}
}

public void onHostResume() {
if(Countly.sharedInstance().isInitialized()) {
Countly.sharedInstance().apm().triggerForeground();
}
}

public void onHostPause() {
if(Countly.sharedInstance().isInitialized()) {
Countly.sharedInstance().apm().triggerBackground();
}
}


}
1 change: 1 addition & 0 deletions src/ios/CountlyCordova.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@
- (void)endTrace:(CDVInvokedUrlCommand*)command;
- (void)recordNetworkTrace:(CDVInvokedUrlCommand*)command;
- (void)enableApm:(CDVInvokedUrlCommand*)command;
- (void)appLoadingFinished:(CDVInvokedUrlCommand*)command;

@end
12 changes: 12 additions & 0 deletions src/ios/CountlyCordova.m
Original file line number Diff line number Diff line change
Expand Up @@ -863,5 +863,17 @@ - (void)enableApm:(CDVInvokedUrlCommand*)command
}];
}

- (void)appLoadingFinished:(CDVInvokedUrlCommand*)command
{
if(countlyNative == nil){
countlyNative = CountlyNative.new;
}
[countlyNative onCall: @"appLoadingFinished" commandString: command.arguments callback: ^(NSString * theResult)
{
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: theResult];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}


@end
6 changes: 6 additions & 0 deletions src/ios/CountlyNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,12 @@ - (void) onCall:(NSString *)method commandString:(NSArray *)command callback:(Re
config.enablePerformanceMonitoring = YES;
result(@"enableApm!");

}else if ([@"appLoadingFinished" isEqualToString:method]) {
dispatch_async(dispatch_get_main_queue(), ^ {
[Countly.sharedInstance appLoadingFinished];
});
result(@"appLoadingFinished!");

} else {
COUNTLY_CORDOVA_LOG(@"Countly Bridge Method Not Implemented %@", method);
result(@"Countly Bridge Method Not Implemented");
Expand Down