Skip to content

Commit 89a82a3

Browse files
feat(ExploreBy): fix and add missing tracking (artsy#11019)
* feat: fix and add missing tracking * fix: broken test provider * fix: argument naming Co-authored-by: Dejan <1176374+egdbear@users.noreply.github.com> * feat: address requested changes * feat: address requested changes * feat: add destination path to the cards element * feat: expand tracking to track y position and check href with OwnerType * feat: adjust tap tracking and enable the feature flag --------- Co-authored-by: Dejan <1176374+egdbear@users.noreply.github.com>
1 parent 76bd596 commit 89a82a3

File tree

11 files changed

+283
-57
lines changed

11 files changed

+283
-57
lines changed

src/app/Scenes/CollectionsByCategory/CollectionRail.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import {
77
Spacer,
88
useScreenDimensions,
99
} from "@artsy/palette-mobile"
10+
import { ArtworkRail_artworks$data } from "__generated__/ArtworkRail_artworks.graphql"
1011
import { CollectionRailCollectionsByCategoryQuery } from "__generated__/CollectionRailCollectionsByCategoryQuery.graphql"
1112
import { CollectionRail_marketingCollection$key } from "__generated__/CollectionRail_marketingCollection.graphql"
1213
import { ArtworkRail, ArtworkRailPlaceholder } from "app/Components/ArtworkRail/ArtworkRail"
1314
import { SectionTitle } from "app/Components/SectionTitle"
15+
import { useCollectionByCategoryTracking } from "app/Scenes/CollectionsByCategory/hooks/useCollectionByCategoryTracking"
1416
import { navigate } from "app/system/navigation/navigate"
1517
import { ElementInView } from "app/utils/ElementInView"
1618
import { extractNodes } from "app/utils/extractNodes"
@@ -24,24 +26,31 @@ interface CollectionRailProps {
2426

2527
export const CollectionRail: FC<CollectionRailProps> = ({ collection: _collection }) => {
2628
const collection = useFragment(fragment, _collection)
29+
const { trackArtworkRailItemTap, trackArtworkRailViewAllTap } = useCollectionByCategoryTracking()
2730

2831
if (!collection || collection.artworksConnection?.counts.total === 0) {
2932
return null
3033
}
3134

3235
const artworks = extractNodes(collection.artworksConnection)
3336

37+
const handleArtworkPress = (artwork: ArtworkRail_artworks$data[0], index: number) => {
38+
trackArtworkRailItemTap(artwork.internalID, index)
39+
navigate(artwork.href ?? "")
40+
}
41+
42+
const handleTitlePress = () => {
43+
trackArtworkRailViewAllTap(collection.slug)
44+
navigate(`/collection/${collection.slug}`)
45+
}
46+
3447
return (
3548
<Flex px={2}>
3649
<Flex justifyContent="center">
37-
<SectionTitle
38-
title={collection.title}
39-
titleVariant="md"
40-
onPress={() => navigate(`/collection/${collection.slug}`)}
41-
/>
50+
<SectionTitle title={collection.title} titleVariant="md" onPress={handleTitlePress} />
4251
</Flex>
4352
<ArtworkRail
44-
onPress={(artwork) => navigate(artwork.href ?? "")}
53+
onPress={handleArtworkPress}
4554
artworks={artworks}
4655
ListHeaderComponent={null}
4756
showSaveIcon

src/app/Scenes/CollectionsByCategory/CollectionsByCategory.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { OwnerType } from "@artsy/cohesion"
12
import { Flex, Screen, useSpace } from "@artsy/palette-mobile"
23
import { RouteProp, useRoute } from "@react-navigation/native"
34
import { BodyWithSuspense } from "app/Scenes/CollectionsByCategory/Body"
45
import { FooterWithSuspense } from "app/Scenes/CollectionsByCategory/Footer"
56
import { goBack } from "app/system/navigation/navigate"
7+
import { ProvideScreenTrackingWithCohesionSchema } from "app/utils/track"
8+
import { screen } from "app/utils/track/helpers"
69
import { FC } from "react"
710

811
type CollectionsByCategoriesNavigationRoutes = {
@@ -27,17 +30,24 @@ export const CollectionsByCategory: FC = () => {
2730
const category = params.props.category
2831

2932
return (
30-
<Screen>
31-
<Screen.Header onBack={goBack} title={category} animated />
32-
<Screen.Body fullwidth flex={1}>
33-
<Screen.ScrollView>
34-
<Flex gap={space(4)}>
35-
<BodyWithSuspense />
33+
<ProvideScreenTrackingWithCohesionSchema
34+
info={screen({
35+
context_screen_owner_type: OwnerType.collectionsCategory,
36+
context_screen_owner_slug: category,
37+
})}
38+
>
39+
<Screen>
40+
<Screen.Header onBack={goBack} title={category} animated />
41+
<Screen.Body fullwidth flex={1}>
42+
<Screen.ScrollView>
43+
<Flex gap={space(4)}>
44+
<BodyWithSuspense />
3645

37-
<FooterWithSuspense homeViewSectionId={params.props.homeViewSectionId} />
38-
</Flex>
39-
</Screen.ScrollView>
40-
</Screen.Body>
41-
</Screen>
46+
<FooterWithSuspense homeViewSectionId={params.props.homeViewSectionId} />
47+
</Flex>
48+
</Screen.ScrollView>
49+
</Screen.Body>
50+
</Screen>
51+
</ProvideScreenTrackingWithCohesionSchema>
4252
)
4353
}

src/app/Scenes/CollectionsByCategory/CollectionsChips.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Chip, Flex, SkeletonBox, SkeletonText, Spacer, useSpace } from "@artsy/palette-mobile"
22
import { CollectionsChips_marketingCollections$key } from "__generated__/CollectionsChips_marketingCollections.graphql"
3+
import { useCollectionByCategoryTracking } from "app/Scenes/CollectionsByCategory/hooks/useCollectionByCategoryTracking"
34
import { navigate } from "app/system/navigation/navigate"
45
import { Dimensions, FlatList, ScrollView } from "react-native"
56
import { isTablet } from "react-native-device-info"
@@ -17,6 +18,7 @@ export const CollectionsChips: React.FC<CollectionsChipsProps> = ({
1718
}) => {
1819
const marketingCollections = useFragment(fragment, _marketingCollections)
1920
const space = useSpace()
21+
const { trackChipTap } = useCollectionByCategoryTracking()
2022

2123
if (!marketingCollections) {
2224
return null
@@ -26,6 +28,11 @@ export const CollectionsChips: React.FC<CollectionsChipsProps> = ({
2628

2729
const snapToOffsets = getSnapToOffsets(numColumns, space(1), space(2))
2830

31+
const handleChipPress = (slug: string, index: number) => {
32+
trackChipTap(slug, index)
33+
navigate(`/collection/${slug}`)
34+
}
35+
2936
return (
3037
<Flex>
3138
<ScrollView
@@ -45,13 +52,15 @@ export const CollectionsChips: React.FC<CollectionsChipsProps> = ({
4552
numColumns={numColumns}
4653
data={marketingCollections}
4754
keyExtractor={(item, index) => `item_${index}_${item.internalID}`}
48-
renderItem={({ item }) => (
55+
renderItem={({ item, index }) => (
4956
<Flex minWidth={CHIP_WIDTH}>
5057
<Chip
5158
key={item.internalID}
5259
title={item.title}
5360
onPress={() => {
54-
if (item?.slug) navigate(`/collection/${item.slug}`)
61+
if (item?.slug) {
62+
handleChipPress(item.slug, index)
63+
}
5564
}}
5665
/>
5766
</Flex>

src/app/Scenes/CollectionsByCategory/__tests__/CollectionRail.tests.tsx

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { screen } from "@testing-library/react-native"
1+
import { fireEvent, screen } from "@testing-library/react-native"
22
import { CollectionRailHomeViewSectionCardsTestQuery } from "__generated__/CollectionRailHomeViewSectionCardsTestQuery.graphql"
33
import { CollectionRail } from "app/Scenes/CollectionsByCategory/CollectionRail"
4+
import { navigate } from "app/system/navigation/navigate"
45
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper"
56
import { graphql } from "react-relay"
6-
7-
jest.mock("app/Components/ArtworkRail/ArtworkRail", () => ({
8-
ArtworkRail: () => null,
9-
ArtworkRailPlaceholder: () => null,
10-
}))
7+
import { useTracking } from "react-tracking"
118

129
describe("CollectionRail", () => {
10+
const trackEvent = useTracking().trackEvent
11+
1312
const { renderWithRelay } = setupTestWrapper<CollectionRailHomeViewSectionCardsTestQuery>({
1413
Component: ({ marketingCollection }) => <CollectionRail collection={marketingCollection} />,
1514
query: graphql`
@@ -26,4 +25,43 @@ describe("CollectionRail", () => {
2625

2726
expect(screen.getByText(/mock-Value-for-Field-"Title"/)).toBeOnTheScreen()
2827
})
28+
29+
it("when tapping on an artwork", () => {
30+
renderWithRelay({
31+
FilterArtworksConnection: () => ({ edges, counts: { total: 2 } }),
32+
})
33+
34+
fireEvent.press(screen.getByTestId(`artwork-${edges[0].node.slug}`))
35+
36+
expect(navigate).toHaveBeenCalledWith(`/artwork/${edges[0].node.internalID}`)
37+
expect(trackEvent).toHaveBeenLastCalledWith({
38+
action: "tappedArtworkGroup",
39+
context_module: "collectionRail",
40+
context_screen_owner_type: "collectionsCategory",
41+
destination_screen_owner_slug: "1",
42+
destination_screen_owner_type: "artwork",
43+
horizontal_slide_position: 0,
44+
type: "thumbnail",
45+
})
46+
})
47+
48+
it("when tapping on the title", () => {
49+
renderWithRelay({
50+
FilterArtworksConnection: () => ({ edges, counts: { total: 1 } }),
51+
})
52+
53+
fireEvent.press(screen.getByText(/mock-Value-for-Field-"Title"/))
54+
55+
expect(navigate).toHaveBeenCalledWith('/collection/<mock-value-for-field-"slug">')
56+
expect(trackEvent).toHaveBeenLastCalledWith({
57+
action: "tappedArtworkGroup",
58+
context_module: "collectionRail",
59+
context_screen_owner_type: "collectionsCategory",
60+
destination_screen_owner_slug: '<mock-value-for-field-"slug">',
61+
destination_screen_owner_type: "collection",
62+
type: "viewAll",
63+
})
64+
})
2965
})
66+
67+
const edges = [{ node: { internalID: "1", href: "/artwork/1", slug: "1-slug" } }]

src/app/Scenes/CollectionsByCategory/__tests__/CollectionsChips.tests.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { screen } from "@testing-library/react-native"
1+
import { fireEvent, screen } from "@testing-library/react-native"
22
import { CollectionsChipsTestQuery } from "__generated__/CollectionsChipsTestQuery.graphql"
33
import { CollectionsChips } from "app/Scenes/CollectionsByCategory/CollectionsChips"
4+
import { navigate } from "app/system/navigation/navigate"
45
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper"
56
import { graphql } from "react-relay"
7+
import { useTracking } from "react-tracking"
68

79
describe("CollectionsChips", () => {
10+
const trackEvent = useTracking().trackEvent
11+
812
const { renderWithRelay } = setupTestWrapper<CollectionsChipsTestQuery>({
913
Component: CollectionsChips,
1014
query: graphql`
@@ -21,4 +25,21 @@ describe("CollectionsChips", () => {
2125

2226
expect(screen.getByText(/mock-value-for-field-"title"/)).toBeOnTheScreen()
2327
})
28+
29+
it("when tapping on a chip", () => {
30+
renderWithRelay()
31+
32+
fireEvent.press(screen.getByText(/mock-value-for-field-"title"/))
33+
34+
expect(navigate).toHaveBeenCalledWith('/collection/<mock-value-for-field-"slug">')
35+
expect(trackEvent).toHaveBeenCalledWith({
36+
action: "tappedCollectionGroup",
37+
context_module: "collectionRail",
38+
context_screen_owner_type: "collectionsCategory",
39+
destination_screen_owner_slug: '<mock-value-for-field-"slug">',
40+
destination_screen_owner_type: "collection",
41+
horizontal_slide_position: 0,
42+
type: "thumbnail",
43+
})
44+
})
2445
})
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {
2+
ActionType,
3+
ContextModule,
4+
OwnerType,
5+
TappedArtworkGroup,
6+
TappedCollectionGroup,
7+
} from "@artsy/cohesion"
8+
import { useTracking } from "react-tracking"
9+
10+
export const useCollectionByCategoryTracking = () => {
11+
const { trackEvent } = useTracking()
12+
13+
const trackChipTap = (slug: string, index: number) => {
14+
const payload: TappedCollectionGroup = {
15+
action: ActionType.tappedCollectionGroup,
16+
context_module: ContextModule.collectionRail,
17+
context_screen_owner_type: OwnerType.collectionsCategory,
18+
destination_screen_owner_type: OwnerType.collection,
19+
destination_screen_owner_slug: slug,
20+
horizontal_slide_position: index,
21+
type: "thumbnail",
22+
}
23+
trackEvent(payload)
24+
}
25+
26+
const trackArtworkRailItemTap = (slug: string, index: number) => {
27+
const payload: TappedArtworkGroup = {
28+
action: ActionType.tappedArtworkGroup,
29+
context_module: ContextModule.collectionRail,
30+
context_screen_owner_type: OwnerType.collectionsCategory,
31+
destination_screen_owner_slug: slug,
32+
destination_screen_owner_type: OwnerType.artwork,
33+
horizontal_slide_position: index,
34+
type: "thumbnail",
35+
}
36+
trackEvent(payload)
37+
}
38+
39+
const trackArtworkRailViewAllTap = (slug: string) => {
40+
const payload: TappedArtworkGroup = {
41+
action: ActionType.tappedArtworkGroup,
42+
context_module: ContextModule.collectionRail,
43+
context_screen_owner_type: OwnerType.collectionsCategory,
44+
destination_screen_owner_slug: slug,
45+
destination_screen_owner_type: OwnerType.collection,
46+
type: "viewAll",
47+
}
48+
trackEvent(payload)
49+
}
50+
51+
return {
52+
trackChipTap,
53+
trackArtworkRailItemTap,
54+
trackArtworkRailViewAllTap,
55+
}
56+
}

0 commit comments

Comments
 (0)