-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |