diff --git a/snowplow-tracker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/TrackerWebViewInterfaceV2Test.kt b/snowplow-tracker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/TrackerWebViewInterfaceV2Test.kt index a95f91011..77eae0020 100644 --- a/snowplow-tracker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/TrackerWebViewInterfaceV2Test.kt +++ b/snowplow-tracker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/TrackerWebViewInterfaceV2Test.kt @@ -87,10 +87,10 @@ class TrackerWebViewInterfaceV2Test { pageUrl = "http://snowplow.com", pageTitle = "Snowplow", referrer = "http://google.com", - ping_xoffset_min = 10, - ping_xoffset_max = 20, - ping_yoffset_min = 30, - ping_yoffset_max = 40 + pingXOffsetMin = 10, + pingXOffsetMax = 20, + pingYOffsetMin = 30, + pingYOffsetMax = 40 ) Thread.sleep(200) @@ -137,6 +137,50 @@ class TrackerWebViewInterfaceV2Test { assertEquals(10.0, payload[Parameters.SE_VALUE]) } + @Test + @Throws(JSONException::class, InterruptedException::class) + fun tracksEventWithCorrectTracker() { + // create the second tracker + val trackedEvents2: MutableList = mutableListOf() + val networkConfig = NetworkConfiguration(MockNetworkConnection(HttpMethod.POST, 200)) + val plugin2 = PluginConfiguration("plugin2") + plugin2.afterTrack { + trackedEvents2.add(it) + } + createTracker( + context, + namespace = "ns2", + network = networkConfig, + TrackerConfiguration("appId"), + plugin2 + ) + + // track an event using the second tracker + webInterface!!.trackWebViewEvent( + eventName = "pv", + trackerVersion = "webview", + useragent = "Chrome", + pageUrl = "http://snowplow.com", + trackers = arrayOf("ns2") + ) + Thread.sleep(200) + + assertEquals(0, trackedEvents.size) + assertEquals(1, trackedEvents2.size) + + // track an event using default tracker if not specified + webInterface!!.trackWebViewEvent( + eventName = "pp", + trackerVersion = "webview", + useragent = "Chrome", + pageUrl = "http://snowplow.com", + ) + Thread.sleep(200) + + assertEquals(1, trackedEvents.size) + assertEquals(1, trackedEvents2.size) + } + // --- PRIVATE private val context: Context diff --git a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/event/WebViewReader.kt b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/event/WebViewReader.kt index 6b309c245..7d7660e53 100644 --- a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/event/WebViewReader.kt +++ b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/event/WebViewReader.kt @@ -13,7 +13,6 @@ package com.snowplowanalytics.core.event import com.snowplowanalytics.core.constants.Parameters -import com.snowplowanalytics.core.constants.TrackerConstants import com.snowplowanalytics.snowplow.event.AbstractPrimitive /** @@ -32,10 +31,10 @@ class WebViewReader( val label: String? = null, val property: String? = null, val value: Double? = null, - val ping_xoffset_min: Int? = null, - val ping_xoffset_max: Int? = null, - val ping_yoffset_min: Int? = null, - val ping_yoffset_max: Int? = null + val pingXOffsetMin: Int? = null, + val pingXOffsetMax: Int? = null, + val pingYOffsetMin: Int? = null, + val pingYOffsetMax: Int? = null ) : AbstractPrimitive() { @@ -54,10 +53,10 @@ class WebViewReader( if (label != null) payload[Parameters.SE_LABEL] = label if (property != null) payload[Parameters.SE_PROPERTY] = property if (value != null) payload[Parameters.SE_VALUE] = value - if (ping_xoffset_min != null) payload[Parameters.PING_XOFFSET_MIN] = ping_xoffset_min - if (ping_xoffset_max != null) payload[Parameters.PING_XOFFSET_MAX] = ping_xoffset_max - if (ping_yoffset_min != null) payload[Parameters.PING_YOFFSET_MIN] = ping_yoffset_min - if (ping_yoffset_max != null) payload[Parameters.PING_YOFFSET_MAX] = ping_yoffset_max + if (pingXOffsetMin != null) payload[Parameters.PING_XOFFSET_MIN] = pingXOffsetMin + if (pingXOffsetMax != null) payload[Parameters.PING_XOFFSET_MAX] = pingXOffsetMax + if (pingYOffsetMin != null) payload[Parameters.PING_YOFFSET_MIN] = pingYOffsetMin + if (pingYOffsetMax != null) payload[Parameters.PING_YOFFSET_MAX] = pingYOffsetMax return payload } diff --git a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerWebViewInterfaceV2.kt b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerWebViewInterfaceV2.kt index 3c5d9598a..96bd8966f 100644 --- a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerWebViewInterfaceV2.kt +++ b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerWebViewInterfaceV2.kt @@ -43,10 +43,10 @@ class TrackerWebViewInterfaceV2 { label: String? = null, property: String? = null, value: Double? = null, - ping_xoffset_min: Int? = null, - ping_xoffset_max: Int? = null, - ping_yoffset_min: Int? = null, - ping_yoffset_max: Int? = null, + pingXOffsetMin: Int? = null, + pingXOffsetMax: Int? = null, + pingYOffsetMin: Int? = null, + pingYOffsetMax: Int? = null, entities: String? = null, trackers: Array? = null ) { @@ -62,75 +62,14 @@ class TrackerWebViewInterfaceV2 { label, property, value, - ping_xoffset_min, - ping_xoffset_max, - ping_yoffset_min, - ping_yoffset_max + pingXOffsetMin, + pingXOffsetMax, + pingYOffsetMin, + pingYOffsetMax ) trackEvent(event, entities, trackers) } - - - /** - * Track a screen view event from the Web view - * @param name The name of the screen viewed - * @param id The id (UUID v4) of screen that was viewed - * @param type The type of screen that was viewed - * @param previousName The name of the previous screen that was viewed - * @param previousId The id (UUID v4) of the previous screen that was viewed - * @param previousType The type of screen that was viewed - * @param transitionType The type of transition that led to the screen being viewed - * @param context Optional JSON string with a list of context entities - * @param trackers Optional list of tracker namespaces to track with - * @throws JSONException In case of JSON parsing failures - */ - @JavascriptInterface - @Throws(JSONException::class) - fun trackScreenView( - name: String, - id: String, - type: String?, - previousName: String?, - previousId: String?, - previousType: String?, - transitionType: String?, - context: String?, - trackers: Array? - ) { - val event = ScreenView(name, UUID.fromString(id)) - .type(type) - .previousId(previousId) - .previousName(previousName) - .previousType(previousType) - .transitionType(transitionType) - trackEvent(event, context, trackers) - } - - /** - * Track a page view event from the Web view - * @param pageUrl Page URL - * @param pageTitle Page title - * @param referrer Referrer URL - * @param context Optional JSON string with a list of context entities - * @param trackers Optional list of tracker namespaces to track with - * @throws JSONException In case of JSON parsing failures - */ - @JavascriptInterface - @Throws(JSONException::class) - fun trackPageView( - pageUrl: String, - pageTitle: String?, - referrer: String?, - context: String?, - trackers: Array? - ) { - val event = PageView(pageUrl) - .pageTitle(pageTitle) - .referrer(referrer) - trackEvent(event, context, trackers) - } - @Throws(JSONException::class) private fun trackEvent(event: AbstractEvent, context: String?, trackers: Array?) { if (context != null) { @@ -139,7 +78,7 @@ class TrackerWebViewInterfaceV2 { event.entities(contextEntities) } } - if (trackers == null || trackers.isEmpty()) { + if (trackers.isNullOrEmpty()) { val tracker = defaultTracker if (tracker != null) { tracker.track(event)