Skip to content

Commit

Permalink
Event tracking support
Browse files Browse the repository at this point in the history
  • Loading branch information
manavo committed Oct 15, 2024
1 parent 6e9e01e commit 56ef573
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/io/doorbell/android/Doorbell.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,35 @@ public Doorbell impression() {
return this;
}

public Doorbell track(String userID, String eventName, JSONObject attributes) {
DoorbellApi newApi = new DoorbellApi(this.mActivity);
newApi.setAppId(this.mApi.getAppId());
newApi.setApiKey(this.mApi.getApiKey());

newApi.setCallback(new RestCallback() {
@Override
public void success(Object obj) {
try {
JSONObject response = (JSONObject) obj;

if (response.has("action") && !response.optString("action").equalsIgnoreCase("")) {
String action = response.getString("action");

if (action.equalsIgnoreCase("show")) {
Doorbell.this.show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});

newApi.track(userID, eventName, attributes);

return this;
}

public Doorbell captureScreenshot() {
try {
View v = this.mActivity.getWindow().getDecorView().getRootView();
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/io/doorbell/android/DoorbellApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.doorbell.android.callbacks.OnErrorCallback;
import io.doorbell.android.manavo.rest.RestApi;
import io.doorbell.android.manavo.rest.RestCache;
import io.doorbell.android.manavo.rest.RestCallback;
import io.doorbell.android.manavo.rest.RestErrorCallback;

import org.json.JSONArray;
Expand All @@ -11,6 +12,7 @@
import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Base64;
import android.util.Log;
import android.widget.Toast;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -54,10 +56,18 @@ public void setAppId(long id) {
this.mAppId = id;
}

public long getAppId() {
return this.mAppId;
}

public void setApiKey(String key) {
this.mApiKey = key;
}

public String getApiKey() {
return this.mApiKey;
}

public void setLanguage(String language) {
this.language = language;
}
Expand Down Expand Up @@ -102,6 +112,18 @@ public void open() {
this.post("applications/" + this.mAppId + "/open?key=" + this.mApiKey);
}

public void track(String userID, String eventName, JSONObject attributes) {
this.setLoadingMessage(null);

this.addParameter("external_user_id", userID);
this.addParameter("name", eventName);
if (attributes != null) {
this.addParameter("attributes_json", attributes);
}

this.post("applications/" + this.mAppId + "/event?key=" + this.mApiKey);
}

public void sendFeedbackWithScreenshot(String message, String email, JSONObject properties, String name, Bitmap screenshot) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Expand Down

0 comments on commit 56ef573

Please # to comment.