Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #43 from watermelontools/feature/telemetry
Browse files Browse the repository at this point in the history
Feature/telemetry
  • Loading branch information
baristaGeek authored Sep 27, 2023
2 parents 850c0c9 + ed9bb0e commit 5debcd2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ repositories {
//maven { url = uri(urlEncode("https://jitpack.io")) }
}

dependencies {
implementation("com.posthog.java:posthog:1.1.0")
}

// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
kotlin {
jvmToolchain(17)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowManager
import com.watermelon.context.toolWindow.MyToolWindowFactory
import com.watermelon.context.utils.PostHog
import com.intellij.openapi.application.PermanentInstallationID

class ContextMenuButton : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
Expand All @@ -27,6 +29,10 @@ class ContextMenuButton : AnAction() {
}
}

val uuid = PermanentInstallationID.get();
PostHog.posthog.capture(uuid,
"intelliJ:GetCodeContext");

toolWindow?.show {}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/com/watermelon/context/actions/LoginAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.intellij.ide.BrowserUtil
import com.intellij.ide.passwordSafe.PasswordSafe
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.PermanentInstallationID
import com.intellij.openapi.ui.Messages
import com.watermelon.context.utils.PostHog
import kotlinx.serialization.json.*
import java.net.HttpURLConnection
import java.net.URL
Expand Down Expand Up @@ -54,6 +56,11 @@ class LoginAction : AnAction() {
}

override fun actionPerformed(e: AnActionEvent) {
// Capture telemetry event
val uuid = PermanentInstallationID.get();
PostHog.posthog.capture(uuid,
"intelliJ:login");

// Open webpage
BrowserUtil.browse("$backendUrl/intellij")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.watermelon.context.listeners

import com.intellij.openapi.application.ApplicationActivationListener
import com.intellij.openapi.application.PermanentInstallationID
import com.intellij.openapi.wm.IdeFrame
import com.watermelon.context.utils.PostHog

internal class MyApplicationActivationListener : ApplicationActivationListener {

override fun applicationActivated(ideFrame: IdeFrame) {
val uuid = PermanentInstallationID.get();
PostHog.posthog.capture(uuid,
"intelliJ:appActivated");
}
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/watermelon/context/utils/PostHog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.watermelon.context.utils
import com.posthog.java.PostHog
object PostHog {

// manually insert API key here
private val POSTHOG_API_KEY = "POSTHOG_API_KEY";
private val POSTHOG_HOST = "POSTHOG_HOST";


val posthog = PostHog.Builder(POSTHOG_API_KEY)
.host(POSTHOG_HOST)
.build()

}

0 comments on commit 5debcd2

Please sign in to comment.