Skip to content

Commit

Permalink
More analytics/kb (#10)
Browse files Browse the repository at this point in the history
* filter parity with iOS

* sort type consitency

* add analytics class supporting ATC and Conversion methods, update readme, update example app

* PR changes

* ints

* update examples

* pdp albums set album_id

* add action link clicked and load more anlaytics

* pr changes and update readme

* update readme text for action click

* make private
  • Loading branch information
kj13ennett authored Jul 23, 2019
1 parent 5b53805 commit 74e6773
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Once an album has loaded photos from the server, it will instantiate `PXLPhoto`
#### Opened Widget
On the first load of an album, an "Opened Widget" analytics event will be fired automatically

#### Load More
On calls to loadNextPageOfPhotos (except the first), a "Load More" analytics event will be fired automatically

#### Opened Lightbox
To fire an opened ligtbox event, simply call the `openedLightbox` method of the PXLPhoto that is being opened, and an "Opened Lightbox" event will be fired containing all of the necessary analytics information.

Expand All @@ -83,6 +86,15 @@ To fire an opened ligtbox event, simply call the `openedLightbox` method of the
photo.openedLightbox(context);
```

#### Action Clicked
To fire an action clicked event, simply call the `actionClicked` method of the PXLPhoto that the action click is being driven from and pass in the URL of the link that the user is being redirected to. An "Action Clicked" event will be fired containing all of the necessary analytics information.

```
#!java
photo.actionClicked("https://ca.puma.com/en/ca/pd/clyde-court-core-basketball-shoes/191712.html", context);
```

### Ecommerce Analytics

For triggering all ecommerce analytics events within your app, you'll want to use the `PXLAnalytics` class. Instantiate one with the application context:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
private void createAlbum() {
Context c = this.getApplicationContext();
PXLClient.initialize("196i8ZzIAhKU8dO2kDe");
album = new PXLPdpAlbum("rr", c);
album = new PXLAlbum("4503434", c);
PXLAlbumFilterOptions fo = new PXLAlbumFilterOptions();
fo.minTwitterFollowers = 0;
fo.minInstagramFollowers = 0;
Expand Down Expand Up @@ -278,6 +278,7 @@ private void updateDetailView(PXLPhoto photo) {
}

photo.openedLightbox(c); // Opened Lightbox Analytics Example
photo.actionClicked("https://ca.puma.com/en/ca/pd/clyde-court-core-basketball-shoes/191712.html", c);

/* ~~~ Add to cart analytics example ~~~
Expand Down
46 changes: 45 additions & 1 deletion pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLAlbum.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public void JsonReceived(JSONObject response) {
// fire opened widget analytics event
if(this.page == 1){
openedWidget();
} else if(this.page > 1) {
loadMore();
}

} catch (JSONException e) {
Expand Down Expand Up @@ -186,7 +188,11 @@ protected HashMap<String, Object> getRequestParams(int desiredPage) {
return paramMap;
}

public boolean openedWidget() {
/***
* Analytics methods
*/

private boolean openedWidget() {
PXLClient pxlClient = PXLClient.getInstance(context);
JSONObject body = new JSONObject();
StringBuilder stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -214,4 +220,42 @@ public boolean openedWidget() {
pxlClient.makeAnalyticsCall("events/openedWidget", body);
return true;
}

private boolean loadMore() {
if (id == null) {
Log.w(TAG, "missing album id");
return false;
}
if(this.page < 2){
Log.w(TAG, "first load detected");
return false;
}
PXLClient pxlClient = PXLClient.getInstance(context);
JSONObject body = new JSONObject();
StringBuilder stringBuilder = new StringBuilder();
int lastIdx = ((this.page - 1) * this.perPage);
for (int i = lastIdx; i < this.photos.size(); i++) {
try {
stringBuilder.append(this.photos.get(i).id);
if(i != this.photos.size() - 1){
stringBuilder.append(",");
}
} catch (Exception e) {
e.printStackTrace();
}
}

try{
body.put("album_id", Integer.parseInt(this.id));
body.put("per_page", this.perPage);
body.put("page", this.page);
body.put("photos", stringBuilder.toString());

} catch (JSONException e) {
e.printStackTrace();
}

pxlClient.makeAnalyticsCall("events/loadMore", body);
return true;
}
}
20 changes: 20 additions & 0 deletions pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLPhoto.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,26 @@ public Integer sourceIconImage() {
}
}

/***
* Analytics methods
*/

public void actionClicked(String actionLink, Context context) {
PXLClient pxlClient = PXLClient.getInstance(context);
JSONObject body = new JSONObject();

try{
body.put("album_id", Integer.parseInt(this.album.id));
body.put("album_photo_id", Integer.parseInt(this.albumPhotoId));
body.put("action_link_url", actionLink);

} catch (JSONException e) {
e.printStackTrace();
}

pxlClient.makeAnalyticsCall("events/actionClicked", body);
}

public boolean openedLightbox(Context context) {

PXLClient pxlClient = PXLClient.getInstance(context);
Expand Down

0 comments on commit 74e6773

Please sign in to comment.