diff --git a/example/src/main/java/com/example/MainActivity.java b/example/src/main/java/com/example/MainActivity.java index 89ecbca5..10003620 100644 --- a/example/src/main/java/com/example/MainActivity.java +++ b/example/src/main/java/com/example/MainActivity.java @@ -4,10 +4,13 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.text.Editable; import android.view.View; +import android.widget.EditText; import android.widget.TextView; import com.parsely.parselyandroid.ParselyTracker; +import com.parsely.parselyandroid.SiteIdSource; import com.parsely.parselyandroid.ParselyTrackerInternal; import com.parsely.parselyandroid.ParselyVideoMetadata; @@ -23,6 +26,7 @@ */ public class MainActivity extends Activity { + public static final String DEFAULT_SITE_ID = "example.com"; private InternalDebugOnlyData internalDebugOnlyData; @Override @@ -31,7 +35,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); // initialize the Parsely tracker with your site id and the current Context - ParselyTracker.init("example.com", 30, this, true); + ParselyTracker.init(DEFAULT_SITE_ID, 30, this, true); internalDebugOnlyData = new InternalDebugOnlyData((ParselyTrackerInternal) ParselyTracker.sharedInstance()); final TextView intervalView = (TextView) findViewById(R.id.interval); @@ -96,14 +100,14 @@ public void trackPageview(View view) { // the post has an internet-accessible URL, we will crawl it. urlMetadata is only used // in the case of app-only content that we can't crawl. ParselyTracker.sharedInstance().trackPageview( - "http://example.com/article1.html", "http://example.com/", null, null + "http://example.com/article1.html", "http://example.com/", null, null, getSiteId() ); } public void startEngagement(View view) { final Map extraData = new HashMap<>(); extraData.put("product-id", "12345"); - ParselyTracker.sharedInstance().startEngagement("http://example.com/article1.html", "http://example.com/", extraData); + ParselyTracker.sharedInstance().startEngagement("http://example.com/article1.html", "http://example.com/", extraData, getSiteId()); updateEngagementStrings(); } @@ -124,7 +128,7 @@ public void trackPlay(View view) { 90 ); // NOTE: For videos embedded in an article, "url" should be the URL for that article. - ParselyTracker.sharedInstance().trackPlay("http://example.com/app-videos", "", metadata, null); + ParselyTracker.sharedInstance().trackPlay("http://example.com/app-videos", "", metadata, null, getSiteId()); } @@ -135,4 +139,12 @@ public void trackPause(View view) { public void trackReset(View view) { ParselyTracker.sharedInstance().resetVideo(); } + + private SiteIdSource getSiteId() { + Editable fromEditText = ((EditText) findViewById(R.id.custom_site_id)).getText(); + if (fromEditText == null || fromEditText.toString().isEmpty()) { + return SiteIdSource.Default.INSTANCE; + } + return new SiteIdSource.Custom(fromEditText.toString()); + } } diff --git a/example/src/main/res/layout/activity_main.xml b/example/src/main/res/layout/activity_main.xml index e86a9223..bae2bae9 100644 --- a/example/src/main/res/layout/activity_main.xml +++ b/example/src/main/res/layout/activity_main.xml @@ -7,19 +7,27 @@ android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > - + - + + +