Closed rutwick-alic closed 2 years ago
Hi @rutwick-alic 👋 thanks for raising this issue. Did you follow the example in the documentation?
Analytics.autoTrack('pageView', {
// REQUIRED, turn on/off the auto tracking
enable: true,
// OPTIONAL, the event name, by default is 'pageView'
eventName: 'pageView',
// OPTIONAL, the attributes of the event, you can either pass an object or a function
// which allows you to define dynamic attributes
attributes: {
attr: 'attr'
},
// when using function
// attributes: () => {
// const attr = somewhere();
// return {
// myAttr: attr
// }
// },
// OPTIONAL, by default is 'multiPageApp'
// you need to change it to 'SPA' if your app is a single-page app like React
type: 'multiPageApp',
// OPTIONAL, the service provider, by default is the Amazon Pinpoint
provider: 'AWSPinpoint',
// OPTIONAL, to get the current page url
getUrl: () => {
// the default function
return window.location.origin + window.location.pathname;
}
});
You might be able to get some insight into when/why the analytics event fires off as well by using either the Hub utility to listen to analytics events or by setting Amplify.Logger.LOG_LEVEL = "DEBUG"
.
Hi @chrisbonifacio Thank you for responding. Yes I have followed the config exactly as per the documentation. This is from my code:
// Check for auto tracked name
Analytics.autoTrack('pageView', {
provider: 'AWSPinpoint',
enable: true,
disable: false,
type: 'SPA',
attributes: () => {
return getAttrs() // returns the attributes
},
getUrl: () => getURL() // returns the URL
})
Thanks.
Hi @rutwick-alic When first visiting a page, do you see this events
network request being made once? It seems like it fires once as long as I remain on the page but if I change tabs or from the browser and return to the page, the event will fire again.
Actually, I was not looking at the right data. I just realized you were sharing the request body from the events request. If you expand the attributes, you should see the url
for the pages visited. From what I can tell, it seems to batch all of the page visits for the current session, which seems to stop/start whenever the visibility of the page changes.
{
"BatchItem": {
"a3034460-2ddf-11ec-9477-573f85e38e88": {
"Endpoint": {},
"Events": {
"06c57502-2de4-11ec-b867-655c3a96ec30": {
"Attributes": {},
"EventType": "_session.start",
"Session": {
"Id": "06c57501-2de4-11ec-b867-655c3a96ec30",
"StartTimestamp": "2021-10-15T18:16:33.104Z"
},
"Timestamp": "2021-10-15T18:16:33.104Z"
},
"08230930-2de4-11ec-b867-655c3a96ec30": {
"Attributes": {
"url": "http://localhost:8080/",
"attr": "attr"
},
"EventType": "pageView",
"Session": {
"Id": "06c57501-2de4-11ec-b867-655c3a96ec30",
"StartTimestamp": "2021-10-15T18:16:33.104Z"
},
"Timestamp": "2021-10-15T18:16:35.395Z"
},
"08230931-2de4-11ec-b867-655c3a96ec30": {
"Attributes": {
"url": "http://localhost:8080/about",
"attr": "attr"
},
"EventType": "pageView",
"Session": {
"Id": "06c57501-2de4-11ec-b867-655c3a96ec30",
"StartTimestamp": "2021-10-15T18:16:33.104Z"
},
"Timestamp": "2021-10-15T18:16:35.395Z"
}
}
}
}
}
Session stop event is triggered when page isn't visible
{
"BatchItem": {
"a3034460-2ddf-11ec-9477-573f85e38e88": {
"Endpoint": {},
"Events": {
"dc712a00-2de4-11ec-aae9-170280f3291c": {
"Attributes": {},
"EventType": "_session.stop",
"Session": {
"Duration": 20491,
"Id": "d03a7c50-2de4-11ec-aae9-170280f3291c",
"StartTimestamp": "2021-10-15T18:22:11.093Z",
"StopTimestamp": "2021-10-15T18:22:31.584Z"
},
"Timestamp": "2021-10-15T18:22:31.584Z"
}
}
}
}
}
Closing this issue as it is expected behavior and not a bug.
Hi @chrisbonifacio
Yes I have followed the documentation, and we have turned off the 'session' events which are actually the page visibility events you have mentioned above. They are not triggered anymore, if you look at our config, we have them disabled. However even in a normal pageView, the event is batched multiple times.
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help
channels or Discussions for those types of questions.
Before opening, please confirm:
JavaScript Framework
Vue
Amplify APIs
Analytics
Amplify Categories
analytics
Environment information
Describe the bug
PageView autotrack is being added multiple times to the batch. This is causing ambiguity in our analysis as a single page is being identified as being visited multiple times in the same user session at the same timestamp.
Does anyone know how to stop this? My configuration syntax is:
In a batch with all the events on the same page, I can see pageView being recorded multiple times. Please check the attached screenshot. We send the route for the current page as well, which is how we identify that the event is being recorded multiple times.
Expected behavior
PageView unique for each page/route.
Reproduction steps
Visit the page, navigate to the next page in a website where this plugin is used.
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
Chrome, Edge
Mobile Browser Version
No response
Additional information and screenshots