From 5b84f9d76373d58db17abce5136790bca10685fa Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 24 Oct 2023 17:21:32 -0700 Subject: [PATCH 1/5] Preparing to introduce GA4 alongside UA-... --- microsite/docs/docs/settings.md | 2 +- src/main/scala/microsites/MicrositeKeys.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/microsite/docs/docs/settings.md b/microsite/docs/docs/settings.md index 1a398a1a..aa1a02fc 100644 --- a/microsite/docs/docs/settings.md +++ b/microsite/docs/docs/settings.md @@ -124,7 +124,7 @@ micrositeGitHostingService := GitLab micrositeGitHostingUrl := "https://gitlab.com/gitlab-org/gitlab-ce" ``` -- `micrositeAnalyticsToken`: Property id of Google Analytics. This is empty by default. +- `micrositeAnalyticsToken`: Property id of Google's Universal Analytics token ("UA-...-1"). This is empty by default. ```scala micrositeAnalyticsToken := 'UA-XXXXX-Y' diff --git a/src/main/scala/microsites/MicrositeKeys.scala b/src/main/scala/microsites/MicrositeKeys.scala index 2f33caf8..25260c9a 100644 --- a/src/main/scala/microsites/MicrositeKeys.scala +++ b/src/main/scala/microsites/MicrositeKeys.scala @@ -185,7 +185,7 @@ trait MicrositeKeys { val micrositeAnalyticsToken: SettingKey[String] = settingKey[String]( - "Optional. Add your property id of Google Analytics to add a Google Analytics tracker" + "Optional. Add your legacy Universal Access (UA-...) property id of Google Analytics to add a Google Analytics tracker" ) val micrositeGitterChannel: SettingKey[Boolean] = settingKey[Boolean]( "Optional. Includes Gitter sidecar Chat functionality. Enabled by default." From 56d3b091adcef56acb5d8670028b67bda484fe60 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 24 Oct 2023 17:23:00 -0700 Subject: [PATCH 2/5] Making space in commonHead for tags around The advice from [Google's Migration Page](https://support.google.com/analytics/answer/13486733) states: To establish a connection between your website and Google Analytics, copy and paste the entire Google tag in the code of every page of your website, **immediately after** the element. and considering that **immediately after** is bold, I'm inclined to comply even though I strongly suspect it should not matter. --- src/main/scala/microsites/layouts/Layout.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/scala/microsites/layouts/Layout.scala b/src/main/scala/microsites/layouts/Layout.scala index fa734aaa..fc523dbe 100644 --- a/src/main/scala/microsites/layouts/Layout.scala +++ b/src/main/scala/microsites/layouts/Layout.scala @@ -54,13 +54,12 @@ abstract class Layout(config: MicrositeSettings) { def render: TypedTag[String] - def commonHead: TypedTag[String] = { - head( + def commonHead: List[TypedTag[String]] = + List(head( metas, favicons, styles - ) - } + )) val ganalytics: Option[TypedTag[String]] = if (config.identity.analytics.nonEmpty) From a2a806e3773635e7de3ee9c3182824a5d8c5f126 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 24 Oct 2023 17:26:04 -0700 Subject: [PATCH 3/5] Introducing micrositeGoogleAnalytics4Token and the corresponding config.identity.googleAnalytics4 --- microsite/docs/docs/settings.md | 6 ++++++ src/main/scala/microsites/MicrositeKeys.scala | 7 ++++++- src/main/scala/microsites/layouts/Layout.scala | 14 +++++++++++++- src/main/scala/microsites/microsites.scala | 3 ++- src/test/scala/microsites/util/Arbitraries.scala | 4 +++- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/microsite/docs/docs/settings.md b/microsite/docs/docs/settings.md index aa1a02fc..f367bd4e 100644 --- a/microsite/docs/docs/settings.md +++ b/microsite/docs/docs/settings.md @@ -130,6 +130,12 @@ micrositeGitHostingUrl := "https://gitlab.com/gitlab-org/gitlab-ce" micrositeAnalyticsToken := 'UA-XXXXX-Y' ``` +- `micrositeGoogleAnalytics4Token`: Property id of Google Analytics 4 (GA4). This is empty by default. + +```scala +micrositeGoogleAnalytics4Token := 'G-XXXXXXXXXX' +``` + - `micrositeGithubLinks`: This setting defines whether to show/hide GitHub links for stars and forks in docs layout. By default, it is enabled. ```scala diff --git a/src/main/scala/microsites/MicrositeKeys.scala b/src/main/scala/microsites/MicrositeKeys.scala index 25260c9a..5ad51f32 100644 --- a/src/main/scala/microsites/MicrositeKeys.scala +++ b/src/main/scala/microsites/MicrositeKeys.scala @@ -187,6 +187,10 @@ trait MicrositeKeys { settingKey[String]( "Optional. Add your legacy Universal Access (UA-...) property id of Google Analytics to add a Google Analytics tracker" ) + val micrositeGoogleAnalytics4Token: SettingKey[String] = + settingKey[String]( + "Optional. Add your Google Analytics 4 (GA4, G-...) property id of Google Analytics to add a Google Analytics tracker" + ) val micrositeGitterChannel: SettingKey[Boolean] = settingKey[Boolean]( "Optional. Includes Gitter sidecar Chat functionality. Enabled by default." ) @@ -338,7 +342,8 @@ trait MicrositeAutoImportSettings extends MicrositeKeys { organizationHomepage = micrositeOrganizationHomepage.value, twitter = micrositeTwitter.value, twitterCreator = micrositeTwitterCreator.value, - analytics = micrositeAnalyticsToken.value + analytics = micrositeAnalyticsToken.value, + googleAnalytics4 = micrositeGoogleAnalytics4Token.value ), visualSettings = MicrositeVisualSettings( highlightTheme = micrositeHighlightTheme.value, diff --git a/src/main/scala/microsites/layouts/Layout.scala b/src/main/scala/microsites/layouts/Layout.scala index fc523dbe..c65fd3ab 100644 --- a/src/main/scala/microsites/layouts/Layout.scala +++ b/src/main/scala/microsites/layouts/Layout.scala @@ -59,7 +59,7 @@ abstract class Layout(config: MicrositeSettings) { metas, favicons, styles - )) + )) ++ ganalytics4 val ganalytics: Option[TypedTag[String]] = if (config.identity.analytics.nonEmpty) @@ -206,6 +206,18 @@ abstract class Layout(config: MicrositeSettings) { cssStyles ++ customCssList ++ customScssList ++ customCDNList ++ ganalytics.toList } + val ganalytics4: List[TypedTag[String]] = + if (config.identity.googleAnalytics4.nonEmpty) + List( + script(attr("async") := "async", attr("src") := s"https://www.googletagmanager.com/gtag/js?id=${config.identity.googleAnalytics4}"), + script(s""" + |window.dataLayer = window.dataLayer || []; + |function gtag(){dataLayer.push(arguments);} + |gtag('js', new Date()); + |gtag('config', '${config.identity.googleAnalytics4}'); + """.stripMargin)) + else Nil + def scripts: List[TypedTag[String]] = { val customJsList = diff --git a/src/main/scala/microsites/microsites.scala b/src/main/scala/microsites/microsites.scala index 6cfd5aad..32252d54 100644 --- a/src/main/scala/microsites/microsites.scala +++ b/src/main/scala/microsites/microsites.scala @@ -26,7 +26,8 @@ case class MicrositeIdentitySettings( organizationHomepage: String, twitter: String, twitterCreator: String, - analytics: String + analytics: String, + googleAnalytics4: String, ) case class MicrositeFileLocations( diff --git a/src/test/scala/microsites/util/Arbitraries.scala b/src/test/scala/microsites/util/Arbitraries.scala index e8abc039..d2473094 100644 --- a/src/test/scala/microsites/util/Arbitraries.scala +++ b/src/test/scala/microsites/util/Arbitraries.scala @@ -122,6 +122,7 @@ trait Arbitraries { twitter <- Arbitrary.arbitrary[String] twitterCreator <- Arbitrary.arbitrary[String] analytics <- Arbitrary.arbitrary[String] + googleAnalytics4 <- Arbitrary.arbitrary[String] highlightTheme <- Arbitrary.arbitrary[String] highlightLanguages <- Arbitrary.arbitrary[Seq[String]] theme <- Arbitrary.arbitrary[String] @@ -166,7 +167,8 @@ trait Arbitraries { organizationHomepage, twitter, twitterCreator, - analytics + analytics, + googleAnalytics4 ), MicrositeVisualSettings( highlightTheme, From c067cc3fa61fe1f068b95fb5410726f3217e6350 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 24 Oct 2023 23:48:58 -0700 Subject: [PATCH 4/5] Adding default GA4 token --- .../scala/microsites/MicrositesPlugin.scala | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/scala/microsites/MicrositesPlugin.scala b/src/main/scala/microsites/MicrositesPlugin.scala index 2b69314b..1d3e5fb4 100644 --- a/src/main/scala/microsites/MicrositesPlugin.scala +++ b/src/main/scala/microsites/MicrositesPlugin.scala @@ -108,22 +108,23 @@ object MicrositesPlugin extends AutoPlugin { "white-color" -> "#FFFFFF" ) }, - micrositeFavicons := Seq(), - micrositeVersionList := Seq(), - micrositeGithubOwner := gitRemoteInfo._1, - micrositeGithubRepo := gitRemoteInfo._2, - micrositeGithubToken := None, - micrositeGitHostingService := GitHub, - micrositeGitHostingUrl := "", - micrositePushSiteWith := GHPagesPlugin, - micrositeAnalyticsToken := "", - micrositeGitterChannel := true, - micrositeGitterChannelUrl := s"${micrositeGithubOwner.value}/${micrositeGithubRepo.value}", - micrositeFooterText := Some(layouts.Layout.footer.toString), - micrositeEditButton := None, - micrositeGithubLinks := true, - micrositeSearchEnabled := true, - micrositeHomeButtonTarget := "repo", + micrositeFavicons := Seq(), + micrositeVersionList := Seq(), + micrositeGithubOwner := gitRemoteInfo._1, + micrositeGithubRepo := gitRemoteInfo._2, + micrositeGithubToken := None, + micrositeGitHostingService := GitHub, + micrositeGitHostingUrl := "", + micrositePushSiteWith := GHPagesPlugin, + micrositeAnalyticsToken := "", + micrositeGoogleAnalytics4Token := "", + micrositeGitterChannel := true, + micrositeGitterChannelUrl := s"${micrositeGithubOwner.value}/${micrositeGithubRepo.value}", + micrositeFooterText := Some(layouts.Layout.footer.toString), + micrositeEditButton := None, + micrositeGithubLinks := true, + micrositeSearchEnabled := true, + micrositeHomeButtonTarget := "repo", makeSite / includeFilter := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.jpeg" | "*.gif" | "*.js" | "*.swf" | "*.md" | "*.webm" | "*.ico" | "CNAME" | "*.yml" | "*.svg" | "*.json", Jekyll / includeFilter := (makeSite / includeFilter).value || "LICENSE", commands ++= Seq(publishMicrositeCommand), From 559dffc06cf9668a60e77b0210c81874a8246598 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 8 Nov 2023 05:26:53 -0800 Subject: [PATCH 5/5] Formatting --- .../scala/microsites/layouts/Layout.scala | 22 +++++++++++++------ src/main/scala/microsites/microsites.scala | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/scala/microsites/layouts/Layout.scala b/src/main/scala/microsites/layouts/Layout.scala index c65fd3ab..98dbea1f 100644 --- a/src/main/scala/microsites/layouts/Layout.scala +++ b/src/main/scala/microsites/layouts/Layout.scala @@ -55,11 +55,13 @@ abstract class Layout(config: MicrositeSettings) { def render: TypedTag[String] def commonHead: List[TypedTag[String]] = - List(head( - metas, - favicons, - styles - )) ++ ganalytics4 + List( + head( + metas, + favicons, + styles + ) + ) ++ ganalytics4 val ganalytics: Option[TypedTag[String]] = if (config.identity.analytics.nonEmpty) @@ -209,13 +211,19 @@ abstract class Layout(config: MicrositeSettings) { val ganalytics4: List[TypedTag[String]] = if (config.identity.googleAnalytics4.nonEmpty) List( - script(attr("async") := "async", attr("src") := s"https://www.googletagmanager.com/gtag/js?id=${config.identity.googleAnalytics4}"), + script( + attr("async") := "async", + attr( + "src" + ) := s"https://www.googletagmanager.com/gtag/js?id=${config.identity.googleAnalytics4}" + ), script(s""" |window.dataLayer = window.dataLayer || []; |function gtag(){dataLayer.push(arguments);} |gtag('js', new Date()); |gtag('config', '${config.identity.googleAnalytics4}'); - """.stripMargin)) + """.stripMargin) + ) else Nil def scripts: List[TypedTag[String]] = { diff --git a/src/main/scala/microsites/microsites.scala b/src/main/scala/microsites/microsites.scala index 32252d54..c5fdc28c 100644 --- a/src/main/scala/microsites/microsites.scala +++ b/src/main/scala/microsites/microsites.scala @@ -27,7 +27,7 @@ case class MicrositeIdentitySettings( twitter: String, twitterCreator: String, analytics: String, - googleAnalytics4: String, + googleAnalytics4: String ) case class MicrositeFileLocations(