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

fix: marketing link tracking #9445

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/app/system/navigation/navigate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from "events"
import { ActionType, OwnerType, Screen } from "@artsy/cohesion"
import { addBreadcrumb } from "@sentry/react-native"
import { addBreadcrumb, captureMessage } from "@sentry/react-native"
import { AppModule, ViewOptions, modules } from "app/AppRegistry"
import { LegacyNativeModules } from "app/NativeModules/LegacyNativeModules"
import { BottomTabType } from "app/Scenes/BottomTabs/BottomTabType"
Expand Down Expand Up @@ -68,8 +68,21 @@ export async function navigate(url: string, options: NavigateOptions = {}) {

// marketing url requires redirect
if (targetURL.startsWith("https://click.artsy.net")) {
const response = await fetch(targetURL)
if (response.url) {
let response
try {
response = await fetch(targetURL)
} catch (error) {
if (__DEV__) {
console.warn(error)
} else {
captureMessage(
`[navigate] Error fetching marketing url redirect on: ${targetURL} failed with error: ${error}`,
"error"
)
}
}

if (response?.url) {
Comment on lines +71 to +85
Copy link
Member Author

Choose a reason for hiding this comment

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

unrelated - just adding a catch to this fetch

targetURL = response.url
}
}
Expand Down
38 changes: 27 additions & 11 deletions src/app/utils/useDeepLinks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { captureMessage } from "@sentry/react-native"
import { GlobalStore } from "app/store/GlobalStore"
import { navigate } from "app/system/navigation/navigate"
import { useEffect, useRef } from "react"
Expand Down Expand Up @@ -29,30 +30,45 @@ export function useDeepLinks() {
}
}, [isHydrated, isLoggedIn])

const handleDeepLink = (url: string) => {
// These will be redirected, avoided double tracking
if (!url.includes("click.artsy.net")) {
gkartalis marked this conversation as resolved.
Show resolved Hide resolved
trackEvent(tracks.deepLink(url))
const handleDeepLink = async (url: string) => {
let targetURL

// If the url is a marketing url, we need to fetch the redirect
if (url.includes("click.artsy.net")) {
try {
targetURL = await fetch(url)
} catch (error) {
if (__DEV__) {
console.warn(error)
} else {
captureMessage(
`[handleDeepLink] Error fetching marketing url redirect on: ${url} failed with error: ${error}`,
"error"
)
}
}
}

const deepLinkUrl = targetURL?.url ?? url

// We track the deep link opened event
trackEvent(tracks.deepLink(deepLinkUrl))

// If the state is hydrated and the user is logged in
// We navigate them to the the deep link
if (isHydrated && isLoggedIn) {
navigate(url)
// and we track the deep link

navigate(deepLinkUrl)
}

// Otherwise, we save the deep link url
// to redirect them to the login screen once they log in
launchURL.current = url
launchURL.current = deepLinkUrl
}

useEffect(() => {
if (isLoggedIn && launchURL.current) {
// These will be redirected, avoided double tracking
if (!launchURL.current.includes("click.artsy.net")) {
trackEvent(tracks.deepLink(launchURL.current))
}

Comment on lines -51 to -55
Copy link
Member Author

Choose a reason for hiding this comment

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

this was causing double tracking for logged out users (for non-marketing links)

// Navigate to the saved launch url
navigate(launchURL.current)
// Reset the launchURL
Expand Down