dspace-angular
dspace-angular copied to clipboard
home page page triggers 2 page views in google analytics
Describe the bug During the page load of the DSpace front page 2 requests get send to google analytics. Both events signify a page view, but use a different way of contacting the google analytics api, one sends an event of type pageview and one triggers a virtual pageview.
Google analytics has made a chrome plugin to help debugging calls to it. Installing this tool gives the following output when visiting the home page of a DSpace instance:
\__, |\___/ \___/ \__, |_|\___| \__,_|_| |_|\__,_|_|\__, |\__|_|\___|___/
__/ | __/ | __/ |
|___/ |___/ |___/
analytics.js:30 Running analytics_debug.js. This script is intended for testing and debugging only.
log @ analytics.js:30
J @ analytics.js:29
(anonymous) @ analytics.js:129
(anonymous) @ analytics.js:129
analytics.js:30 Initializing Google Analytics.
analytics.js:30 Running command: ga("create", "UA-XXXXXX-X", "auto")
analytics.js:30 Creating new tracker: t0
analytics.js:30 Auto cookieDomain found: "none"
analytics.js:30 The tracking Id should only be of the format UA-NNNNNN-N.
log @ analytics.js:30
J @ analytics.js:29
La @ analytics.js:44
Td @ analytics.js:41
ad @ analytics.js:100
Z.create @ analytics.js:122
Y.b.<computed> @ analytics.js:79
jf.R @ analytics.js:121
jf.H @ analytics.js:119
Z.P @ analytics.js:126
cd @ analytics.js:113
A @ analytics.js:113
(anonymous) @ analytics.js:129
(anonymous) @ analytics.js:129
analytics.js:30 Running command: ga("send", "pageview", "/")
analytics.js:30
Sent beacon:
v=1&_v=j98d&a=792940351&t=pageview&_s=1&dl=http%3A%2F%2Flocalhost%2Fhome&dp=%2F&ul=nl-nl&de=UTF-8&dt=DSpace&sd=24-bit&sr=1920x1080&vp=1163x976&je=0&_u=AACAAEABAAAAACAAI~&jid=&gjid=&cid=1621726639.1664894804&tid=UA-XXXXXX-X&_gid=1109278256.1664894804&_slc=1&z=1612913127
analytics.js:30 _j1 (&jid)
analytics.js:30 _j2 (&gjid)
analytics.js:30 adSenseId (&a) 792940351
analytics.js:30 apiVersion (&v) 1
analytics.js:30 clientId (&cid) 1621726639.1664894804
analytics.js:30 encoding (&de) UTF-8
analytics.js:30 hitType (&t) pageview
analytics.js:30 javaEnabled (&je) 0
analytics.js:30 language (&ul) nl-nl
analytics.js:30 location (&dl) http://localhost/home
analytics.js:30 page (&dp) /
analytics.js:30 screenColors (&sd) 24-bit
analytics.js:30 screenResolution (&sr) 1920x1080
analytics.js:30 title (&dt) DSpace
analytics.js:30 trackingId (&tid) UA-XXXXXX-X
analytics.js:30 viewportSize (&vp) 1163x976
analytics.js:30 Registered new plugin: ga(provide, "render", Function)
core.mjs:24889 Angular is running in development mode. Call enableProdMode() to enable production mode.
analytics.js:30 Executing Google Analytics commands.
analytics.js:30 Running command: ga("send", "event", {eventCategory: "Event", eventAction: "pageView", eventLabel: undefined, eventValue: undefined, nonInteraction: undefined, page: "/home", userId: null, hitCallback: undefined})
analytics.js:30
Sent beacon:
v=1&_v=j98d&a=792940351&t=event&_s=2&dl=http%3A%2F%2Flocalhost%2Fhome&dp=%2Fhome&ul=nl-nl&de=UTF-8&dt=DSpace%20Angular%20%3A%3A%20DSpace%20Angular%20%3A%3A%20Home&sd=24-bit&sr=1920x1080&vp=1163x976&je=0&ec=Event&ea=pageView&_u=CACAAEABAAAAACAAI~&jid=&gjid=&cid=1621726639.1664894804&tid=UA-XXXXXX-X&_gid=1109278256.1664894804&z=76909085
analytics.js:30 _j1 (&jid)
analytics.js:30 _j2 (&gjid)
analytics.js:30 adSenseId (&a) 792940351
analytics.js:30 apiVersion (&v) 1
analytics.js:30 clientId (&cid) 1621726639.1664894804
analytics.js:30 encoding (&de) UTF-8
analytics.js:30 eventAction (&ea) pageView
analytics.js:30 eventCategory (&ec) Event
analytics.js:30 hitType (&t) event
analytics.js:30 javaEnabled (&je) 0
analytics.js:30 language (&ul) nl-nl
analytics.js:30 location (&dl) http://localhost/home
analytics.js:30 page (&dp) /home
analytics.js:30 screenColors (&sd) 24-bit
analytics.js:30 screenResolution (&sr) 1920x1080
analytics.js:30 title (&dt) DSpace Angular :: DSpace Angular :: Home
analytics.js:30 trackingId (&tid) UA-XXXXXX-X
analytics.js:30 viewportSize (&vp) 1163x976
I have already determined that the 2 requests come from different places in the code: One gets triggered by the view tracker component that is embedded in the home page. The other request is made because of the [browser-init component](https://github.com/DSpace/dspace-angular/blob/1370363a54e3194a5b1cbf195cccb86726e11409/src/modules/app/browser-init.service.ts#
L132). This adds the google tracker id to every page. I have also attached a screenshot of the http requests made during the loading of the home page.
To Reproduce Steps to reproduce the behavior:
- add a google analytics key to the backend configuration
- install the google analytics debugger extension in chrome
- visit the home page
- 2 page visits get send to google analytics, this is visible in the javascript console
Expected behavior 1 page visit gets send to google analytics
Related work Link to any related tickets or PRs here.
Hi Would this bug also be applicable to Google Analytics 4? Thanks Tanya Holm
We'd like to claim this ticket