Skip to content

Commit b528386

Browse files
committed
Implement incrementGateDisplayCount
1 parent 793f3a3 commit b528386

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

dotcom-rendering/src/components/SignInGateSelector.importable.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCookie, isUndefined } from '@guardian/libs';
1+
import { getCookie, isUndefined, storage } from '@guardian/libs';
22
import { useState } from 'react';
33
import {
44
hasCmpConsentForBrowserId,
@@ -376,7 +376,15 @@ const decideShowDefaultGate = (): ShowGateValues => {
376376

377377
const getGateDisplayCount = (): number => {
378378
// TODO: retrieve the number of time the page has been displayed
379-
return 0;
379+
const count = storage.local.get('gate_display_count') as number;
380+
return count;
381+
};
382+
383+
const incrementGateDisplayCount = () => {
384+
const count = getGateDisplayCount();
385+
const now = new Date();
386+
const oneYearFromNow = new Date(now.getTime() + 365 * 86400);
387+
storage.local.set('gate_display_count', count + 1, oneYearFromNow);
380388
};
381389

382390
const buildAuxiaGateDisplayData = async (
@@ -732,6 +740,10 @@ const ShowSignInGateAuxia = ({
732740
},
733741
renderingTarget,
734742
);
743+
744+
// Once the gate is being displayed we need to update
745+
// the tracking of the number of times the gate has been displayed
746+
incrementGateDisplayCount();
735747
}, [componentId]);
736748

737749
return (

0 commit comments

Comments
 (0)