Skip to content

Commit 32dd425

Browse files
randyribackclaude
andcommitted
Example: add sandbox buttons for trackConversion smoke testing
Adds two buttons on the main screen — "Track Pageview (sandbox)" and "Track Conversion (sandbox)" — that fire against the `sandbox.joshhanson.io` apikey on a shared test URL. The pageview lets a session accrue history before the conversion fires so the conversions topology has something to attribute to. NOTE: the example app initializes the SDK with `dryRun=true`, which suppresses real network sends. To exercise these buttons end-to-end against mobileproxy, temporarily flip the fourth argument of `ParselyTracker.init(...)` to `false`. Used during the manual end-to-end verification of trackConversion on the Android emulator: with logcat filtered to `Parsely:V`, confirm the emitted "POST Data {...}" JSON includes `action: "conversion"` and the `_conversion_type` / `_conversion_label` keys, then watch dash.parsely.com for the conversion in the conversions report. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f7ab7bf commit 32dd425

3 files changed

Lines changed: 50 additions & 1 deletion

File tree

example/src/main/java/com/example/MainActivity.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.widget.EditText;
1010
import android.widget.TextView;
1111

12+
import com.parsely.parselyandroid.ConversionType;
1213
import com.parsely.parselyandroid.ParselyTracker;
1314
import com.parsely.parselyandroid.SiteIdSource;
1415
import com.parsely.parselyandroid.ParselyTrackerInternal;
@@ -140,6 +141,34 @@ public void trackReset(View view) {
140141
ParselyTracker.sharedInstance().resetVideo();
141142
}
142143

144+
// --- Sandbox buttons for trackConversion smoke testing against sandbox.joshhanson.io.
145+
// Both fire against the same URL so the conversions topology has a pageview to attribute to.
146+
private static final String SANDBOX_SITE_ID = "sandbox.joshhanson.io";
147+
private static final String SANDBOX_URL = "https://sandbox.joshhanson.io/path/test-conversion2";
148+
149+
public void trackSandboxPageview(View view) {
150+
final Map<String, Object> extraData = new HashMap<>();
151+
extraData.put("source", "android_demo_app");
152+
ParselyTracker.sharedInstance().trackPageview(
153+
SANDBOX_URL, "", null, extraData, new SiteIdSource.Custom(SANDBOX_SITE_ID)
154+
);
155+
}
156+
157+
public void trackSandboxConversion(View view) {
158+
final Map<String, Object> extraData = new HashMap<>();
159+
extraData.put("plan", "weekly");
160+
extraData.put("source", "android_demo_app");
161+
ParselyTracker.sharedInstance().trackConversion(
162+
SANDBOX_URL,
163+
ConversionType.SUBSCRIPTION,
164+
"android_sdk_smoke_test",
165+
"",
166+
null,
167+
extraData,
168+
new SiteIdSource.Custom(SANDBOX_SITE_ID)
169+
);
170+
}
171+
143172
private SiteIdSource getSiteId() {
144173
Editable fromEditText = ((EditText) findViewById(R.id.custom_site_id)).getText();
145174
if (fromEditText == null || fromEditText.toString().isEmpty()) {

example/src/main/res/layout/activity_main.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,29 @@
7676
android:onClick="trackReset"
7777
android:text="@string/button_reset_video" />
7878

79+
<Button
80+
android:id="@+id/sandbox_pageview_button"
81+
android:layout_width="wrap_content"
82+
android:layout_height="wrap_content"
83+
android:layout_below="@+id/reset_video_button"
84+
android:layout_centerHorizontal="true"
85+
android:onClick="trackSandboxPageview"
86+
android:text="@string/button_sandbox_pageview" />
87+
88+
<Button
89+
android:id="@+id/sandbox_conversion_button"
90+
android:layout_width="wrap_content"
91+
android:layout_height="wrap_content"
92+
android:layout_below="@+id/sandbox_pageview_button"
93+
android:layout_centerHorizontal="true"
94+
android:onClick="trackSandboxConversion"
95+
android:text="@string/button_sandbox_conversion" />
96+
7997
<TextView android:id="@+id/interval"
8098
android:layout_width="wrap_content"
8199
android:layout_height="wrap_content"
82100
android:layout_centerHorizontal="true"
83-
android:layout_below="@id/reset_video_button"
101+
android:layout_below="@id/sandbox_conversion_button"
84102
android:text="Flush timer inactive"/>
85103

86104
<TextView

example/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
<string name="button_track_video">Track Video</string>
99
<string name="button_pause_video">Pause Video</string>
1010
<string name="button_reset_video">Reset Video</string>
11+
<string name="button_sandbox_pageview">Track Pageview (sandbox)</string>
12+
<string name="button_sandbox_conversion">Track Conversion (sandbox)</string>
1113

1214
</resources>

0 commit comments

Comments
 (0)