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

feat: Preserve search parameters in external links #258

Merged
merged 16 commits into from
Dec 14, 2023
Merged

Conversation

DiogoSoaress
Copy link
Member

@DiogoSoaress DiogoSoaress commented Dec 12, 2023

What it solves

We want to preserve the search parameters when navigating the homepage.

How this PR fixes it

On page navigation the search parameters are merged and stored in the session storage key SAFE__searchParams and saved to a Context.
All links navigating to https://app.safe.global include the stored search parameters.

Copy link

github-actions bot commented Dec 12, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

Copy link

github-actions bot commented Dec 12, 2023

Branch preview

✅ Deployed to dev:

https://safe-web-landing.dev.5afe.dev

@DiogoSoaress
Copy link
Member Author

I would extend this behaviour to the other links in the homepage if you could navigate to a campaign page from https://safe.global , otherwise I don't see a justification to attach campaign related UTM codes when navigating to https://app.safe.global/

@katspaugh
Copy link
Member

  • I would do it for all pages, not just campaigns
  • Store the initial UTM params in the session storage so that they aren't gone on page refresh
  • Why create a new component? You could just add it directly to ExternalLink.
  • Next.js has a hook to get parsed params, which AFAIK is now preferred to useRouter, check out https://nextjs.org/docs/app/api-reference/functions/use-search-params

@DiogoSoaress
Copy link
Member Author

DiogoSoaress commented Dec 13, 2023

I would do it for all pages, not just campaigns

Why?

Store the initial UTM params in the session storage so that they aren't gone on page refresh

The search params are not lost on page refresh. This approach is however necessary if we want to hydrate the links on all pages with the UTM params, right?

@katspaugh
Copy link
Member

katspaugh commented Dec 13, 2023

Because the user can:

  1. come to a campaign page from a twitter link
  2. navigate to another page on the site
    2a. (potentially refresh the page)
  3. only then go to app.safe.global

We lose the UTM params on steps 2 and 2a in your current implementation. Refreshing the page is less likely but navigating within the website is very likely.

@DiogoSoaress
Copy link
Member Author

To clarify on the campaigns navigation:

  • the user cannot reach the campaigns from safe.global and only the buttons in the campaign page link to the custom /welcome route in app.safe.global. The links on other pages link to https://app.safe.global, see https://safe.global/wallet for example.

Am I missing / overlooking something?

@katspaugh
Copy link
Member

Once again: the user can navigate to another internal page from the campaign page (e.g. via the links in the footer), at which point UTM params are lost.
I just don't see the point of limiting this solution to one particular type of pages while also making it less robust.

@katspaugh
Copy link
Member

katspaugh commented Dec 13, 2023

I'll outline again my proposed solution which I shared before you started working on this PR:

  • On page load, in a global context, save UTM params into the context and sessionStorage.
  • Also attempt to restore any existing params from sessionStorage in case they are not in the URL.
  • For all app.safe.global links, read UTMs from the global context and append them to the link.

If you still disagree, please clarify the requiements with BI and marketing.

@DiogoSoaress DiogoSoaress changed the title feat: Pass UTM parameters to campaign links feat: Pass UTM parameters to external links in the homepage Dec 13, 2023
@DiogoSoaress DiogoSoaress changed the title feat: Pass UTM parameters to external links in the homepage feat: Preserve search parameters in external links Dec 13, 2023
Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

Importing the context, the append function and calling said function for every link in every component with external links isn’t very maintainable don’t you think? Please propose an alternative solution to discuss.

The context needs tests.

@DiogoSoaress
Copy link
Member Author

Please propose an alternative solution to discuss.

I think having a HOC to call the context and append the search params is more maintainable, avoiding all the duplicated code.
You mentioned above to use the ExternalLink component but we don't have that component in this repo so I need to create a new component for this purpose. WDYT?

@katspaugh
Copy link
Member

I don't see the need for a HoC. Just create a custom link component, e.g. SafeLink that has all the logic and renders a Link.

const finalHref = appendSearchParamsToURL(href, searchParams)

return (
<Link href={finalHref} target="_blank" rel="noreferrer">
Copy link
Member

Choose a reason for hiding this comment

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

We should remove rel="noreferrer" for app.safe.global links.

const SafeLink = ({ href, children }: { href: string; children: ReactNode }) => {
const searchParams = useContext(SearchParamsContext)

const finalHref = appendSearchParamsToURL(href, searchParams)
Copy link
Member

Choose a reason for hiding this comment

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

useMemo perhaps?

@katspaugh
Copy link
Member

Looks good to me.

@usame-algan could you also take a look when you have a minute?

Copy link
Member

@usame-algan usame-algan left a comment

Choose a reason for hiding this comment

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

Looks good 👍

I assume we use SafeLink for all links to app.safe.global but haven't checked each occurence.

Although for the Launch Wallet button in the header it doesn't seem to be used. Is that intended?

@DiogoSoaress
Copy link
Member Author

Launch Wallet button in the header it doesn't seem to be used

I've included it inside of the ContextProvider. Good catch @usame-algan

Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

Thanks Diogo.
In future reviews we should keep in mind that we should always use SafeLink instead of Link for all links except when 100% internal.

@DiogoSoaress
Copy link
Member Author

Definitely!
I am very curious to see how carrying the UTM parameters will give another dimension to our website and wallet app traffic.

@DiogoSoaress DiogoSoaress merged commit 173c225 into main Dec 14, 2023
5 checks passed
@DiogoSoaress DiogoSoaress deleted the pass-utm-params branch December 14, 2023 15:50
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants