-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-config.ts
150 lines (145 loc) · 4.78 KB
/
gatsby-config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import type { GatsbyConfig } from "gatsby";
import netlifyAdapter from "gatsby-adapter-netlify";
import { ExperienceConfiguration } from "@ninetailed/experience.js-gatsby";
import type { NinetailedInstance } from "@ninetailed/experience.js";
import {
audienceQuery,
audienceMapper,
experienceQuery,
experienceMapper,
} from "./lib/preview";
require("dotenv").config();
const config: GatsbyConfig = {
adapter: netlifyAdapter(),
siteMetadata: {
title: `marketing-contentful-gatsby`,
siteUrl: `https://www.yourdomain.tld`,
},
// More easily incorporate content into your pages through automatic TypeScript type generation and better GraphQL IntelliSense.
// If you use VSCode you can also use the GraphQL plugin
// Learn more at: https://gatsby.dev/graphql-typegen
graphqlTypegen: true,
plugins: [
{
resolve: "gatsby-source-contentful",
options: {
accessToken: process.env.CONTENTFUL_PREVIEW
? process.env.CONTENTFUL_CPA_KEY
: process.env.CONTENTFUL_CDA_KEY,
spaceId: process.env.GATSBY_CONTENTFUL_SPACE,
environment: process.env.GATSBY_CONTENTFUL_ENVIRONMENT,
host: process.env.CONTENTFUL_PREVIEW
? "preview.contentful.com"
: "cdn.contentful.com",
},
},
{
resolve: "gatsby-plugin-google-tagmanager",
options: {
id: process.env.GATSBY_GTM_ID,
includeInDevelopment: true,
},
},
{
resolve: "@ninetailed/experience.js-gatsby",
options: {
clientId: process.env.NINETAILED_CLIENT_ID,
environment: process.env.NINETAILED_ENV || "main",
onInitProfileId: async (profileId?: string) => {
if (profileId) {
return profileId;
}
const cookieObject = document.cookie
.split(";")
.map((v) => v.split("="))
.reduce<Record<string, string>>((acc, v) => {
acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(
v[1].trim()
);
return acc;
}, {});
return cookieObject["_ga"];
},
onRouteChange: (
{ isInitialRoute, url }: { isInitialRoute: boolean; url: string },
ninetailed: NinetailedInstance
) => {
if (isInitialRoute) {
const params = new URL(url).searchParams;
const experienceId = params.get("experienceId");
const variantIndex = parseInt(params.get("variantIndex") || "", 10);
if (experienceId && variantIndex) {
ninetailed.batch([
ninetailed.eventBuilder.component(
"componentId",
experienceId,
variantIndex
),
ninetailed.eventBuilder.page(),
]);
} else {
ninetailed.page();
}
} else {
ninetailed.page();
}
},
ninetailedPlugins: [
// {
// resolve: `@ninetailed/experience.js-plugin-preview`,
// name: "@ninetailed/experience.js-plugin-preview",
// options: {
// customOptions: {
// audienceQuery,
// experienceQuery,
// audienceMapper,
// experienceMapper,
// },
// // Callback to handle user forwarding to the experience entry
// // in your CMS - optional
// onOpenExperienceEditor: (experience: ExperienceConfiguration) => {
// // TODO: For now, hard code your space ID and environment ID rather than trying to pull them from .env variables
// window.open(
// `https://app.contentful.com/spaces/[YOUR_CONETNTFUL_SPACE_ID]/environments/[YOUR_CONTENTFUL_ENVIRONMENT_ID]/entries/${experience.id}`,
// "_blank"
// );
// },
// },
// },
{
resolve: `@ninetailed/experience.js-plugin-google-tagmanager`,
name: "@ninetailed/experience.js-plugin-google-tagmanager",
options: {
template: {
ninetailed_audience_name: "{{ audience.name }}",
},
},
},
{
resolve: `@ninetailed/experience.js-plugin-insights`,
options: {},
},
],
},
},
"gatsby-plugin-image",
"gatsby-plugin-sharp",
"gatsby-transformer-sharp",
"gatsby-plugin-sitemap",
{
resolve: "gatsby-source-filesystem",
options: {
name: "images",
path: "./src/images/",
},
__key: "images",
},
{
resolve: "gatsby-plugin-manifest",
options: {
icon: "src/images/icon.png",
},
},
],
};
export default config;