diff --git a/microsite/docs/docs/settings.md b/microsite/docs/docs/settings.md index 1a398a1a..f367bd4e 100644 --- a/microsite/docs/docs/settings.md +++ b/microsite/docs/docs/settings.md @@ -124,12 +124,18 @@ 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' ``` +- `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 2f33caf8..5ad51f32 100644 --- a/src/main/scala/microsites/MicrositeKeys.scala +++ b/src/main/scala/microsites/MicrositeKeys.scala @@ -185,7 +185,11 @@ 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 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/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), diff --git a/src/main/scala/microsites/layouts/Layout.scala b/src/main/scala/microsites/layouts/Layout.scala index fa734aaa..98dbea1f 100644 --- a/src/main/scala/microsites/layouts/Layout.scala +++ b/src/main/scala/microsites/layouts/Layout.scala @@ -54,13 +54,14 @@ abstract class Layout(config: MicrositeSettings) { def render: TypedTag[String] - def commonHead: TypedTag[String] = { - head( - metas, - favicons, - styles - ) - } + def commonHead: List[TypedTag[String]] = + List( + head( + metas, + favicons, + styles + ) + ) ++ ganalytics4 val ganalytics: Option[TypedTag[String]] = if (config.identity.analytics.nonEmpty) @@ -207,6 +208,24 @@ 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..c5fdc28c 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,