Skip to content

Commit

Permalink
Merge pull request #70 from Parsely/issue/33_69_extradata_in_engageme…
Browse files Browse the repository at this point in the history
…nt_session
  • Loading branch information
wzieba authored Sep 15, 2023
2 parents 91c7922 + 231f043 commit 7dab75f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion example/src/main/java/com/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

Expand Down Expand Up @@ -116,7 +118,9 @@ public void trackPageview(View view) {
}

public void startEngagement(View view) {
ParselyTracker.sharedInstance().startEngagement("http://example.com/article1.html", "http://example.com/");
final Map<String, Object> extraData = new HashMap<>();
extraData.put("product-id", "12345");
ParselyTracker.sharedInstance().startEngagement("http://example.com/article1.html", "http://example.com/", extraData);
updateEngagementStrings();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,21 @@ public void trackPageview(
* @param urlRef Referrer URL associated with this video view.
*/
public void startEngagement(@NonNull String url, @Nullable String urlRef) {
startEngagement(url, urlRef, null);
}

/**
* Same as {@link #startEngagement(String, String)} but with extra data.
*
* @param url The URL to track engaged time for.
* @param urlRef Referrer URL associated with this video view.
* @param extraData A Map of additional information to send with the event.
*/
public void startEngagement(
final @NonNull String url,
@Nullable String urlRef,
final @Nullable Map<String, Object> extraData
) {
if (url.equals("")) {
throw new IllegalArgumentException("url cannot be null or empty.");
}
Expand All @@ -255,7 +270,7 @@ public void startEngagement(@NonNull String url, @Nullable String urlRef) {
stopEngagement();

// Start a new EngagementTask
Map<String, Object> event = buildEvent(url, urlRef, "heartbeat", null, null);
Map<String, Object> event = buildEvent(url, urlRef, "heartbeat", null, extraData);
engagementManager = new EngagementManager(timer, DEFAULT_ENGAGEMENT_INTERVAL_MILLIS, event);
engagementManager.start();
}
Expand Down

0 comments on commit 7dab75f

Please sign in to comment.