Comments on: Scroll Tracking for Single-Page Applications (GTM) https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/ APIs, Sheets, and Analytics Thu, 02 Sep 2021 05:47:02 +0000 hourly 1 https://wordpress.org/?v=6.5.5 By: AK https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-20397 Wed, 11 Nov 2020 12:58:47 +0000 https://mixedanalytics.com/?p=12450#comment-20397 In reply to Ana.

Well, try putting a simple `console.log` statement (or alert() for something more obvious) in that anonymous function and you'll notice that it isn't really called.

I basically updated `onDocHeightChange` to be `onLocationChange` which would check for changes to `location.href` every half a second and reset internal state, same as `onDocHeightChange` did.

]]>
By: Ana https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-20358 Tue, 10 Nov 2020 12:36:26 +0000 https://mixedanalytics.com/?p=12450#comment-20358 In reply to AK.

Hi Kriya, thank you for the comment! This is very interesting to read. Though I'm not totally sure what to make of it, because it seems to work fine as is on the SPA sites I've tested it on, and when I remove the custom HTML tag from step 7, it no longer works. Do you have any suggestions for how to make this a more reliable scroll tracking script for SPA pages?

]]>
By: AK https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-20342 Mon, 09 Nov 2020 17:57:44 +0000 https://mixedanalytics.com/?p=12450#comment-20342 Looks like step 7, the one said to be the core step to make the plugin work on single-page apps, is not doing anything. The function is never called, and even if it were called (as an IIFE), the result would be an error as `this` would refer to Window object that does not have any `_artifacts` property defined.

Those three statements are a copy of ScrollTracker class' `destroy` method from the plugin (which is never actually used in the plugin itself anyway).

To test it yourself, try removing that Custom HTML tag from step 7 and navigate around your site/app. The events will still be triggered for any page that has a different height than the previous one as the plugin has a method, `onDocHeightChange`, that checks for changes in the height of the document every half second, resetting internal state if it does.

However, that internal logic will not work for any site or app that has a fixed height for pages, so I've updated it to work on history change.

]]>
By: Ana https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-19369 Sun, 20 Sep 2020 10:39:31 +0000 https://mixedanalytics.com/?p=12450#comment-19369 In reply to Andrew Chepurny.

Sorry, good question but I don't know the answer as I didn't create the script myself. I would just test it out and see how it goes.

]]>
By: Andrew Chepurny https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-19367 Sun, 20 Sep 2020 02:13:49 +0000 https://mixedanalytics.com/?p=12450#comment-19367 Question on Horizontal scrolling; I have a DIV container on my SPA landing page. It scrolls deep horizontally but the rest of the page doesn't. Will this work just for that DIV container?

]]>
By: Ana https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-19323 Thu, 17 Sep 2020 02:15:40 +0000 https://mixedanalytics.com/?p=12450#comment-19323 In reply to Michael Mahannah.

Thanks for letting me know! On my test site, it seems to work even on second page views, but I will update the post to note that it might not always work as expected.

]]>
By: Michael Mahannah https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-19314 Wed, 16 Sep 2020 20:14:40 +0000 https://mixedanalytics.com/?p=12450#comment-19314 Great stuff! I loved working with Luna while I was at Caterpillar. Nice mod. One interesting thing I noticed (or maybe didn't adjust right) is that the scroll tracking doesn't like to fire again when you return to the same page in a session. For example user moves from A (first time) to B to C to A (second time)

It seems that the tag fires on A (first time), B, & C as expected but fails to fire when the user returns to page A for the 2nd time.

]]>
By: Jean-Christophe Chouinard https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-18717 Sun, 23 Aug 2020 22:47:19 +0000 https://mixedanalytics.com/?p=12450#comment-18717 Hey Ana, haven't read your blog in a while an I stumble on this post! Great work! Thanks for sharing so many good stuff!

]]>
By: Ana https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-17802 Mon, 29 Jun 2020 14:28:33 +0000 https://mixedanalytics.com/?p=12450#comment-17802 In reply to Jason.

Awesome, I love to hear this 🙂 I was dealing with the same issue, so I totally get it...

]]>
By: Jason https://mixedanalytics.com/blog/scroll-tracking-single-page-applications-gtm/#comment-17800 Mon, 29 Jun 2020 13:39:01 +0000 https://mixedanalytics.com/?p=12450#comment-17800 Thank you for this article! I have been working on this work a week and this solves my problem! Thank you for putting this together!

]]>