Skip to content

Commit 9138b0a

Browse files
authored
Merge pull request #296 from shopware/feat/telemetry
Add anonymous feature usage telemetry
2 parents 9b09ff4 + 4417789 commit 9138b0a

23 files changed

Lines changed: 358 additions & 6 deletions

src/main/kotlin/de/shyim/shopware6/action/context/InsertSnippetAction.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.intellij.ui.components.JBList
1313
import com.jetbrains.php.lang.psi.PhpFile
1414
import com.jetbrains.twig.TwigFile
1515
import de.shyim.shopware6.completion.SnippetCompletionElement
16+
import de.shyim.shopware6.telemetry.TelemetryClient
1617
import de.shyim.shopware6.util.AdminSnippetUtil
1718
import de.shyim.shopware6.util.FrontendSnippetUtil
1819
import icons.ShopwareToolBoxIcons
@@ -25,6 +26,8 @@ class InsertSnippetAction : DumbAwareAction("Insert Snippet", "Insert snippet co
2526
val pf: PsiFile = LangDataKeys.PSI_FILE.getData(e.dataContext) ?: return
2627
val editor = LangDataKeys.EDITOR.getData(e.dataContext) ?: return
2728

29+
val startedAt = System.currentTimeMillis()
30+
2831
val items: MutableList<SnippetCompletionElement> = if (pf.virtualFile.path.contains("app/administration")) {
2932
AdminSnippetUtil.getAllEnglishKeys(pf.project)
3033
} else {
@@ -76,6 +79,8 @@ class InsertSnippetAction : DumbAwareAction("Insert Snippet", "Insert snippet co
7679
)
7780
}, "Insert Snippet", null)
7881
}
82+
83+
TelemetryClient.trackFeature(pf.project, "snippet.insert", startedAt)
7984
})
8085
.createPopup()
8186
.showInBestPositionFor(e.dataContext)

src/main/kotlin/de/shyim/shopware6/action/context/admin/ExtendAdminComponentAction.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.intellij.ui.components.JBList
2323
import de.shyim.shopware6.action.generator.ActionUtil
2424
import de.shyim.shopware6.action.generic.GenericSimpleDialogWrapper
2525
import de.shyim.shopware6.index.dict.ShopwareBundle
26+
import de.shyim.shopware6.telemetry.TelemetryClient
2627
import de.shyim.shopware6.templates.ShopwareTemplates
2728
import de.shyim.shopware6.util.JavaScriptPattern
2829
import de.shyim.shopware6.util.PsiUtil
@@ -154,6 +155,8 @@ class ExtendAdminComponentAction : DumbAwareAction(
154155
project: Project,
155156
runnable: (String) -> Unit
156157
) {
158+
val startedAt = System.currentTimeMillis()
159+
157160
val newComponentName: String
158161
val defaultFilePath = if (type == "override") {
159162
newComponentName = componentName
@@ -214,6 +217,8 @@ class ExtendAdminComponentAction : DumbAwareAction(
214217

215218
if (file != null) {
216219
runnable(file.virtualFile.path)
220+
221+
TelemetryClient.trackFeature(project, "admin.extend_component.$type", startedAt)
217222
}
218223

219224
val entryPoint = LocalFileSystem.getInstance().findFileByPath(bundle.getAdministrationEntrypoint())!!

src/main/kotlin/de/shyim/shopware6/action/context/admin/ExtendAdminComponentMethodAction.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.intellij.ui.components.JBList
2323
import com.intellij.util.containers.filterSmartMutable
2424
import de.shyim.shopware6.index.dict.AdminComponent
2525
import de.shyim.shopware6.index.dict.ShopwareBundle
26+
import de.shyim.shopware6.telemetry.TelemetryClient
2627
import de.shyim.shopware6.util.ShopwareBundleUtil
2728
import de.shyim.shopware6.util.StringUtil
2829
import icons.ShopwareToolBoxIcons
@@ -83,6 +84,8 @@ class ExtendAdminComponentMethodAction :
8384
private const val NEW_COMPONENT = "Create new component"
8485

8586
fun extendMethod(element: PsiElement, editor: Editor) {
87+
val startedAt = System.currentTimeMillis()
88+
8689
val componentName = getComponentName(element)
8790

8891
val popup = ShopwareBundleUtil.getBundleSelectionPopup(element.project)
@@ -130,9 +133,13 @@ class ExtendAdminComponentMethodAction :
130133
bundle
131134
) {
132135
addMethodToComponent(element, it)
136+
137+
TelemetryClient.trackFeature(element.project, "admin.extend_method", startedAt)
133138
}
134139
} else {
135140
addMethodToComponent(element, component.file)
141+
142+
TelemetryClient.trackFeature(element.project, "admin.extend_method", startedAt)
136143
}
137144
}
138145

src/main/kotlin/de/shyim/shopware6/action/copy/CopySnippet.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.intellij.openapi.ui.popup.PopupChooserBuilder
1010
import com.intellij.psi.PsiElement
1111
import com.intellij.psi.PsiFile
1212
import com.intellij.ui.components.JBList
13+
import de.shyim.shopware6.telemetry.TelemetryClient
1314
import icons.ShopwareToolBoxIcons
1415
import java.awt.Toolkit
1516
import java.awt.datatransfer.StringSelection
@@ -20,6 +21,8 @@ class CopySnippet : DumbAwareAction("Copy Snippet Code", "Copy the snippet code"
2021
val editor = LangDataKeys.EDITOR.getData(e.dataContext) ?: return
2122
val pe = pf.findElementAt(editor.caretModel.offset) ?: return
2223

24+
val startedAt = System.currentTimeMillis()
25+
2326
val key = resolveKey(pe)
2427
val collectionList: MutableCollection<String> = mutableListOf()
2528
collectionList.add("Admin Twig")
@@ -45,6 +48,8 @@ class CopySnippet : DumbAwareAction("Copy Snippet Code", "Copy the snippet code"
4548
StringSelection(code),
4649
null
4750
)
51+
52+
TelemetryClient.trackFeature(pf.project, "snippet.copy", startedAt)
4853
})
4954
.createPopup()
5055
.showInBestPositionFor(editor)

