-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBL-1236 Call CreateAttributionEvent on ProjectPage for project page … (
#1972) * MBL-1236 Call CreateAttributionEvent on ProjectPage for project page viewed event * No need to manually add props that backend will send for free * Small edits * Fix lint * Fix tests --------- Co-authored-by: mtgriego <[email protected]>
- Loading branch information
1 parent
484f230
commit b220df4
Showing
10 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/kickstarter/libs/AttributionEvents.kt
This file contains 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,52 @@ | ||
package com.kickstarter.libs | ||
|
||
import android.annotation.SuppressLint | ||
import com.kickstarter.libs.utils.AnalyticEventsUtils | ||
import com.kickstarter.libs.utils.ContextPropertyKeyName | ||
import com.kickstarter.libs.utils.EventContextValues | ||
import com.kickstarter.libs.utils.EventName | ||
import com.kickstarter.models.Project | ||
import com.kickstarter.services.ApolloClientTypeV2 | ||
import com.kickstarter.services.mutations.CreateAttributionEventData | ||
import com.kickstarter.services.transformers.encodeRelayId | ||
import com.kickstarter.ui.data.ProjectData | ||
import timber.log.Timber | ||
|
||
/** | ||
* Similar to the [AnalyticEvents] class but specifically for sending attribution events to KSR | ||
* event attribution backend. | ||
* | ||
*/ | ||
class AttributionEvents( | ||
val apolloClient: ApolloClientTypeV2 | ||
) { | ||
/** | ||
* Sends data to the backend for event attribution when the projects screen is loaded. | ||
* | ||
* @param projectData: The selected project data. | ||
*/ | ||
fun trackProjectPageViewed(projectData: ProjectData) { | ||
val props: HashMap<String, Any> = hashMapOf(ContextPropertyKeyName.CONTEXT_PAGE.contextName to EventContextValues.ContextPageName.PROJECT.contextName) | ||
props["context_page_url"] = projectData.fullDeeplink()?.toString() ?: "" | ||
props.putAll(AnalyticEventsUtils.refTagProperties(projectData.refTagFromIntent(), projectData.refTagFromCookie())) | ||
track(EventName.PROJECT_PAGE_VIEWED.eventName, props, projectData.project()) | ||
} | ||
|
||
@SuppressLint("CheckResult") | ||
private fun track(eventName: String, eventProperties: Map<String, Any?>, project: Project) { | ||
val attributionEventData = CreateAttributionEventData( | ||
eventName = eventName, | ||
eventProperties = eventProperties, | ||
projectId = encodeRelayId(project) | ||
) | ||
createAttributionEvent(attributionEventData) | ||
.subscribe { | ||
Timber.tag("Event Attribution").d("Project page viewed sent to backend: %s", it) | ||
} | ||
} | ||
|
||
private fun createAttributionEvent(eventInput: CreateAttributionEventData) = | ||
this.apolloClient.createAttributionEvent(eventInput) | ||
.materialize() | ||
.share() | ||
} |
This file contains 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 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 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 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 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 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 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 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