Skip to content

Commit

Permalink
feat: add edit text for testing custom site id in example/MainActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
wzieba committed Apr 5, 2024
1 parent 7f2782e commit 2273370
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
19 changes: 15 additions & 4 deletions example/src/main/java/com/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
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;
Expand All @@ -24,6 +26,7 @@
*/
public class MainActivity extends Activity {

public static final String DEFAULT_SITE_ID = "example.com";
private InternalDebugOnlyData internalDebugOnlyData;

@Override
Expand All @@ -32,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);
Expand Down Expand Up @@ -97,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, SiteIdSource.Default.INSTANCE
"http://example.com/article1.html", "http://example.com/", null, null, getSiteId()
);
}

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

Expand All @@ -125,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, SiteIdSource.Default.INSTANCE);
ParselyTracker.sharedInstance().trackPlay("http://example.com/app-videos", "", metadata, null, getSiteId());

}

Expand All @@ -136,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());
}
}
14 changes: 11 additions & 3 deletions example/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="@drawable/parsely_logo_horizontal" />


<EditText
android:id="@+id/custom_site_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/imageView1"
android:layout_centerHorizontal="true"
android:hint="Custom site id. Default if empty"/>

<Button android:id="@+id/url_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/imageView1"
android:layout_below="@id/custom_site_id"
android:text="@string/button_track_url"
android:onClick="trackPageview" />

Expand Down

0 comments on commit 2273370

Please sign in to comment.