diff --git a/build.gradle.kts b/build.gradle.kts index 6ab8037..0c8ac1f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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) diff --git a/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt b/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt index 42f14c5..a300e10 100644 --- a/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt +++ b/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt @@ -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) { @@ -27,6 +29,10 @@ class ContextMenuButton : AnAction() { } } + val uuid = PermanentInstallationID.get(); + PostHog.posthog.capture(uuid, + "intelliJ:GetCodeContext"); + toolWindow?.show {} } } diff --git a/src/main/kotlin/com/watermelon/context/actions/LoginAction.kt b/src/main/kotlin/com/watermelon/context/actions/LoginAction.kt index 674b6ed..daa321e 100644 --- a/src/main/kotlin/com/watermelon/context/actions/LoginAction.kt +++ b/src/main/kotlin/com/watermelon/context/actions/LoginAction.kt @@ -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 @@ -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") diff --git a/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt b/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt index 2b4ddd3..934fb5b 100644 --- a/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt +++ b/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt @@ -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"); } } diff --git a/src/main/kotlin/com/watermelon/context/utils/PostHog.kt b/src/main/kotlin/com/watermelon/context/utils/PostHog.kt new file mode 100644 index 0000000..3bf7b24 --- /dev/null +++ b/src/main/kotlin/com/watermelon/context/utils/PostHog.kt @@ -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() + +}