-
Notifications
You must be signed in to change notification settings - Fork 582
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c9c6438
fix: marketing link tracking
gkartalis 846532b
refactor: tracking logic to deobfuscate marketing link
gkartalis d62e86e
refactor: logic to track marketing link once
gkartalis f15eb88
refactor: fetch only when needed
gkartalis 669e89d
fix: double tracking
gkartalis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -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,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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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