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

Expose "sendUpdate" function for external use. #54

Closed
odensc opened this issue Jun 27, 2020 · 6 comments
Closed

Expose "sendUpdate" function for external use. #54

odensc opened this issue Jun 27, 2020 · 6 comments

Comments

@odensc
Copy link

odensc commented Jun 27, 2020

It'd be nice if the sendUpdate function in script.js was exposed. In SPAs, Shynet doesn't properly detect page transitions because the browser page is never reloaded. Hence you have to wait for the next heartbeat for anything to be tracked.

If the sendUpdate function was exposed, it could be called in your router transition event handler and would allow for these events to be tracked. For example with Fathom and Next.js you can do something like this:

Router.events.on("routeChangeComplete", () => {
  fathom.trackPageview();
});
@odensc
Copy link
Author

odensc commented Jun 27, 2020

The JS script could probably use some other updates too, like using window.addEventListener instead of directly overriding the onload prop. Let me know if you're open to these changes, I'm glad to make a PR.

@milesmcc
Copy link
Owner

Yeah, I'd like to do a pretty significant refactoring of the script -- I'll definitely expose some kind of shynet.newHit() function.

@odensc
Copy link
Author

odensc commented Jun 29, 2020

Latest update works great in my Next.js app - thanks!

@mrspartak
Copy link

Hi @milesmcc, as I can tell you did not expose newHit function yet? Should I just use shynet.newPageLoad() for SPA then?

@milesmcc
Copy link
Owner

milesmcc commented Jul 3, 2020

Yep! Shynet.newPageLoad() is what you want to use.

@mrspartak
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants