From 173e38741718e02214f3bf2f7cb29c0f24ca4fbf Mon Sep 17 00:00:00 2001 From: baristaGeek Date: Thu, 21 Sep 2023 16:59:08 -0500 Subject: [PATCH 1/4] Add posthog and send the first event with an IntelliJ uuid --- build.gradle.kts | 4 ++++ .../context/actions/ContextMenuButton.kt | 7 +++++++ .../listeners/MyApplicationActivationListener.kt | 1 + .../kotlin/com/watermelon/context/utils/PostHog.kt | 14 ++++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 src/main/kotlin/com/watermelon/context/utils/PostHog.kt 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..d0fdbbf 100644 --- a/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt +++ b/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt @@ -6,6 +6,9 @@ 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.ide.util.PropertiesComponent +import com.intellij.openapi.application.PermanentInstallationID class ContextMenuButton : AnAction() { override fun actionPerformed(e: AnActionEvent) { @@ -27,6 +30,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/listeners/MyApplicationActivationListener.kt b/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt index 2b4ddd3..f61583f 100644 --- a/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt +++ b/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt @@ -6,5 +6,6 @@ import com.intellij.openapi.wm.IdeFrame internal class MyApplicationActivationListener : ApplicationActivationListener { override fun applicationActivated(ideFrame: IdeFrame) { + } } 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..05d74c1 --- /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 { + + // still need to figure this out +// private val POSTHOG_API_KEY = System.getProperties().get("POSTHOG_API_KEY") as String; +// private val POSTHOG_HOST = System.getProperties().get("POSTHOG_HOST") as String; + + + val posthog = PostHog.Builder(POSTHOG_API_KEY) + .host(POSTHOG_HOST) + .build() + +} From 6fc38866ded4c27fb16eab0072fc9f7d18859287 Mon Sep 17 00:00:00 2001 From: baristaGeek Date: Thu, 21 Sep 2023 17:03:10 -0500 Subject: [PATCH 2/4] Track application activated --- .../com/watermelon/context/actions/ContextMenuButton.kt | 1 - .../context/listeners/MyApplicationActivationListener.kt | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt b/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt index d0fdbbf..a300e10 100644 --- a/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt +++ b/src/main/kotlin/com/watermelon/context/actions/ContextMenuButton.kt @@ -7,7 +7,6 @@ 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.ide.util.PropertiesComponent import com.intellij.openapi.application.PermanentInstallationID class ContextMenuButton : AnAction() { diff --git a/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt b/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt index f61583f..934fb5b 100644 --- a/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt +++ b/src/main/kotlin/com/watermelon/context/listeners/MyApplicationActivationListener.kt @@ -1,11 +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"); } } From 718ceb8b9563ea83fc2294759b655e0201ad46d4 Mon Sep 17 00:00:00 2001 From: baristaGeek Date: Thu, 21 Sep 2023 17:09:06 -0500 Subject: [PATCH 3/4] Track login action --- .../kotlin/com/watermelon/context/actions/LoginAction.kt | 7 +++++++ 1 file changed, 7 insertions(+) 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") From ed9bb0ee8107ffcda8e7e5a081ae7c51ec640791 Mon Sep 17 00:00:00 2001 From: baristaGeek Date: Mon, 25 Sep 2023 11:56:18 -0500 Subject: [PATCH 4/4] Solve the not being able to store env vars to retrieve the PostHog environment key issue by forcing the developer to manually insert the API key --- src/main/kotlin/com/watermelon/context/utils/PostHog.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/watermelon/context/utils/PostHog.kt b/src/main/kotlin/com/watermelon/context/utils/PostHog.kt index 05d74c1..3bf7b24 100644 --- a/src/main/kotlin/com/watermelon/context/utils/PostHog.kt +++ b/src/main/kotlin/com/watermelon/context/utils/PostHog.kt @@ -2,9 +2,9 @@ package com.watermelon.context.utils import com.posthog.java.PostHog object PostHog { - // still need to figure this out -// private val POSTHOG_API_KEY = System.getProperties().get("POSTHOG_API_KEY") as String; -// private val POSTHOG_HOST = System.getProperties().get("POSTHOG_HOST") as String; + // 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)