gatsby-plugin-segment-js icon indicating copy to clipboard operation
gatsby-plugin-segment-js copied to clipboard

delayLoad and delayLoadTime did not work

Open eDubrovsky opened this issue 2 years ago • 11 comments

Hi! At version 4.0.3, the delay load didn't work.

delayLoad: true,
delayLoadTime: 1000

Segment load without page scroll event or Link click.

eDubrovsky avatar Dec 17 '22 09:12 eDubrovsky

I'll have a look. I guess nobody really has been using that or watching closely?

Are you a new user of this library, or that option? Wondering how long it's been broken.

newhouse avatar Dec 17 '22 22:12 newhouse

Hi @eDubrovsky I think you just need to set the trackPage: true option...the delayLoad functionality is working for me.

newhouse avatar Dec 18 '22 05:12 newhouse

@newhouse Hi!

I have used this plugin for about 10 months, and version 3.7.1 works perfectly. :)

I found the problem scenario. My current setting:

trackPage: true,
trackPageDelay: 50,
delayLoad: true,
delayLoadTime: 1000

In this case, the delay time = trackPageDelay = 50. And script loaded without a page scroll event. But delayLoadTime and loading script by scroll event no applied in this case.

If I set delayLoad to false, the script loading without delay and works correctly.

eDubrovsky avatar Dec 18 '22 08:12 eDubrovsky

Hi @eDubrovsky maybe I'm misunderstanding. Are you saying that:

  1. With the settings listed above
  2. you expected the pageview to not occur until the User scrolls?

I think perhaps:

  • what I'm seeing happen is what I am expecting
  • you are seeing the same thing that I am seeing, but it is NOT what you are expecting.

Can you try to clarify a bit for me - I think I'm not following. Thank you!

newhouse avatar Dec 19 '22 19:12 newhouse

I am trying to improve my website's TTI for PageSpeed Insights by Google. When I set delayLoad: true I am expecting this scenario:

  1. User opens my site, and Segment is NOT loading (it helps with a better result in PageSpeed Insights)
  2. After the user scrolls the page, the Segment loading with delayLoadTime: 1000
  3. After that analytics.page() trigger with trackPageDelay: 50

CleanShot 2022-12-20 at 00 24 33@2x

eDubrovsky avatar Dec 19 '22 20:12 eDubrovsky

OK, I think I understand.

You expect to not see the loading occur until either (a) the user scrolls or (b) a page routing change.

I think what I've done in 4.x is more like breaking-change and expected behavior from this issue: https://github.com/benjaminhoffman/gatsby-plugin-segment-js/issues/37

At this point, what I think I should do is leave things how they are with the options you've chosen, but add an additional option like delayLoadUntilScrollOrRouteChange that if true will do what you're expecting....which was the old actual behavior but not the new current behavior.

How does that sound?

newhouse avatar Dec 19 '22 21:12 newhouse

Code back at 3.7.1:

https://github.com/benjaminhoffman/gatsby-plugin-segment-js/tree/897db9ba7f2b0bab91aab3c87bac1682fcf36396 https://github.com/benjaminhoffman/gatsby-plugin-segment-js/blob/897db9ba7f2b0bab91aab3c87bac1682fcf36396/src/gatsby-browser.js https://github.com/benjaminhoffman/gatsby-plugin-segment-js/blob/897db9ba7f2b0bab91aab3c87bac1682fcf36396/src/gatsby-ssr.js

newhouse avatar Dec 19 '22 21:12 newhouse

@newhouse delayLoadUntilScrollOrRouteChange option sounds cool, yep! 🤟

eDubrovsky avatar Dec 20 '22 08:12 eDubrovsky

@eDubrovsky can you please install 5.0.0-beta.0 and play around with it a bit to see if it's working correctly?

You can see the new options here: https://github.com/benjaminhoffman/gatsby-plugin-segment-js/pull/59/files

newhouse avatar Dec 21 '22 20:12 newhouse

Actually 5.0.0-beta.1, please.

newhouse avatar Dec 21 '22 21:12 newhouse

Yes, it works! Like it! 🤟

p.s.: how can I turn off plugin console.logs?

CleanShot 2022-12-22 at 18 17 07@2x

eDubrovsky avatar Dec 22 '22 14:12 eDubrovsky