diff --git a/README.md b/README.md index 180c6d22..0c2c47bf 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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: diff --git a/app/src/main/java/com/pixlee/pixleeandroidsdk/SampleActivity.java b/app/src/main/java/com/pixlee/pixleeandroidsdk/SampleActivity.java index e76cc649..36eb1dbd 100644 --- a/app/src/main/java/com/pixlee/pixleeandroidsdk/SampleActivity.java +++ b/app/src/main/java/com/pixlee/pixleeandroidsdk/SampleActivity.java @@ -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; @@ -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 ~~~ diff --git a/pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLAlbum.java b/pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLAlbum.java index 359adafe..654714b6 100644 --- a/pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLAlbum.java +++ b/pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLAlbum.java @@ -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) { @@ -186,7 +188,11 @@ protected HashMap 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(); @@ -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; + } } diff --git a/pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLPhoto.java b/pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLPhoto.java index 5eb89e67..75e9a104 100644 --- a/pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLPhoto.java +++ b/pixleesdk/src/main/java/com/pixlee/pixleesdk/PXLPhoto.java @@ -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);