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

[✨] How to distinguish between link preload and page visit #6269

Open
juanpmarin opened this issue May 7, 2024 · 2 comments
Open

[✨] How to distinguish between link preload and page visit #6269

juanpmarin opened this issue May 7, 2024 · 2 comments
Labels
P1: nice to have / fix Not an urgent enhancement or bug (has workarounds) STATUS-2: requires discussion Requires further discussion before moving forward TYPE: enhancement New feature or request WAITING FOR: team Waiting for one of the core team members to review and reply

Comments

@juanpmarin
Copy link

Is your feature request related to a problem?

I'm trying to collect some analytics when a certain page is visited. I'm storing an event every time a routeLoader is executed, but when a Link to that page is hovered, the routeLoader is executed without the user actually visiting the page

Describe the solution you'd like

Be able to distinguish if the current request is a preload or an actual visit to the page, in the routeLoader

Describe alternatives you've considered

Calling a server function from a useVisibleTask$ but seems overkilling

Additional context

No response

@juanpmarin juanpmarin added STATUS-1: needs triage New issue which needs to be triaged TYPE: enhancement New feature or request labels May 7, 2024
@PatrickJS
Copy link
Member

assigned to @yousefmarey12 (can't do it directly with github for some reason atm) it might be best to send a prefetch header with prefetch calls to detect when requests are only prefetching

@shairez
Copy link
Collaborator

shairez commented Jun 1, 2024

Thanks @yousefmarey12 for your research and hard work!

@juanpmarin it seems like this requires more investigation, and because we're focused on V2, I suggest we'll evaluate a proper solution for it after V2 is done.

In the meantime, what do you say about the following workaround:
instead of using a visible task, what do you think about using a regular task that calls a server$ function? (in case you analytics logic is server side only)

Something like:

const sendAnalytics = server$(() => {
  console.log('sending');
});

export default component$(() => {

  useTask$(() => {
    sendAnalytics();
  });
  ...

That way no javascript will run on initial page load (unlike with visible task which "resumes" and executes its javascript on page load)

@shairez shairez added WAITING FOR: team Waiting for one of the core team members to review and reply P1: nice to have / fix Not an urgent enhancement or bug (has workarounds) STATUS-2: requires discussion Requires further discussion before moving forward and removed STATUS-1: needs triage New issue which needs to be triaged labels Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1: nice to have / fix Not an urgent enhancement or bug (has workarounds) STATUS-2: requires discussion Requires further discussion before moving forward TYPE: enhancement New feature or request WAITING FOR: team Waiting for one of the core team members to review and reply
Projects
None yet
Development

No branches or pull requests

3 participants