Skip to content
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

EP-415: CTA Clicked (project) #1215

Merged
merged 5 commits into from
Apr 21, 2021

Conversation

sunday-okpoluaefe
Copy link
Contributor

📲 What

Android: CTA Clicked (project)

🤔 Why

Segment Integration

  • Event for when user taps on a project from the results on the discover page when no filter is applied (“All Projects), the Projects We Love filter is applied, or a category and/or subcategory filter is applied.

  • Event for when user applies Recommended for you filter.

🛠 How

  • Added method trackDiscoverProjectCtaClicked
/**
     * Sends data to the client when a project in the discovery is clicked
     * sending sort and filter properties.
     *
     * @param discoveryParams: The discovery parameters.
     * @param projectData: The projectData parameters.
     */
    fun trackDiscoverProjectCtaClicked(discoveryParams: DiscoveryParams, projectData: ProjectData) {
        val props: HashMap<String, Any> = hashMapOf(CONTEXT_CTA.contextName to PROJECT.contextName)
        props[CONTEXT_LOCATION.contextName] = DISCOVER_ADVANCED.contextName
        props[CONTEXT_PAGE.contextName] = DISCOVER.contextName
        props[CONTEXT_TYPE.contextName] = when {
            BooleanUtils.isTrue(discoveryParams.category()?.isRoot) ||
                discoveryParams.category() != null ||
                BooleanUtils.isTrue(discoveryParams.staffPicks()) ||
                BooleanUtils.isTrue(discoveryParams.isAllProjects) -> RESULTS.contextName
            BooleanUtils.isTrue(discoveryParams.recommended()) -> RECOMMENDED.contextName
            else -> ""
        }

        props.putAll(AnalyticEventsUtils.projectProperties(projectData.project(), client.loggedInUser()))
        props.putAll(AnalyticEventsUtils.refTagProperties(projectData.refTagFromIntent(), projectData.refTagFromCookie()))
        props.putAll(AnalyticEventsUtils.discoveryParamsProperties(discoveryParams))

        client.track(CTA_CLICKED.eventName, props)
    }

  • Called method on project card clicked in DiscoveryFragmentViewModel
 this.paramsFromActivity
              .compose(takePairWhen(this.projectCardClicked))
              .compose(bindToLifecycle())
              .subscribe(it -> {
                final Pair<Project, RefTag> refTag = RefTagUtils.projectAndRefTagFromParamsAndProject(it.first, it.second);
                final RefTag cookieRefTag = RefTagUtils.storedCookieRefTagForProject(it.second, this.cookieManager, 
 this.sharedPreferences);
                final ProjectData projectData = SharedFunctionsKt.projectData(refTag.second, cookieRefTag, it.second);

                this.lake.trackDiscoverProjectCtaClicked(it.first, projectData);
              });

  • Added unit test to event properties
 @Test
    fun testDiscoveryProjectCtaClickedProperties_AllProjects() {
        val user = user()
        val client = client(user)
        client.eventNames.subscribe(this.segmentTrack)
        client.eventProperties.subscribe(this.propertiesTest)
        client.identifiedId.subscribe(this.segmentIdentify)
        val segment = AnalyticEvents(listOf(client))

        val project = project().toBuilder().build()

        val params = DiscoveryParams
            .builder()
            .sort(DiscoveryParams.Sort.MAGIC)
            .build()

        segment.trackDiscoverProjectCtaClicked(params, ProjectDataFactory.project(project, RefTag.discovery(), RefTag.recommended()))

        assertSessionProperties(user)
        assertContextProperties()
        assertDiscoverProperties()
        assertUserProperties(false)
        assertProjectProperties(project)

        val expectedProperties = propertiesTest.value

        assertEquals(EventContextValues.ContextPageName.PROJECT.contextName, expectedProperties[CONTEXT_CTA.contextName])
        assertEquals(EventContextValues.LocationContextName.DISCOVER_ADVANCED.contextName, expectedProperties[ContextPropertyKeyName.CONTEXT_LOCATION.contextName])
        assertEquals(EventContextValues.DiscoveryContextType.RESULTS.contextName, expectedProperties[ContextPropertyKeyName.CONTEXT_TYPE.contextName])
        assertEquals(EventContextValues.CtaContextName.DISCOVER.contextName, expectedProperties[CONTEXT_PAGE.contextName])
        this.segmentTrack.assertValue(EventName.CTA_CLICKED.eventName)
    }
    @Test
    fun testDiscoveryProjectCtaClickedProperties_Recommended() {
        val user = user()
        val client = client(user)
        client.eventNames.subscribe(this.segmentTrack)
        client.eventProperties.subscribe(this.propertiesTest)
        client.identifiedId.subscribe(this.segmentIdentify)
        val segment = AnalyticEvents(listOf(client))

        val project = project().toBuilder().build()

        val params = DiscoveryParams
            .builder()
            .recommended(true)
            .sort(DiscoveryParams.Sort.MAGIC)
            .build()

        segment.trackDiscoverProjectCtaClicked(params, ProjectDataFactory.project(project, RefTag.discovery(), RefTag.recommended()))

        assertSessionProperties(user)
        assertContextProperties()

        assertUserProperties(false)
        assertProjectProperties(project)

        val expectedProperties = propertiesTest.value

        // test custom discover properties
        assertNull(expectedProperties["discover_category_id"])
        assertNull(expectedProperties["discover_category_name"])
        assertEquals(false, expectedProperties["discover_everything"])
        assertEquals(false, expectedProperties["discover_pwl"])
        assertEquals(true, expectedProperties["discover_recommended"])
        assertEquals("discovery", expectedProperties["discover_ref_tag"])
        assertEquals(null, expectedProperties["discover_search_term"])
        assertEquals(false, expectedProperties["discover_social"])
        assertEquals("magic", expectedProperties["discover_sort"])
        assertNull(expectedProperties["discover_subcategory_id"])
        assertNull(expectedProperties["discover_subcategory_name"])
        assertEquals(null, expectedProperties["discover_tag"])
        assertEquals(false, expectedProperties["discover_watched"])

        assertEquals(EventContextValues.ContextPageName.PROJECT.contextName, expectedProperties[CONTEXT_CTA.contextName])
        assertEquals(EventContextValues.LocationContextName.DISCOVER_ADVANCED.contextName, expectedProperties[ContextPropertyKeyName.CONTEXT_LOCATION.contextName])
        assertEquals(EventContextValues.DiscoveryContextType.RECOMMENDED.contextName, expectedProperties[ContextPropertyKeyName.CONTEXT_TYPE.contextName])
        assertEquals(EventContextValues.CtaContextName.DISCOVER.contextName, expectedProperties[CONTEXT_PAGE.contextName])
        this.segmentTrack.assertValue(EventName.CTA_CLICKED.eventName)
    }

👀 See

All Projects Filter

all_projects

Recommended Filter

recommended

Before 🐛 After 🦋

📋 QA

All Projects, Project We Love, Category and Subcategory Filters

  • Click on the Hamburger Menu Select any of All Projects, Project We Love Category and Subcategory ``` Filters
  • Click on any project from the Discover page, the new event should be registered in the segment console.

Screenshot 2021-04-21 at 09 55 23

Recommended For You Filters

  • Click on the Hamburger Menu Select Recommended For You Filters
  • Click on any project from the Discover page, the new event should be registered in the segment console.

Screenshot 2021-04-21 at 10 09 58

Story 📖

https://kickstarter.atlassian.net/browse/EP-415
https://kickstarter.atlassian.net/browse/EP-419

Copy link
Contributor

@hadia hadia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job👏

@sunday-okpoluaefe sunday-okpoluaefe merged commit 8d7a482 into master Apr 21, 2021
@sunday-okpoluaefe sunday-okpoluaefe deleted the sunday-ep-415-project-cta-clicked branch April 21, 2021 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants