From c9c643865330d6f2076a84dcc0ef3d1969ba1db4 Mon Sep 17 00:00:00 2001 From: George Kartalis Date: Wed, 18 Oct 2023 12:51:40 +0200 Subject: [PATCH 1/5] fix: marketing link tracking --- src/app/utils/useDeepLinks.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/app/utils/useDeepLinks.ts b/src/app/utils/useDeepLinks.ts index 911d4b2bd76..04541f2ec00 100644 --- a/src/app/utils/useDeepLinks.ts +++ b/src/app/utils/useDeepLinks.ts @@ -30,10 +30,8 @@ export function useDeepLinks() { }, [isHydrated, isLoggedIn]) const handleDeepLink = (url: string) => { - // These will be redirected, avoided double tracking - if (!url.includes("click.artsy.net")) { - trackEvent(tracks.deepLink(url)) - } + // track deep link tap + trackEvent(tracks.deepLink(url)) // If the state is hydrated and the user is logged in // We navigate them to the the deep link From 846532bdde41a9a7ead8020bec28bee5e335f700 Mon Sep 17 00:00:00 2001 From: George Kartalis Date: Thu, 19 Oct 2023 17:18:36 +0200 Subject: [PATCH 2/5] refactor: tracking logic to deobfuscate marketing link --- src/app/system/navigation/navigate.ts | 19 ++++++++++++++++--- src/app/utils/useDeepLinks.ts | 26 ++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/app/system/navigation/navigate.ts b/src/app/system/navigation/navigate.ts index e01cf0b27ea..adf1c34c4a9 100644 --- a/src/app/system/navigation/navigate.ts +++ b/src/app/system/navigation/navigate.ts @@ -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" @@ -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) { targetURL = response.url } } diff --git a/src/app/utils/useDeepLinks.ts b/src/app/utils/useDeepLinks.ts index 04541f2ec00..ff68b733e27 100644 --- a/src/app/utils/useDeepLinks.ts +++ b/src/app/utils/useDeepLinks.ts @@ -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" @@ -29,19 +30,36 @@ export function useDeepLinks() { } }, [isHydrated, isLoggedIn]) - const handleDeepLink = (url: string) => { + const handleDeepLink = async (url: string) => { + let targetURL + + 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 + // track deep link tap - trackEvent(tracks.deepLink(url)) + 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) + 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(() => { From d62e86eabb4f3a71682f7b92f703ac38ed2dfec1 Mon Sep 17 00:00:00 2001 From: George Kartalis Date: Thu, 19 Oct 2023 17:45:42 +0200 Subject: [PATCH 3/5] refactor: logic to track marketing link once --- src/app/utils/useDeepLinks.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/utils/useDeepLinks.ts b/src/app/utils/useDeepLinks.ts index ff68b733e27..177f0e9105b 100644 --- a/src/app/utils/useDeepLinks.ts +++ b/src/app/utils/useDeepLinks.ts @@ -33,6 +33,7 @@ export function useDeepLinks() { const handleDeepLink = async (url: string) => { let targetURL + // If the url is a marketing url, we need to fetch the redirect try { targetURL = await fetch(url) } catch (error) { @@ -48,12 +49,12 @@ export function useDeepLinks() { const deepLinkUrl = targetURL?.url ?? url - // track deep link tap - 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) { + // and we track the deep link + trackEvent(tracks.deepLink(deepLinkUrl)) + navigate(deepLinkUrl) } From f15eb88928e9a19ab44c064879fd8cff9b6747ed Mon Sep 17 00:00:00 2001 From: George Kartalis Date: Thu, 19 Oct 2023 17:54:04 +0200 Subject: [PATCH 4/5] refactor: fetch only when needed --- src/app/utils/useDeepLinks.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/app/utils/useDeepLinks.ts b/src/app/utils/useDeepLinks.ts index 177f0e9105b..4e87279ec39 100644 --- a/src/app/utils/useDeepLinks.ts +++ b/src/app/utils/useDeepLinks.ts @@ -34,16 +34,18 @@ export function useDeepLinks() { let targetURL // If the url is a marketing url, we need to fetch the redirect - 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" - ) + 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" + ) + } } } From 669e89d2cc96ae8a2e585a60158cf0f406acc024 Mon Sep 17 00:00:00 2001 From: George Kartalis Date: Thu, 19 Oct 2023 19:24:14 +0200 Subject: [PATCH 5/5] fix: double tracking --- src/app/utils/useDeepLinks.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/app/utils/useDeepLinks.ts b/src/app/utils/useDeepLinks.ts index 4e87279ec39..c7424c056d2 100644 --- a/src/app/utils/useDeepLinks.ts +++ b/src/app/utils/useDeepLinks.ts @@ -51,11 +51,13 @@ export function useDeepLinks() { 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) { // and we track the deep link - trackEvent(tracks.deepLink(deepLinkUrl)) navigate(deepLinkUrl) } @@ -67,11 +69,6 @@ export function useDeepLinks() { useEffect(() => { if (isLoggedIn && launchURL.current) { - // These will be redirected, avoided double tracking - if (!launchURL.current.includes("click.artsy.net")) { - trackEvent(tracks.deepLink(launchURL.current)) - } - // Navigate to the saved launch url navigate(launchURL.current) // Reset the launchURL