src/main/kotlin/de/shyim/shopware6/action/generator/NewConfigXmlAction.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import com.intellij.openapi.actionSystem.AnActionEvent
66
import com.intellij.openapi.actionSystem.PlatformDataKeys
77
import com.intellij.openapi.project.DumbAwareAction
88
import com.intellij.openapi.project.Project
9+
import de.shyim.shopware6.telemetry.TelemetryClient
910
import de.shyim.shopware6.templates.ShopwareTemplates
1011

1112
class NewConfigXmlAction : DumbAwareAction("Create a Config.Xml", "Create a new config.xml", AllIcons.FileTypes.Xml) {
1213

1314
override fun actionPerformed(e: AnActionEvent) {
15+
val startedAt = System.currentTimeMillis()
16+
1417
val project: Project? = e.getData(PlatformDataKeys.PROJECT)
1518

1619
if (project === null) {
@@ -24,6 +27,8 @@ class NewConfigXmlAction : DumbAwareAction("Create a Config.Xml", "Create a new
2427
"config.xml",
2528
XmlFileType.INSTANCE
2629
)
30+
31+
TelemetryClient.trackFeature(project, "generator.config_xml", startedAt)
2732
}
2833

2934
}

src/main/kotlin/de/shyim/shopware6/action/generator/app/AddCmsActions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class AddCmsActions : AddConfigFileAction(
77
"cms.xml",
88
"Resources",
99
ShopwareTemplates.SHOPWARE_APP_CMS,
10+
"generator.app_cms_blocks",
1011
"Add CMS blocks",
1112
"Add CMS blocks to an app",
1213
ShopwareToolBoxIcons.SHOPWARE

src/main/kotlin/de/shyim/shopware6/action/generator/app/AddConfigFileAction.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.intellij.psi.PsiManager
1414
import com.intellij.ui.components.JBList
1515
import de.shyim.shopware6.action.generator.ActionUtil
1616
import de.shyim.shopware6.index.dict.ShopwareApp
17+
import de.shyim.shopware6.telemetry.TelemetryClient
1718
import de.shyim.shopware6.templates.ShopwareTemplates
1819
import de.shyim.shopware6.util.ShopwareAppUtil
1920
import java.awt.Component
@@ -25,6 +26,7 @@ abstract class AddConfigFileAction(
2526
private val configFileName: String,
2627
private val configFilePath: String,
2728
private val shopwareTemplate: String,
29+
private val telemetryFeature: String,
2830
text: String,
2931
description: String,
3032
icon: Icon
@@ -40,15 +42,17 @@ abstract class AddConfigFileAction(
4042
e.project!!,
4143
this.configFileName,
4244
this.configFilePath,
43-
this.shopwareTemplate
45+
this.shopwareTemplate,
46+
System.currentTimeMillis()
4447
)
4548
}
4649

4750
private fun chooseAppAndCreateConfigFileFromTemplate(
4851
project: Project,
4952
configFile: String,
5053
configFilePath: String,
51-
shopwareTemplate: String
54+
shopwareTemplate: String,
55+
startedAt: Long
5256
) {
5357
val apps = ShopwareAppUtil.getAllApps(project)
5458
val jbAppList = JBList(apps)
@@ -100,6 +104,8 @@ abstract class AddConfigFileAction(
100104

101105
FileEditorManager.getInstance(project)
102106
.openTextEditor(OpenFileDescriptor(project, createdConfigFile.virtualFile), true)
107+
108+
TelemetryClient.trackFeature(project, telemetryFeature, startedAt)
103109
}, "Creating Config File", null)
104110
})
105111
.createPopup()

