Skip to content

Commit

Permalink
Add Google Analytics settings (#172)
Browse files Browse the repository at this point in the history
* wip add google analytics settings
* add google analytics settings
* pull from master and solves source conflicts
* fixes changes requested
* update tests
  • Loading branch information
AdrianRaFo authored and juanpedromoreno committed Apr 24, 2017
1 parent 7bf18d4 commit f3d53c8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
6 changes: 6 additions & 0 deletions docs/src/main/tut/docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ micrositeGitHostingService := GitLab
micrositeGitHostingUrl := "https://gitlab.com/gitlab-org/gitlab-ce"
```

- `micrositeAnalyticsToken`: Property id of Google Analytics, by default is empty.

```
micrositeAnalyticsToken := 'UA-XXXXX-Y'
```

- `micrositeHighlightTheme`: by default, the theme of Highlight.js is [default](https://highlightjs.org/static/demo/), however, you can configure it to a different theme thanks to this setting:

```
Expand Down
6 changes: 5 additions & 1 deletion src/main/scala/microsites/MicrositeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ trait MicrositeKeys {
"Determines what will be chosen for pushing the site. The options are sbt-ghpages plugin and github4s library.")

val publishMicrositeCommandKey: String = "publishMicrosite"
val micrositeAnalyticsToken =
settingKey[String](
"Optional. Add your property id of Google Analytics to add a Google Analytics tracker")
}

object MicrositeKeys extends MicrositeKeys
Expand Down Expand Up @@ -151,7 +154,8 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
author = micrositeAuthor.value,
homepage = micrositeHomepage.value,
organizationHomepage = micrositeOrganizationHomepage.value,
twitter = micrositeTwitter.value
twitter = micrositeTwitter.value,
analytics = micrositeAnalyticsToken.value
),
visualSettings = MicrositeVisualSettings(
highlightTheme = micrositeHighlightTheme.value,
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/microsites/MicrositesPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ object MicrositesPlugin extends AutoPlugin {
micrositeGitHostingService := GitHub,
micrositeGitHostingUrl := "",
micrositePushSiteWith := GHPagesPlugin,
micrositeAnalyticsToken := "",
includeFilter in Jekyll := ("*.html" | "*.css" | "*.png" | "*.jpg" | "*.jpeg" | "*.gif" | "*.js" | "*.swf" | "*.md" | "*.webm" | "*.ico" | "CNAME"),
commands ++= Seq(publishMicrositeCommand)
)
Expand Down
15 changes: 13 additions & 2 deletions src/main/scala/microsites/layouts/Layout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ abstract class Layout(config: MicrositeSettings) {
)
}

val ganalytics: Option[TypedTag[String]] =
if (config.identity.analytics.nonEmpty)
Some(script(s"""
|(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
|ga('create', '${config.identity.analytics}' , 'auto');
|ga('send', 'pageview');
""".stripMargin))
else None
def metas: List[TypedTag[String]] =
List(
meta(charset := "utf-8"),
Expand Down Expand Up @@ -73,8 +85,7 @@ abstract class Layout(config: MicrositeSettings) {
rel := "icon",
`type` := "image/png",
href := "{{site.url}}{{site.baseurl}}/img/favicon.png")
)

) ++ ganalytics.toList
def favicons: List[TypedTag[String]] =
(if (config.visualSettings.favicons.nonEmpty) {
config.visualSettings.favicons
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/microsites/microsites.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ case class MicrositeIdentitySettings(
author: String,
homepage: String,
organizationHomepage: String,
twitter: String)
twitter: String,
analytics: String)

case class MicrositeFileLocations(
micrositeImgDirectory: File,
Expand Down
4 changes: 3 additions & 1 deletion src/test/scala/microsites/util/Arbitraries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ trait Arbitraries {
homepage Arbitrary.arbitrary[String]
organizationHomepage Arbitrary.arbitrary[String]
twitter Arbitrary.arbitrary[String]
analytics Arbitrary.arbitrary[String]
highlightTheme Arbitrary.arbitrary[String]
micrositeConfigYaml configYamlArbitrary.arbitrary
micrositeImgDirectory Arbitrary.arbitrary[File]
Expand Down Expand Up @@ -143,7 +144,8 @@ trait Arbitraries {
author,
homepage,
organizationHomepage,
twitter),
twitter,
analytics),
MicrositeVisualSettings(highlightTheme, palette, favicon),
micrositeConfigYaml,
MicrositeFileLocations(
Expand Down

0 comments on commit f3d53c8

Please sign in to comment.