Skip to content

Commit

Permalink
changed lib
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit committed Oct 28, 2019
1 parent 6724615 commit fc3f5fc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
35 changes: 35 additions & 0 deletions src/main/kotlin/io/quarkus/code/AnalyticsFilter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.quarkus.code

import com.brsanthu.googleanalytics.GoogleAnalytics
import com.brsanthu.googleanalytics.GoogleAnalyticsConfig
import org.eclipse.microprofile.config.inject.ConfigProperty
import java.util.stream.Collectors
import javax.ws.rs.container.ContainerRequestContext
import javax.ws.rs.container.ContainerRequestFilter
import javax.ws.rs.core.Context
import javax.ws.rs.core.UriInfo
import javax.ws.rs.ext.Provider

@Provider
class AnalyticsFilter : ContainerRequestFilter {

@Context
internal var info: UriInfo? = null

@ConfigProperty(name = "io.quarkus.code.google-tracking-id")
lateinit var googleTrackingId: String

override fun filter(context: ContainerRequestContext) {
val googleAnalytics: GoogleAnalytics = GoogleAnalytics.builder()
.withTrackingId(googleTrackingId)
.withConfig(GoogleAnalyticsConfig().setUserAgent("userAgent"))
.build()

val stream = context.uriInfo.queryParameters.entries.stream()
val params = stream.map { entry -> "${entry.key}=${entry.value}" }.collect(Collectors.joining("&"))
val path = info!!.path
val divider = if (params != null) "?" else ""

googleAnalytics.pageView().documentPath("$path$divider${params ?: ""}").sendAsync()
}
}
11 changes: 0 additions & 11 deletions src/main/kotlin/io/quarkus/code/CodeQuarkusResource.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.code

import com.brsanthu.googleanalytics.GoogleAnalytics
import io.quarkus.code.model.Config
import io.quarkus.code.model.QuarkusExtension
import io.quarkus.code.model.QuarkusProject
Expand Down Expand Up @@ -56,16 +55,6 @@ class CodeQuarkusResource {
val extensionsResource = CodeQuarkusResource::class.java.getResource("/quarkus/extensions.json")
?: throw IOException("missing extensions.json file")
extensions = extensionsResource.readBytes()

val ga = GoogleAnalytics.builder()
.withTrackingId("UA-150941584-1")
.build()

ga.pageView()
.documentTitle("bla")
.documentPath("/bla")
.clientId("don't know")
.send();
}

@GET
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
quarkus.resteasy.path=/api
quarkus.log.file.enable=false
quarkus.http.cors=true
quarkus.ssl.native=true
io.quarkus.code.quarkus-version=${version.quarkus}
io.quarkus.code.git-commit-id=${git.commit.id.abbrev}
quarkus.ssl.native=true
io.quarkus.code.google-tracking-id=UA-150941584-1

0 comments on commit fc3f5fc

Please sign in to comment.