Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push a new search AI dataLayer variable on the Search page to GTM #342

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ga/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface DataLayer {
adminset?: string;
collections?: string | null;
creatorsContributors?: Array<string> | string;
isUsingAI?: boolean;
isLoggedIn?: boolean;
pageTitle: string;
rightsStatement?: string | null;
Expand All @@ -15,6 +16,7 @@ const defaultDataLayer = {
adminset: "",
collections: "",
creatorsContributors: "",
isUsingAI: false,
isLoggedIn: false,
pageTitle: "",
rightsStatement: "",
Expand Down
10 changes: 7 additions & 3 deletions pages/search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Tabs from "@radix-ui/react-tabs";

import { GetServerSideProps, NextPage } from "next";
import {
NoResultsMessage,
ResultsMessage,
Expand All @@ -21,7 +22,6 @@ import Heading from "@/components/Heading/Heading";
import Icon from "@/components/Shared/Icon";
import { IconSparkles } from "@/components/Shared/SVG/Icons";
import Layout from "@/components/layout";
import { NextPage } from "next";
import { PRODUCTION_URL } from "@/lib/constants/endpoints";
import PaginationAltCounts from "@/components/Search/PaginationAltCounts";
import SearchOptions from "@/components/Search/Options";
Expand Down Expand Up @@ -280,8 +280,12 @@ const SearchPage: NextPage = () => {
);
};

export async function getStaticProps() {
export const getServerSideProps: GetServerSideProps = async (context) => {
const { query } = context;
const isUsingAI = query?.ai === "true";

const dataLayer = buildDataLayer({
isUsingAI,
pageTitle: "Search page",
});

Expand All @@ -293,6 +297,6 @@ export async function getStaticProps() {
return {
props: { dataLayer, openGraphData },
};
}
};

export default SearchPage;