mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-14 18:22:21 +00:00
fix(analytics): allow tracking static pages events when the user is not authenticated
This commit is contained in:
parent
103b4cb8a8
commit
6b3a6eb59f
2 changed files with 2 additions and 11 deletions
|
|
@ -1,19 +1,10 @@
|
|||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import { mockAnalyticsService as analytics } from '../../../../../website/server/libs/analyticsService';
|
||||
|
||||
describe('POST /analytics/track/:eventName', () => {
|
||||
it('requires authentication', async () => {
|
||||
await expect(requester().post('/analytics/track/event')).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('missingAuthHeaders'),
|
||||
});
|
||||
});
|
||||
|
||||
it('calls res.analytics', async () => {
|
||||
const user = await generateUser();
|
||||
sandbox.spy(analytics, 'track');
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ api.trackEvent = {
|
|||
method: 'POST',
|
||||
url: '/analytics/track/:eventName',
|
||||
// we authenticate these requests to make sure they actually came from a real user
|
||||
middlewares: [authWithHeaders()],
|
||||
middlewares: [authWithHeaders({ optional: true })],
|
||||
async handler (req, res) {
|
||||
// As of now only web can track events using this route
|
||||
if (req.headers['x-client'] !== 'habitica-web') {
|
||||
|
|
@ -30,7 +30,7 @@ api.trackEvent = {
|
|||
const eventProperties = req.body;
|
||||
|
||||
res.analytics.track(req.params.eventName, {
|
||||
uuid: user._id,
|
||||
uuid: user ? user._id : null,
|
||||
headers: req.headers,
|
||||
category: 'behaviour',
|
||||
gaLabel: 'local',
|
||||
|
|
|
|||
Loading…
Reference in a new issue