Skip to content

Commit

Permalink
Use ConfigManager in GA
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Nov 22, 2019
1 parent 45de916 commit 74e8958
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package io.quarkus.code.analytics
import com.brsanthu.googleanalytics.GoogleAnalytics
import com.brsanthu.googleanalytics.GoogleAnalyticsConfig
import com.brsanthu.googleanalytics.request.DefaultRequest
import io.quarkus.code.services.CodeQuarkusConfigManager
import javax.inject.Singleton
import io.quarkus.runtime.StartupEvent
import org.eclipse.microprofile.config.inject.ConfigProperty
import java.util.logging.Logger
import javax.enterprise.event.Observes

import javax.inject.Inject


@Singleton
Expand All @@ -18,24 +19,24 @@ open class GoogleAnalyticsService {
private val log = Logger.getLogger(GoogleAnalyticsService::class.java.name)
}

@ConfigProperty(name = "io.quarkus.code.ga-tracking-id", defaultValue = "")
lateinit var googleTrackingId: String
@Inject
lateinit var config: CodeQuarkusConfigManager

var googleAnalytics: GoogleAnalytics? = null

fun onStart(@Observes e: StartupEvent) {
if (googleAnalytics == null && googleTrackingId.isNotEmpty()) {
if (googleAnalytics == null && config.gaTrackingId.isNotEmpty()) {
val defaultRequest = DefaultRequest()

defaultRequest.documentHostName("code.quarkus.io")
defaultRequest.documentReferrer("https://code.quarkus.io")

googleAnalytics = GoogleAnalytics.builder()
.withDefaultRequest(defaultRequest)
.withTrackingId(googleTrackingId)
.withTrackingId(config.gaTrackingId)
.withConfig(GoogleAnalyticsConfig().setBatchSize(30).setBatchingEnabled(true))
.build()
log.info("GoogleAnalytics is enabled, trackingId: $googleTrackingId")
log.info("GoogleAnalytics is enabled, trackingId: ${config.gaTrackingId}")
} else {
log.info("GoogleAnalytics is disabled")
}
Expand Down

0 comments on commit 74e8958

Please sign in to comment.