Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/commonMain/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Miley Chandonnet • Portfolio</title>
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-9MPHTXCPC7"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-9MPHTXCPC7');
</script>
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="gallery.css">
<link rel="stylesheet" href="blog.css">
Expand Down
15 changes: 15 additions & 0 deletions src/jsMain/kotlin/codes/miley/frontend/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ import kotlinx.browser.window
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*

private fun trackPageView(route: Map<String, String>) {
val path = when {
route["page"] == "blog" && route.containsKey("post") -> "/blog/${route["post"]}"
route["page"] == "blog" -> "/blog"
else -> "/"
}
val gtag = window.asDynamic().gtag
if (gtag != null) {
val params = js("{}")
params.page_path = path
gtag("event", "page_view", params)
}
}

fun RenderContext.header() {
var lastScrollY = window.scrollY
div("categories") {
Expand Down Expand Up @@ -72,6 +86,7 @@ fun main() {
.data
.distinctUntilChanged()
.render { route ->
trackPageView(route)
val page = route["page"]

header()
Expand Down