From f3d1a9fa79f6e98504f8b953d31ee9fde09e1a82 Mon Sep 17 00:00:00 2001 From: Tanner Heffner Date: Wed, 24 Jan 2024 12:15:37 -0800 Subject: [PATCH] VACMS-16501 gtm keys (#357) --- READMEs/analytics.md | 15 +++++++++++++++ envs/.env.example | 2 +- envs/.env.gha | 2 +- envs/.env.prod | 15 +++++++++++++++ envs/.env.staging | 17 +++++++++++++++++ envs/.env.tugboat | 2 +- src/lib/analytics/index.tsx | 2 +- src/pages/_document.tsx | 4 +--- 8 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 READMEs/analytics.md create mode 100644 envs/.env.prod create mode 100644 envs/.env.staging diff --git a/READMEs/analytics.md b/READMEs/analytics.md new file mode 100644 index 000000000..b3ebb3cf6 --- /dev/null +++ b/READMEs/analytics.md @@ -0,0 +1,15 @@ +Analytics in next-build: + +1. Google Tag Manager via [react-gtm-module](https://www.npmjs.com/package/react-gtm-module). See `src/pages/_app.tsx` + +Existing content-build analytics tags for reference: + +- [vagovdev](https://github.com/department-of-veterans-affairs/content-build/blob/main/src/site/assets/js/google-analytics/vagovdev.js) +- [vagovstaging](https://github.com/department-of-veterans-affairs/content-build/blob/main/src/site/assets/js/google-analytics/vagovstaging.js) +- [vagovprod](https://github.com/department-of-veterans-affairs/content-build/blob/main/src/site/assets/js/google-analytics/vagovprod.js) + +2. VA.gov participates in the US government’s analytics program. See the data at analytics.usa.gov. + +- https://github.com/digital-analytics-program/gov-wide-code + +3. Datadog integration coming soon diff --git a/envs/.env.example b/envs/.env.example index 7dfc67659..401e26c1e 100644 --- a/envs/.env.example +++ b/envs/.env.example @@ -20,7 +20,7 @@ REDIS_URL=redis://127.0.0.1:6379 # for local assets from vets-website NEXT_PUBLIC_ASSETS_URL=/generated/ -# google analytics (These are the dev environment credentials) +# Google Analytics (These are the dev environment credentials) NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=GTM-WFJWBD NEXT_PUBLIC_GOOGLE_TAG_MANAGER_AUTH=N9BisSDKAwJENFQtQIEvXQ NEXT_PUBLIC_GOOGLE_TAG_MANAGER_PREVIEW=env-423 diff --git a/envs/.env.gha b/envs/.env.gha index b4c5e5e75..f5dfc29d7 100644 --- a/envs/.env.gha +++ b/envs/.env.gha @@ -7,7 +7,7 @@ DRUPAL_PREVIEW_SECRET=secret DRUPAL_CLIENT_ID=Retrieve this from AWS SSM /cms/consumers/next-build/client_id DRUPAL_CLIENT_SECRET=Retrieve this from AWS SSM /cms/consumers/next-build/client_secret -# google analytics (These are the dev environment credentials) +# Google Analytics (These are the dev environment credentials) NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=GTM-WFJWBD NEXT_PUBLIC_GOOGLE_TAG_MANAGER_AUTH=N9BisSDKAwJENFQtQIEvXQ NEXT_PUBLIC_GOOGLE_TAG_MANAGER_PREVIEW=env-423 diff --git a/envs/.env.prod b/envs/.env.prod new file mode 100644 index 000000000..ba829ef56 --- /dev/null +++ b/envs/.env.prod @@ -0,0 +1,15 @@ +# This is the standard lower environment for Content API. +NEXT_PUBLIC_DRUPAL_BASE_URL=https://prod.cms.va.gov/ +NEXT_IMAGE_DOMAIN=https://prod.cms.va.gov/ + +NEXT_PUBLIC_ASSETS_URL=/generated/ + +# for Drupal preview +DRUPAL_PREVIEW_SECRET=secret +# store these securely in the build pipeline env +#DRUPAL_CLIENT_ID=Retrieve this from AWS SSM /cms/consumers/next-build/client_id +#DRUPAL_CLIENT_SECRET=Retrieve this from AWS SSM /cms/consumers/next-build/client_secret + +# Google Analytics +# These print directly to the page so do not need to store in SSM. +NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=GTM-WFJWBD diff --git a/envs/.env.staging b/envs/.env.staging new file mode 100644 index 000000000..9cda7a5a4 --- /dev/null +++ b/envs/.env.staging @@ -0,0 +1,17 @@ +# This is the standard lower environment for Content API. +NEXT_PUBLIC_DRUPAL_BASE_URL=https://staging.cms.va.gov/ +NEXT_IMAGE_DOMAIN=https://staging.cms.va.gov/ + +NEXT_PUBLIC_ASSETS_URL=/generated/ + +# for Drupal preview +DRUPAL_PREVIEW_SECRET=secret +# store these securely in the build pipeline env +#DRUPAL_CLIENT_ID=Retrieve this from AWS SSM /cms/consumers/next-build/client_id +#DRUPAL_CLIENT_SECRET=Retrieve this from AWS SSM /cms/consumers/next-build/client_secret + +# Google Analytics +# These print directly to the page so do not need to store in SSM. +NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=GTM-WFJWBD +NEXT_PUBLIC_GOOGLE_TAG_MANAGER_AUTH=inC4EKQce9vlWpRVcowiyQ +NEXT_PUBLIC_GOOGLE_TAG_MANAGER_PREVIEW=env-661 diff --git a/envs/.env.tugboat b/envs/.env.tugboat index e01269326..11b764182 100644 --- a/envs/.env.tugboat +++ b/envs/.env.tugboat @@ -10,7 +10,7 @@ REDIS_URL=redis://redis:6379 # Where to source vets-website assets from NEXT_PUBLIC_ASSETS_URL=/generated/ -# google analytics +# Google Analytics (These are the dev environment credentials) NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID=GTM-WFJWBD NEXT_PUBLIC_GOOGLE_TAG_MANAGER_AUTH=N9BisSDKAwJENFQtQIEvXQ NEXT_PUBLIC_GOOGLE_TAG_MANAGER_PREVIEW=env-423 diff --git a/src/lib/analytics/index.tsx b/src/lib/analytics/index.tsx index 46d285d24..b39b47f13 100644 --- a/src/lib/analytics/index.tsx +++ b/src/lib/analytics/index.tsx @@ -1,6 +1,6 @@ import TagManager from 'react-gtm-module' -export const GTM_ID = process.env.GOOGLE_TAG_MANAGER_ID +export const GTM_ID = process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID export const TAG_MANAGER_ARGS = { gtmId: process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID, auth: process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_AUTH, diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index 523dd7012..be76d86cf 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -3,9 +3,7 @@ import { GTM_ID } from '@/lib/analytics' import Script from 'next/script' const Document = () => { - const ASSETS_URL = - process.env.NEXT_PUBLIC_ASSETS_URL || - 'https://prod-va-gov-assets.s3-us-gov-west-1.amazonaws.com/generated/' + const ASSETS_URL = process.env.NEXT_PUBLIC_ASSETS_URL || '/generated/' return (