Skip to content

Commit

Permalink
Only send fylke and rolle
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Jan 16, 2025
1 parent 3c76d82 commit 640ccdd
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/containers/AboutPage/AboutPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const AboutPageContent = ({ article: _article, frontpage }: Props) => {

useEffect(() => {
if (_article && authContextLoaded) {
const dimensions = getAllDimensions({ article: _article, user });
const dimensions = getAllDimensions({ user });
trackPageView({ dimensions, title: getDocumentTitle(t, _article.title) });
}
}, [_article, authContextLoaded, t, trackPageView, user]);
Expand Down
6 changes: 1 addition & 5 deletions src/containers/ArticlePage/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ const ArticlePage = ({ resource, errors, skipToContentId, loading }: Props) => {

useEffect(() => {
if (!loading && authContextLoaded) {
const dimensions = getAllDimensions({
article: resource?.article,
filter: root?.name,
user,
});
const dimensions = getAllDimensions({ user });
trackPageView({
dimensions,
title: getDocumentTitle(t, resource, root),
Expand Down
2 changes: 1 addition & 1 deletion src/containers/CollectionPage/CollectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const CollectionPageContent = ({ collectionLanguage, subjects }: CollectionpageC
dimensions,
title: pageTitle,
});
}, [authContextLoaded, pageTitle, t, trackPageView, user]);
}, [authContextLoaded, pageTitle, trackPageView, user]);

return (
<StyledPageContainer padding="large" asChild consumeCss>
Expand Down
12 changes: 1 addition & 11 deletions src/containers/LearningpathPage/LearningpathPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,7 @@ const LearningpathPage = ({ data, skipToContentId, stepId, loading }: Props) =>

useEffect(() => {
if (loading || !data || !authContextLoaded) return;
const { node } = data;
const learningpath = node?.learningpath;
const firstStep = learningpath?.learningsteps?.[0];
const currentStep = learningpath?.learningsteps?.find((ls) => `${ls.id}` === stepId);
const learningstep = currentStep || firstStep;
const dimensions = getAllDimensions({
learningpath,
learningstep,
filter: node?.context?.parents?.[0]?.name,
user,
});
const dimensions = getAllDimensions({ user });
trackPageView({ dimensions, title: getDocumentTitle(t, data, stepId) });
}, [authContextLoaded, data, loading, stepId, t, trackPageView, user]);

Expand Down
2 changes: 1 addition & 1 deletion src/containers/PlainArticlePage/PlainArticleContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const PlainArticleContainer = ({ article: propArticle, skipToContentId }: Props)

useEffect(() => {
if (!propArticle || !authContextLoaded) return;
const dimensions = getAllDimensions({ article: propArticle, user });
const dimensions = getAllDimensions({ user });
trackPageView({
dimensions,
title: getDocumentTitle(t, propArticle.title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ const PlainLearningpathContainer = ({ learningpath, skipToContentId, stepId }: P

useEffect(() => {
if (learningpath && authContextLoaded) {
const learningstep = stepId
? learningpath.learningsteps?.find((step) => `${step.id}` === stepId)
: learningpath.learningsteps?.[0];
const dimensions = getAllDimensions({ learningpath, user, learningstep });
const dimensions = getAllDimensions({ user });
trackPageView({ dimensions, title: getDocumentTitle(learningpath, t) });
}
}, [authContextLoaded, learningpath, stepId, t, trackPageView, user]);
Expand Down
5 changes: 1 addition & 4 deletions src/containers/SubjectPage/SubjectContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ const SubjectContainer = ({ node, subjectType, loading }: Props) => {

useEffect(() => {
if (!authContextLoaded || loading) return;
const dimensions = getAllDimensions({
filter: node.name,
user,
});
const dimensions = getAllDimensions({ user });
trackPageView({
dimensions,
title: htmlTitle(node.name, [t("htmlTitles.titleTemplate")]),
Expand Down
8 changes: 2 additions & 6 deletions src/containers/TopicPage/MultidisciplinarySubjectArticle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,12 @@ const MultidisciplinarySubjectArticle = ({ node }: Props) => {

useEffect(() => {
if (!node?.article || !authContextLoaded) return;
const dimensions = getAllDimensions({
article: node.article,
filter: root?.name,
user,
});
const dimensions = getAllDimensions({ user });
trackPageView({
dimensions,
title: pageTitle,
});
}, [authContextLoaded, root, t, node.article, node.url, trackPageView, user, pageTitle]);
}, [authContextLoaded, node.article, trackPageView, user, pageTitle]);

const breadCrumbs = useMemo(() => {
return toBreadcrumbItems(t("breadcrumb.toFrontpage"), [...crumbs, node]);
Expand Down
8 changes: 2 additions & 6 deletions src/containers/TopicPage/TopicContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,10 @@ export const TopicContainer = ({ node, subjectType }: TopicContainerProps) => {

useEffect(() => {
if (authContextLoaded && node.article) {
const dimensions = getAllDimensions({
article: node.article,
filter: node.breadcrumbs[0],
user,
});
const dimensions = getAllDimensions({ user });
trackPageView({ dimensions, title: pageTitle });
}
}, [authContextLoaded, node.article, node.breadcrumbs, pageTitle, trackPageView, user]);
}, [authContextLoaded, node.article, pageTitle, trackPageView, user]);

const breadcrumbs = useMemo(() => {
if (!node.context) return [];
Expand Down
3 changes: 0 additions & 3 deletions src/iframe/IframeArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { LocaleType } from "../interfaces";
import { getArticleScripts } from "../util/getArticleScripts";
import { getContentType } from "../util/getContentType";
import getStructuredDataFromArticle, { structuredArticleDataFragment } from "../util/getStructuredDataFromArticle";
import { getAllDimensions } from "../util/trackingUtil";
import { transformArticle } from "../util/transformArticle";

interface Props {
Expand Down Expand Up @@ -62,9 +61,7 @@ const IframeArticlePage = ({ node, article: propArticle, locale: localeProp }: P

useEffect(() => {
if (propArticle?.id) return;
const dimensions = getAllDimensions({ article: propArticle });
trackPageView({
dimensions,
title: getDocumentTitle({ article: propArticle }),
});
}, [propArticle, node, trackPageView]);
Expand Down
56 changes: 9 additions & 47 deletions src/util/trackingUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,22 @@
*
*/

import { GQLArticle, GQLLearningpathStep, GQLMyNdlaPersonalDataFragmentFragment } from "../graphqlTypes";
import { GQLMyNdlaPersonalDataFragmentFragment } from "../graphqlTypes";

type DimensionKeys = "10" | "13" | "14" | "16" | "17" | "18" | "19" | "20";
type DimensionType = Record<DimensionKeys, string | number | undefined>;

export const getDimensionsCodes = {
"10": "CustDimKjerneelement",
"13": "CustDimStiLengde",
"14": "CustDimStiSteg",
"16": "CustDimFylke",
"17": "CustDimSkule",
"18": "CustDimRolle",
"19": "CustDimFilter",
"20": "CustDimKompetansemaal",
};

export const convertToGaOrGtmDimension = (dimensions: DimensionType): Record<string | number, any> => {
return Object.keys(dimensions).reduce((prev, curr) => {
const key = curr as DimensionKeys;
return {
...prev,
[getDimensionsCodes[key]]: dimensions[key],
};
}, {});
};

const getGrepCodeOfType = (pattern: string, grepCodes?: string[]) =>
grepCodes?.filter((code) => code?.startsWith(pattern))?.join("|") || undefined;

type RequiredLearningpath = {
learningsteps?: any[];
};
type DimensionType = Record<string, string | number | undefined>;

interface Props {
article?: Pick<GQLArticle, "grepCodes">;
learningpath?: RequiredLearningpath;
learningstep?: Pick<GQLLearningpathStep, "seqNo">;
filter?: string;
user?: GQLMyNdlaPersonalDataFragmentFragment;
}

export const getAllDimensions = ({ article, learningpath, learningstep, filter, user }: Props) => {
export const getAllDimensions = ({ user }: Props) => {
if (!user) {
return {};
}
const dimensions: DimensionType = {
"10": getGrepCodeOfType("KE", article?.grepCodes),
"13": learningpath?.learningsteps?.length,
"14": learningstep ? learningstep.seqNo + 1 : undefined,
"16": user?.organization,
// This is disabled for now.
// "17": user?.groups.find((g) => g.isPrimarySchool)?.displayName,
"17": undefined,
"18": user?.role,
"19": filter,
"20": getGrepCodeOfType("KM", article?.grepCodes),
CustDimFylke: user?.organization,
CustDimRolle: user?.role,
};

return convertToGaOrGtmDimension(dimensions);
return dimensions;
};

0 comments on commit 640ccdd

Please sign in to comment.