-
Notifications
You must be signed in to change notification settings - Fork 3
[REM-3040] Display ads tracking #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ZSnake
wants to merge
2
commits into
master
Choose a base branch
from
REM-3040/display-ads-tracking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
library/src/main/java/io/constructor/data/model/tracking/MediaImpressionClickRequestBody.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package io.constructor.data.model.tracking | ||
|
|
||
| import com.squareup.moshi.Json | ||
| import com.squareup.moshi.JsonClass | ||
| import java.io.Serializable | ||
|
|
||
| @JsonClass(generateAdapter = true) | ||
| data class MediaImpressionClickRequestBody( | ||
| @Json(name = "banner_ad_id") val bannerAdId: String, | ||
| @Json(name = "placement_id") val placementId: String, | ||
| @Json(name = "beacon") val beacon: Boolean = true, | ||
| @Json(name = "c") val c: String, | ||
| @Json(name = "i") val i: String, | ||
| @Json(name = "s") val s: Int, | ||
| @Json(name = "key") val key: String, | ||
| @Json(name = "ui") val ui: String?, | ||
| @Json(name = "us") val us: List<String?>, | ||
| @Json(name = "_dt") val dt: Long | ||
| ) : Serializable |
19 changes: 19 additions & 0 deletions
19
library/src/main/java/io/constructor/data/model/tracking/MediaImpressionViewRequestBody.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package io.constructor.data.model.tracking | ||
|
|
||
| import com.squareup.moshi.Json | ||
| import com.squareup.moshi.JsonClass | ||
| import java.io.Serializable | ||
|
|
||
| @JsonClass(generateAdapter = true) | ||
| data class MediaImpressionViewRequestBody( | ||
| @Json(name = "banner_ad_id") val bannerAdId: String, | ||
| @Json(name = "placement_id") val placementId: String, | ||
| @Json(name = "beacon") val beacon: Boolean = true, | ||
| @Json(name = "c") val c: String, | ||
| @Json(name = "i") val i: String, | ||
| @Json(name = "s") val s: Int, | ||
| @Json(name = "key") val key: String, | ||
| @Json(name = "ui") val ui: String?, | ||
| @Json(name = "us") val us: List<String?>, | ||
| @Json(name = "_dt") val dt: Long | ||
| ) : Serializable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
library/src/test/java/io/constructor/core/ConstructorIoIntegrationMediaTrackingTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package io.constructor.core | ||
|
|
||
| import android.content.Context | ||
| import io.constructor.data.local.PreferencesHelper | ||
| import io.constructor.data.memory.ConfigMemoryHolder | ||
| import io.constructor.test.createTestDataManager | ||
| import io.constructor.util.RxSchedulersOverrideRule | ||
| import io.mockk.every | ||
| import io.mockk.mockk | ||
| import okhttp3.OkHttpClient | ||
| import okhttp3.Request | ||
| import org.json.JSONObject | ||
| import org.junit.Before | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| class ConstructorIoIntegrationMediaTrackingTest { | ||
|
|
||
| @Rule | ||
| @JvmField | ||
| val overrideSchedulersRule = RxSchedulersOverrideRule() | ||
|
|
||
| private var constructorIo = ConstructorIo | ||
| private val ctx = mockk<Context>() | ||
| private val preferencesHelper = mockk<PreferencesHelper>() | ||
| private val configMemoryHolder = mockk<ConfigMemoryHolder>() | ||
| private val timeBetweenTests = 2000L | ||
|
|
||
| private val testKey = "key_x6UnCVRZaJgIHFQD" | ||
| private val testPlacementId = "home" | ||
| private lateinit var bannerAdId: String | ||
|
|
||
| @Before | ||
| fun setup() { | ||
| every { ctx.applicationContext } returns ctx | ||
|
|
||
| every { preferencesHelper.apiKey } returns testKey | ||
| every { preferencesHelper.id } returns "wacko-the-guid" | ||
| every { preferencesHelper.scheme } returns "https" | ||
| every { preferencesHelper.serviceUrl } returns "ac.cnstrc.com" | ||
| every { preferencesHelper.mediaServiceUrl } returns "behavior.media-cnstrc.com" | ||
| every { preferencesHelper.port } returns 443 | ||
| every { preferencesHelper.defaultItemSection } returns "Products" | ||
| every { preferencesHelper.getSessionId(any(), any()) } returns 67 | ||
|
|
||
| every { configMemoryHolder.autocompleteResultCount } returns null | ||
| every { configMemoryHolder.userId } returns "player-three" | ||
| every { configMemoryHolder.defaultAnalyticsTags } returns mapOf("appVersion" to "123", "appPlatform" to "Android") | ||
| every { configMemoryHolder.testCellParams } returns emptyList() | ||
| every { configMemoryHolder.segments } returns emptyList() | ||
|
|
||
| val config = ConstructorIoConfig(testKey) | ||
| val dataManager = createTestDataManager(preferencesHelper, configMemoryHolder) | ||
|
|
||
| constructorIo.testInit(ctx, config, dataManager, preferencesHelper, configMemoryHolder) | ||
|
|
||
| bannerAdId = fetchBannerAdId() | ||
| } | ||
|
|
||
| private fun fetchBannerAdId(): String { | ||
| val client = OkHttpClient() | ||
| val url = "https://display.media-cnstrc.com/display-ads?key=$testKey&placement_ids=$testPlacementId" | ||
| val request = Request.Builder().url(url).build() | ||
| client.newCall(request).execute().use { response -> | ||
| val body = response.body?.string() | ||
| val json = JSONObject(body ?: "{}") | ||
| val displayAds = json.getJSONObject("display_ads") | ||
| val placementArray = displayAds.optJSONArray(testPlacementId) | ||
| if (placementArray != null && placementArray.length() > 0) { | ||
| return placementArray.getJSONObject(0).getString("banner_ad_id") | ||
| } | ||
| val placementObject = displayAds.optJSONObject(testPlacementId) | ||
| if (placementObject != null) { | ||
| return placementObject.getString("banner_ad_id") | ||
| } | ||
| } | ||
| throw IllegalStateException("Unable to fetch banner ad id for placement $testPlacementId") | ||
| } | ||
|
|
||
| @Test | ||
| fun trackMediaImpressionViewAgainstRealResponse() { | ||
| val observer = ConstructorIo.trackMediaImpressionViewInternal(bannerAdId, testPlacementId).test() | ||
| observer.assertComplete() | ||
| observer.assertNoErrors() | ||
| Thread.sleep(timeBetweenTests) | ||
| } | ||
|
|
||
| @Test | ||
| fun trackMediaImpressionClickAgainstRealResponse() { | ||
| val observer = ConstructorIo.trackMediaImpressionClickInternal(bannerAdId, testPlacementId).test() | ||
| observer.assertComplete() | ||
| observer.assertNoErrors() | ||
| Thread.sleep(timeBetweenTests) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.