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 2 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
22 changes: 18 additions & 4 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.04";
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 @@ -505,7 +504,22 @@ Countly.askForStarRating = function(callback){
Countly.askForFeedback = function(widgetId, buttonText){
cordova.exec(Countly.onSuccess,Countly.onError,"CountlyCordova","askForFeedback",[widgetId, buttonText || ""]);
}
// FEEDBACK-WORK

// 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",[]);
}

// Push Notification
Countly.sendPushToken = function(options){
Expand Down
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
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<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 @@ -150,6 +149,7 @@ <h1 class="ui center aligned header">Countly Cordova Demo App</h1>
Countly.onNotification(function(theNotification){
console.log("[CountlyCordova] onNotification : " + JSON.stringify(theNotification));
});
app.init();
});
app = {};
function makeid() {
Expand Down Expand Up @@ -185,6 +185,7 @@ <h1 class="ui center aligned header">Countly Cordova Demo App</h1>
}); // Set Automatic value download happens when the SDK is initiated or when the device ID is changed.

Countly.init("https://try.count.ly", "YOUR_API_KEY").then((result) => {
Countly.appLoadingFinished();
ijunaid marked this conversation as resolved.
Show resolved Hide resolved
/**
* Push notifications settings
* Should be call after init
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>
</config-file>

Expand Down
32 changes: 31 additions & 1 deletion src/android/CountlyCordova.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,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 @@ -226,6 +237,9 @@ public void callback(String result) {
}
});
}
else if("appLoadingFinished".equals(action)){
callbackContext.success(countlyNative.appLoadingFinished(args));
}
else if("sendPushToken".equals(action)){
callbackContext.success(countlyNative.sendPushToken(args));
}
Expand Down Expand Up @@ -256,4 +270,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();
}
}
26 changes: 25 additions & 1 deletion src/android/CountlyNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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 @@ -59,6 +60,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 @@ -104,6 +108,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 @@ -883,6 +889,12 @@ 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 sendPushToken(JSONArray args){
try {
this.log("sendPushToken", args);
Expand Down Expand Up @@ -973,7 +985,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 @@ -1005,5 +1017,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 @@ -76,5 +76,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 @@ -791,5 +791,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 @@ -989,6 +989,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