googleanalytics / autotrack

Automatic and enhanced Google Analytics tracking for common user interactions on the web.
Other
4.92k stars 560 forks source link

urlChangeTracker does not work #246

Closed LZinsmeister closed 4 years ago

LZinsmeister commented 4 years ago

I am trying to use the urlChangeTracker for tracking the use of an R shiny application hosted on in a linux virtual machine in the cloud. The shiny application is basically a single page application in the form of a dashboard containing several tabs. I have build the shiny application in such a way that for every tab the url of the website is changed, so that I can use the urlChangeTracker plugin to track which tabs users are viewing.

My tracking code snippet looks like this:

<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');

ga('require', 'urlChangeTracker')

ga('send', 'pageview');
</script>
<script async src="https://www.google-analytics.com/analytics_debug.js"></script>
<script async src="path/to/autotrack.js"></script>

I did not install autotrack.js with npm but I have downloaded the file from the git repository and saved it in an accesible directory. I have also checked whether the autotrack.js file is available by visiting myWebsite.com/autotrack.js, and it was available as such:

(function(){var g,aa="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(c.get||c.set)throw new TypeError("ES3 does not support getters and setters.");a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)},k="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;function l(){l=function(){};k.Symbol||(k.Symbol=ba)}var ca=0;function ba(a){return"jscomp_symbol_"+(a||"")+ca++}
function m(){l();var a=k.Symbol.iterator;a||(a=k.Symbol.iterator=k.Symbol("iterator"));"function"!=typeof Array.prototype[a]&&aa(Array.prototype,a,{configurable:!0,writable:!0,value:function(){return da(this)}});m=function(){}}function da(a){var b=0;return ea(function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}})}function ea(a){m();a={next:a};a[k.S 
[...]

The analytics_debug.js report looks as follows:

Initializing Google Analytics.
analytics_debug.js:16 No plugin url set for "urlChangeTracker".
analytics_debug.js:16 Registered new plugin: ga(provide, "cleanUrlTracker", Function)
analytics_debug.js:16 Registered new plugin: ga(provide, "eventTracker", Function)
analytics_debug.js:16 Registered new plugin: ga(provide, "impressionTracker", Function)
analytics_debug.js:16 Registered new plugin: ga(provide, "maxScrollTracker", Function)
analytics_debug.js:16 Registered new plugin: ga(provide, "mediaQueryTracker", Function)
analytics_debug.js:16 Registered new plugin: ga(provide, "outboundFormTracker", Function)
analytics_debug.js:16 Registered new plugin: ga(provide, "outboundLinkTracker", Function)
analytics_debug.js:16 Registered new plugin: ga(provide, "pageVisibilityTracker", Function)
analytics_debug.js:16 Registered new plugin: ga(provide, "socialWidgetTracker", Function)
analytics_debug.js:16 Registered new plugin: ga(provide, "urlChangeTracker", Function)
analytics_debug.js:16 Running command: ga("create", "UA-XXXXX-Y", "auto")
analytics_debug.js:16 Creating new tracker: t0
analytics_debug.js:16 Auto cookieDomain found: "xyz.com"
analytics_debug.js:16 Running command: ga("require", "urlChangeTracker")
analytics_debug.js:16 Plugin "urlChangeTracker" intialized on tracker "t0".
analytics_debug.js:16 Running command: ga("send", "pageview")
analytics_debug.js:16 Setting throttling cookie: "_gat"
analytics_debug.js:16 
Sent beacon:
v=1&_v=j79d&a=1855665599&t=pageview&_s=1&dl=https%3A%2F%2Fxyz.com%2Ftab1%2tab2%2F&ul=nl-nl&de=UTF-8&dt=xyz%20tab3%20tab4&sd=24-bit&sr=1920x1080&vp=1140x901&je=0&_u=QCCAAEAD~&jid=2127417377&gjid=1964178890&cid=428550628.1567514178&tid=UA-55220421-10&_gid=1087991776.1567514178&_r=1&_av=2.4.1&_au=100&did=i5iSjo&z=198028291

analytics_debug.js:16 <unknown>        (&did)  i5iSjo
analytics_debug.js:16 _j1              (&jid)  2127417377
analytics_debug.js:16 _j2              (&gjid) 1964178890
analytics_debug.js:16 adSenseId        (&a)    1855665599
analytics_debug.js:16 apiVersion       (&v)    1
analytics_debug.js:16 clientId         (&cid)  428550628.1567514178
analytics_debug.js:16 encoding         (&de)   UTF-8
analytics_debug.js:16 hitType          (&t)    pageview
analytics_debug.js:16 javaEnabled      (&je)   0
analytics_debug.js:16 language         (&ul)   nl-nl
analytics_debug.js:16 location         (&dl)   https://xyz.com/
analytics_debug.js:16 screenColors     (&sd)   24-bit
analytics_debug.js:16 screenResolution (&sr)   1920x1080
analytics_debug.js:16 title            (&dt)   xyz
analytics_debug.js:16 trackingId       (&tid)  UA-XXXXX-Y
analytics_debug.js:16 viewportSize     (&vp)   1140x901
analytics_debug.js:16 Registered new plugin: ga(provide, "render", Function)
(index):544 Uncaught TypeError: $(...).accordion is not a function
    at HTMLDocument.<anonymous> ((index):544)
    at i (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at Function.ready (jquery.min.js:2)
    at HTMLDocument.K (jquery.min.js:2)
(anonymous) @ (index):544
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
K @ jquery.min.js:2
jquery.min.js:2 GET https://xyz.com/fonts/Gustan-Thin.woff net::ERR_ABORTED 404 (Not Found)
(anonymous) @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
K @ jquery.min.js:2
jquery.min.js:2 GET https://xyz.com/fonts/Gustan-Extrabold.woff net::ERR_ABORTED 404 (Not Found)
(anonymous) @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
K @ jquery.min.js:2
jquery.min.js:2 GET https://xyz.com/fonts/Gustan-Black.woff net::ERR_ABORTED 404 (Not Found)
(anonymous) @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
K @ jquery.min.js:2
jquery.min.js:2 GET https://xyz.com/fonts/Gustan-Light.woff net::ERR_ABORTED 404 (Not Found)
(anonymous) @ jquery.min.js:2
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
K @ jquery.min.js:2
shiny-server-client.min.js:1 Tue Sep 03 2019 15:31:37 GMT+0200 (Midden-Europese zomertijd) [INF]: Connection opened. https://xyz.com/
shiny-server-client.min.js:1 Tue Sep 03 2019 15:31:37 GMT+0200 (Midden-Europese zomertijd) [DBG]: Open channel 0
shiny-server-client.min.js:1 Tue Sep 03 2019 15:31:39 GMT+0200 (Midden-Europese zomertijd) [DBG]: 3 message(s) discarded from buffer
shiny-server-client.min.js:1 Tue Sep 03 2019 15:31:47 GMT+0200 (Midden-Europese zomertijd) [DBG]: 1 message(s) discarded from buffer
spinner.js:11 select_tab3
jquery.min.js:4 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
send @ jquery.min.js:4
ajax @ jquery.min.js:4
n._evalUrl @ jquery.min.js:4
Ha @ jquery.min.js:3
append @ jquery.min.js:3
renderDependency @ output_binding_html.js:109
(anonymous) @ output_binding_html.js:22
each @ jquery.min.js:2
exports.renderDependencies @ output_binding_html.js:21
exports.renderHtml @ output_binding_html.js:68
exports.renderContent @ output_binding_html.js:46
renderValue @ output_binding_html.js:14
onValueChange @ output_binding.js:16
onValueChange @ output_binding_adapter.js:21
receiveOutput @ shinyapp.js:332
(anonymous) @ shinyapp.js:544
_sendMessagesToHandlers @ shinyapp.js:529
dispatchMessage @ shinyapp.js:515
c.onmessage @ shinyapp.js:112
_conn.onmessage @ shiny-server-client.min.js:1
MultiplexClient._conn.onmessage @ shiny-server-client.min.js:1
BufferedResendConnection._handleMessage @ shiny-server-client.min.js:1
RobustConnection._handleMessage @ shiny-server-client.min.js:1
conn.<computed> @ shiny-server-client.min.js:2
d.dispatchEvent @ sockjs-0.3.4.min.js:27
y._dispatchMessage @ sockjs-0.3.4.min.js:27
y._didMessage @ sockjs-0.3.4.min.js:27
e.ws.onmessage @ sockjs-0.3.4.min.js:27
spinner.js:11 select_tab2
spinner.js:11 select_tab3
spinner.js:11 select_tab1
[...]

So I think the initial pageview is correctly tracked (I also see pageviews on the GA page), but the url changes are not tracked. So how can I make this work?

LZinsmeister commented 4 years ago

Found the solution! Had to do with the way I updated the url in shiny.