Skip to content

Commit ada03d6

Browse files
committed
Merge branch 'main' into contact-step-page
2 parents c9bf753 + 17c958b commit ada03d6

File tree

9 files changed

+84
-17
lines changed

9 files changed

+84
-17
lines changed

packages/nextjs/src/components/_common/areaCard/AreaCard.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { LinkPanel } from '@navikt/ds-react';
33
import { EditorHelp } from 'components/_editor-only/editor-help/EditorHelp';
44
import { classNames } from 'utils/classnames';
5+
import { useLayoutConfig } from 'components/layouts/useLayoutConfig';
56
import { LenkeBase } from 'components/_common/lenke/lenkeBase/LenkeBase';
67
import { AreaCardGraphics } from './graphics/AreaCardGraphics';
78

@@ -17,6 +18,9 @@ type Props = {
1718
} & Omit<React.ComponentProps<typeof LinkPanel>, 'as'>;
1819

1920
export const AreaCard = ({ path, title, area, linkGroup, className, ...rest }: Props) => {
21+
const { layoutConfig } = useLayoutConfig();
22+
const analyticsLinkGroup= linkGroup ?? layoutConfig.title;
23+
2024
if (!area) {
2125
return <EditorHelp text={'Velg en grafikk for kortet'} />;
2226
}
@@ -28,7 +32,7 @@ export const AreaCard = ({ path, title, area, linkGroup, className, ...rest }: P
2832
href={path}
2933
analyticsLabel={title}
3034
analyticsComponent={'Områdekort'}
31-
analyticsLinkGroup={linkGroup}
35+
analyticsLinkGroup={analyticsLinkGroup}
3236
className={classNames(style.linkPanel, graphicsStyle.expandOnHover, className)}
3337
as={LenkeBase}
3438
>

packages/nextjs/src/components/_common/moreLink/MoreLink.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@ import { LenkeStandalone } from 'components/_common/lenke/lenkeStandalone/LenkeS
55

66
import styles from './MoreLink.module.scss';
77

8-
export const MoreLink = ({ link }: { link?: LinkSelectable }) => {
9-
if (!link) {
8+
type Props = {
9+
link: LinkSelectable;
10+
analyticsGroup?: string;
11+
};
12+
13+
export const MoreLink = ( props: Props) => {
14+
if (!props.link) {
1015
return null;
1116
}
1217

13-
const { text, url } = getSelectableLinkProps(link);
18+
const { text, url } = getSelectableLinkProps(props.link);
1419

1520
return (
16-
<LenkeStandalone href={url} className={styles.moreLink} withChevron={false}>
21+
<LenkeStandalone
22+
href={url}
23+
linkGroup={props.analyticsGroup}
24+
className={styles.moreLink}
25+
withChevron={false}
26+
>
1727
<ArrowRightIcon aria-hidden={true} className={styles.arrow} />
1828
{text}
1929
</LenkeStandalone>

packages/nextjs/src/components/_common/uxsignalsWidget/UxSignalsWidget.tsx

+54-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,70 @@
11
import React, { useEffect } from 'react';
2+
import { getCurrentConsent } from '@navikt/nav-dekoratoren-moduler';
23
import { EditorHelp } from 'components/_editor-only/editor-help/EditorHelp';
34

45
import style from './UxSignalsWidget.module.scss';
56

6-
type Props = {
7+
type UxSignalsWidgetProps = {
78
embedCode: string;
89
};
910

10-
export const UxSignalsWidget = ({ embedCode }: Props) => {
11-
useEffect(() => {
11+
type Consent = {
12+
consent: {
13+
analytics: boolean;
14+
surveys: boolean;
15+
};
16+
userActionTaken: boolean;
17+
};
18+
19+
const uxSignalsScriptUrl = 'https://widget.uxsignals.com/embed.js';
20+
let scriptAddTimeout: ReturnType<typeof setTimeout>;
21+
22+
export const UxSignalsWidget = ({ embedCode }: UxSignalsWidgetProps) => {
23+
// If the cookie banner is visible, the user has not taken any action yet.
24+
// Wait and see if the user takes action before adding the script if consent is given..
25+
const checkConsentOrWait = (tries: number = 0) => {
26+
const { consent, userActionTaken }: Consent = getCurrentConsent();
27+
if (consent.surveys && consent.analytics) {
28+
addUXSignalsScript();
29+
return;
30+
}
31+
// Wait max 60 seconds for user respond to the cookie banner
32+
// (userActionTaken) or give up.
33+
if (!userActionTaken && tries < 60) {
34+
scriptAddTimeout = setTimeout(() => {
35+
checkConsentOrWait(tries + 1);
36+
}, 1000);
37+
}
38+
};
39+
40+
const addUXSignalsScript = () => {
41+
if (document.querySelector(`script[src="${uxSignalsScriptUrl}"]`)) {
42+
return;
43+
}
44+
1245
const script = document.createElement('script');
13-
script.src = 'https://widget.uxsignals.com/embed.js';
46+
script.src = uxSignalsScriptUrl;
1447
script.async = true;
1548
document.body.appendChild(script);
16-
return () => {
49+
};
50+
51+
const removeUXSignalsScript = () => {
52+
const script = document.querySelector(`script[src="${uxSignalsScriptUrl}"]`);
53+
if (script) {
1754
document.body.removeChild(script);
55+
}
56+
};
57+
58+
useEffect(() => {
59+
checkConsentOrWait();
60+
return () => {
61+
if (scriptAddTimeout) {
62+
clearTimeout(scriptAddTimeout);
63+
}
64+
removeUXSignalsScript();
1865
};
19-
});
66+
/* eslint-disable-next-line react-hooks/exhaustive-deps */
67+
}, []);
2068

2169
return (
2270
<>

packages/nextjs/src/components/layouts/LayoutContainer.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export const LayoutContainer = ({
2020
layoutProps,
2121
layoutStyle,
2222
children,
23+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
24+
pageProps,
2325
...divElementProps
2426
}: Props) => {
2527
const { editorView } = usePageContentProps();

packages/nextjs/src/components/layouts/frontpage-loggedin-section/FrontpageLoggedinSectionLayout.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export const FrontpageLoggedinSectionLayout = ({ layoutProps, pageProps }: Props
4343
}
4444

4545
const { header, mypage } = config;
46+
const title = yourServicesText('yourServices');
47+
layoutProps.config.title = title; //for at kortene i region skal kunne plukke opp title til analytics
4648

4749
return (
4850
<AuthDependantRender renderOn={'loggedIn'}>
@@ -53,11 +55,11 @@ export const FrontpageLoggedinSectionLayout = ({ layoutProps, pageProps }: Props
5355
data-hj-suppress
5456
>
5557
<HeaderWithName headerText={header} />
56-
<Header level={'2'} size={'small'} className={style.services}>
57-
{yourServicesText('yourServices')}
58+
<Header level="3" size="small" className={style.services}>
59+
{title}
5860
</Header>
5961
<Region pageProps={pageProps} regionProps={regions.cards} className={style.cards} />
60-
<MoreLink link={mypage?.link} />
62+
<MoreLink analyticsGroup={title} link={mypage?.link} />
6163
</LayoutContainer>
6264
</AuthDependantRender>
6365
);

packages/nextjs/src/components/parts/frontpage-current-topics/FrontpageCurrentTopicsPart.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const FrontpageCurrentTopicsPart = ({
8282
);
8383
})}
8484
</ul>
85-
{link && <MoreLink link={link} />}
85+
{link && <MoreLink analyticsGroup={title} link={link} />}
8686
</div>
8787
);
8888
};

packages/nextjs/src/components/parts/frontpage-person-shortcuts/FrontpagePersonShortcutsPart.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const FrontpagePersonShortcutsPart = ({
6161
href={href}
6262
className={style.linkPanel}
6363
analyticsComponent="Lenkepanel navno enkel"
64-
analyticsLinkGroup={title}
64+
analyticsLinkGroup={sectionTitle}
6565
>
6666
<div className={style.icon}>
6767
{

packages/nextjs/src/components/parts/frontpage-shortcuts/FrontpageShortcutsPart.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const FrontpageShortcutsPart = ({
7979
<li key={title}>
8080
<LinkPanelNavnoSimple
8181
href={href}
82-
analyticsLinkGroup={title}
82+
analyticsLinkGroup={sectionTitle}
8383
icon={<IllustrationStatic illustration={illustration} />}
8484
className={classNames(
8585
style.item,

packages/nextjs/src/types/component-props/layouts/frontpage-loggedin-section.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface FrontpageLoggedinSectionLayoutProps extends LayoutBaseProps {
88
regions: Regions<'cards'>;
99
config: {
1010
header: string;
11+
title: string;
1112
mypage: {
1213
link: LinkSelectable;
1314
};

0 commit comments

Comments
 (0)