src/main/kotlin/de/shyim/shopware6/action/generator/app/AddCustomEntitiesAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class AddCustomEntitiesAction : AddConfigFileAction(
77
"entities.xml",
88
"Resources",
99
ShopwareTemplates.SHOPWARE_APP_CUSTOM_ENTITIES,
10+
"generator.app_custom_entities",
1011
"Add Custom Entities",
1112
"Add custom entities to an app",
1213
ShopwareToolBoxIcons.SHOPWARE

src/main/kotlin/de/shyim/shopware6/action/generator/app/NewAppAction.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent
55
import com.intellij.openapi.project.DumbAwareAction
66
import com.intellij.openapi.ui.Messages
77
import de.shyim.shopware6.action.generator.ActionUtil
8+
import de.shyim.shopware6.telemetry.TelemetryClient
89
import de.shyim.shopware6.templates.ShopwareTemplates
910
import icons.ShopwareToolBoxIcons
1011

@@ -14,6 +15,8 @@ class NewAppAction : DumbAwareAction("Create an App", "Create a new Shopware app
1415
return
1516
}
1617

18+
val startedAt = System.currentTimeMillis()
19+
1720
val rootDirectory = ActionUtil.getViewDirectory(e.dataContext) ?: return
1821

1922
val wrapper = NewAppDialogWrapper()
@@ -40,5 +43,7 @@ class NewAppAction : DumbAwareAction("Create an App", "Create a new Shopware app
4043
content,
4144
appFolder
4245
)
46+
47+
TelemetryClient.trackFeature(e.project, "generator.app", startedAt)
4348
}
4449
}

src/main/kotlin/de/shyim/shopware6/action/generator/app/NewAppScriptAction.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.jetbrains.twig.TwigFileType
1313
import de.shyim.shopware6.action.generator.ActionUtil
1414
import de.shyim.shopware6.index.dict.ScriptHook
1515
import de.shyim.shopware6.index.dict.ShopwareApp
16+
import de.shyim.shopware6.telemetry.TelemetryClient
1617
import de.shyim.shopware6.templates.ShopwareTemplates
1718
import de.shyim.shopware6.util.PsiUtil
1819
import de.shyim.shopware6.util.ScriptHookUtil
@@ -29,6 +30,8 @@ class NewAppScriptAction :
2930
return
3031
}
3132

33+
val startedAt = System.currentTimeMillis()
34+
3235
val hooks = ScriptHookUtil.getAllHooks(e.project!!)
3336

3437
val jbHookList = JBList(hooks.sortedBy { it.name })
@@ -57,13 +60,13 @@ class NewAppScriptAction :
5760
return@setFilteringEnabled (it as ScriptHook).name
5861
}
5962
.setItemChosenCallback(Runnable {
60-
this.chooseApp(jbHookList.selectedValue!!, e.project!!)
63+
this.chooseApp(jbHookList.selectedValue!!, e.project!!, startedAt)
6164
})
6265
.createPopup()
6366
.showInFocusCenter()
6467
}
6568

66-
private fun chooseApp(scriptHook: ScriptHook, project: Project) {
69+
private fun chooseApp(scriptHook: ScriptHook, project: Project, startedAt: Long) {
6770
val apps = ShopwareAppUtil.getAllApps(project)
6871
val jbAppList = JBList(apps)
6972

@@ -89,15 +92,15 @@ class NewAppScriptAction :
8992
.setTitle("Shopware: Select App")
9093
.setItemChosenCallback(Runnable {
9194
CommandProcessor.getInstance().executeCommand(project, {
92-
this.createFile(jbAppList.selectedValue, scriptHook, project)
95+
this.createFile(jbAppList.selectedValue, scriptHook, project, startedAt)
9396

9497
}, "Create Hook", null)
9598
})
9699
.createPopup()
97100
.showInFocusCenter()
98101
}
99102

100-
private fun createFile(app: ShopwareApp, scriptHook: ScriptHook, project: Project) {
103+
private fun createFile(app: ShopwareApp, scriptHook: ScriptHook, project: Project, startedAt: Long) {
101104
val localFolder = LocalFileSystem.getInstance().findFileByPath(app.rootFolder)
102105
val psiDir = PsiManager.getInstance(project).findDirectory(localFolder!!) as PsiDirectory
103106

@@ -118,5 +121,7 @@ class NewAppScriptAction :
118121
),
119122
scriptsDir
120123
) ?: return
124+
125+
TelemetryClient.trackFeature(project, "generator.app_script", startedAt)
121126
}
122127
}

0 commit comments

Comments
 (0)