store pageview and visit in database
@vishalsim9598 @wasim.memon0007
The sendBeacon() request now arrives in the controller. The problem was simply a wrong URL. The request went to api/pageview. But it must be sent to api/pageviews.
Currently the controller returns a status 200 OK. But no record is created.
And this is how it should work:
If the pageview does not exist yet, it should be created. Otherwise the fields "Duration", "Reload" and "visibilityChange" should be updated.
If the visit does not exist, then it should be created. Otherwise the visit should be updated.
If the visitor does not exist, then it should be created. Otherwise the visitor should be updated.
who has time to do this?
Output of console.log()
[2022-07-14 20:49:15.718] http: POST /api/pageviews (10 ms) 200
{
request: {
method: 'POST',
url: '/api/pageviews',
header: {
host: '10.10.1.81:1339',
connection: 'keep-alive',
'content-length': '524',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
'content-type': 'text/plain;charset=UTF-8',
accept: '*/*',
origin: 'http://10.10.1.8',
referer: 'http://10.10.1.8/',
'accept-encoding': 'gzip, deflate',
'accept-language': 'de-DE,de;q=0.9,en;q=0.8',
dnt: '1',
'sec-gpc': '1'
}
},
response: {
status: 404,
message: 'Not Found',
header: [Object: null prototype] {
'content-security-policy': "connect-src 'self' https:;img-src 'self' data: blob: https://dl.airtable.com;media-src 'self' data: blob:;default-src 'self';base-uri 'self';block-all-mixed-content;font-src 'self' https: data:;frame-ancestors 'self';object-src 'none';script-src 'self';script-src-attr 'none';style-src 'self' https: 'unsafe-inline'",
'x-dns-prefetch-control': 'off',
'expect-ct': 'max-age=0',
'x-frame-options': 'SAMEORIGIN',
'strict-transport-security': 'max-age=31536000; includeSubDomains',
'x-download-options': 'noopen',
'x-content-type-options': 'nosniff',
'x-permitted-cross-domain-policies': 'none',
'referrer-policy': 'no-referrer',
vary: 'Origin',
'access-control-allow-origin': '*',
'access-control-allow-credentials': 'true'
}
},
app: { subdomainOffset: 2, proxy: false, env: 'development' },
originalUrl: '/api/pageviews',
req: '<original node req>',
res: '<original node res>',
socket: '<original node socket>'
}