From dee5994aa7444e9df361c6d5ce235c876cce6496 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Tue, 30 Jul 2024 09:13:31 +0200 Subject: [PATCH] add matomo to git --- apps/remix-ide/src/app/plugins/matomo.ts | 2 +- libs/remix-api/src/lib/plugins/matomo-api.ts | 10 +++++ libs/remix-api/src/lib/remix-api.ts | 2 + libs/remix-ui/git/src/lib/gitactions.ts | 41 ++++++++++++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 libs/remix-api/src/lib/plugins/matomo-api.ts diff --git a/apps/remix-ide/src/app/plugins/matomo.ts b/apps/remix-ide/src/app/plugins/matomo.ts index 9495d1ddd7..8aa8f61f70 100644 --- a/apps/remix-ide/src/app/plugins/matomo.ts +++ b/apps/remix-ide/src/app/plugins/matomo.ts @@ -11,7 +11,7 @@ const profile = { version: '1.0.0' } -const allowedPlugins = ['LearnEth', 'etherscan', 'vyper', 'circuit-compiler', 'doc-gen', 'doc-viewer', 'solhint', 'walletconnect', 'scriptRunner'] +const allowedPlugins = ['LearnEth', 'etherscan', 'vyper', 'circuit-compiler', 'doc-gen', 'doc-viewer', 'solhint', 'walletconnect', 'scriptRunner', 'dgit'] export class Matomo extends Plugin { diff --git a/libs/remix-api/src/lib/plugins/matomo-api.ts b/libs/remix-api/src/lib/plugins/matomo-api.ts new file mode 100644 index 0000000000..37c17ee646 --- /dev/null +++ b/libs/remix-api/src/lib/plugins/matomo-api.ts @@ -0,0 +1,10 @@ +import { IFilePanel } from '@remixproject/plugin-api' +import { StatusEvents } from '@remixproject/plugin-utils' + +export interface IMatonmoApi { + events:{ + } & StatusEvents + methods: { + track: (data: string[]) => void + } +} diff --git a/libs/remix-api/src/lib/remix-api.ts b/libs/remix-api/src/lib/remix-api.ts index 034c6d4c2e..273f70ecc9 100644 --- a/libs/remix-api/src/lib/remix-api.ts +++ b/libs/remix-api/src/lib/remix-api.ts @@ -11,6 +11,7 @@ import { Plugin } from "@remixproject/engine" import { ISidePanelApi } from "./plugins/sidePanel-api" import { IPinnedPanelApi } from "./plugins/pinned-panel-api" import { ILayoutApi } from "./plugins/layout-api" +import { IMatonmoApi } from "./plugins/matomo-api" export interface ICustomRemixApi extends IRemixApi { dgitApi: IGitApi @@ -23,6 +24,7 @@ export interface ICustomRemixApi extends IRemixApi { sidePanel: ISidePanelApi pinnedPanel: IPinnedPanelApi layout: ILayoutApi + matomo: IMatonmoApi } export declare type CustomRemixApi = Readonly \ No newline at end of file diff --git a/libs/remix-ui/git/src/lib/gitactions.ts b/libs/remix-ui/git/src/lib/gitactions.ts index aa753125a2..23a4726735 100644 --- a/libs/remix-ui/git/src/lib/gitactions.ts +++ b/libs/remix-ui/git/src/lib/gitactions.ts @@ -8,7 +8,6 @@ import { ModalTypes } from "@remix-ui/app"; import { setFileDecorators } from "./pluginActions"; import { Plugin } from "@remixproject/engine"; import { CustomRemixApi } from "@remix-api"; -import { file } from "jszip"; export const fileStatuses = [ ["new,untracked", 0, 2, 0], // new, untracked @@ -25,6 +24,27 @@ export const fileStatuses = [ ["unstaged,modified", 1, 2, 0] ]; +enum gitEventTypes { + INIT = 'INIT', + COMMIT = 'COMMIT', + PUSH = 'PUSH', + PULL = 'PULL', + ADDREMOTE = 'ADDREMOTE', + RMREMOTE = 'RMREMOTE', + CLONE = 'CLONE', + FETCH = 'FETCH', + ADD = 'ADD', + ADD_ALL = 'ADD_ALL', + RM = 'RM', + CHECKOUT = 'CHECKOUT', + DIFF = 'DIFF', + BRANCH = 'BRANCH', + CREATEBRANCH = 'CREATEBRANCH', +} + + + + const statusmatrix: statusMatrixType[] = fileStatuses.map((x: any) => { return { matrix: x.shift().split(","), @@ -39,8 +59,12 @@ export const setPlugin = (p: Plugin, dispatcher: React.Dispatch { +const sendToMatomo = async (event: gitEventTypes) => { + plugin.call('matomo', 'track', ['trackEvent', 'git', event]) +} +export const init = async () => { + sendToMatomo(gitEventTypes.INIT) await plugin.call('dgitApi', "init"); await gitlog(); await getBranches(); @@ -145,6 +169,7 @@ export const currentBranch = async () => { } export const createBranch = async (name: string = "") => { + sendToMatomo(gitEventTypes.CREATEBRANCH) dispatch(setLoading(true)) if (name) { await plugin.call('dgitApi', 'branch', { ref: name, force: true, checkout: true }); @@ -175,6 +200,7 @@ const settingsWarning = async () => { export const commit = async (message: string = "") => { + sendToMatomo(gitEventTypes.COMMIT) try { const credentials = await settingsWarning() if (!credentials) { @@ -202,6 +228,7 @@ export const commit = async (message: string = "") => { } export const addall = async (files: fileStatusResult[]) => { + sendToMatomo(gitEventTypes.ADD_ALL) try { const filesToAdd = files .filter(f => !f.statusNames.includes('deleted')) @@ -227,6 +254,7 @@ export const addall = async (files: fileStatusResult[]) => { } export const add = async (filepath: addInput) => { + sendToMatomo(gitEventTypes.ADD) try { if (typeof filepath.filepath === "string") { filepath.filepath = removeSlash(filepath.filepath) @@ -253,6 +281,7 @@ const getLastCommmit = async () => { } export const rm = async (args: rmInput) => { + sendToMatomo(gitEventTypes.RM) await plugin.call('dgitApi', 'rm', { filepath: removeSlash(args.filepath), }); @@ -303,6 +332,7 @@ export const checkout = async (cmd: checkoutInput) => { export const clone = async (input: cloneInputType) => { + sendToMatomo(gitEventTypes.CLONE) dispatch(setLoading(true)) const urlParts = input.url.split("/"); const lastPart = urlParts[urlParts.length - 1]; @@ -331,6 +361,7 @@ export const clone = async (input: cloneInputType) => { } export const fetch = async (input: fetchInputType) => { + sendToMatomo(gitEventTypes.FETCH) dispatch(setLoading(true)) await disableCallBacks() try { @@ -348,6 +379,7 @@ export const fetch = async (input: fetchInputType) => { } export const pull = async (input: pullInputType) => { + sendToMatomo(gitEventTypes.PULL) dispatch(setLoading(true)) await disableCallBacks() try { @@ -362,6 +394,7 @@ export const pull = async (input: pullInputType) => { } export const push = async (input: pushInputType) => { + sendToMatomo(gitEventTypes.PUSH) dispatch(setLoading(true)) await disableCallBacks() try { @@ -664,7 +697,7 @@ export const resolveRef = async (ref: string) => { } export const diff = async (commitChange: commitChange) => { - + sendToMatomo(gitEventTypes.DIFF) if (!commitChange.hashModified) { const newcontent = await plugin.call( "fileManager", @@ -835,6 +868,7 @@ export const setDefaultRemote = async (remote: remote) => { } export const addRemote = async (remote: remote) => { + sendToMatomo(gitEventTypes.ADDREMOTE) try { await plugin.call('dgitApi', 'addremote', remote) await getRemotes() @@ -849,6 +883,7 @@ export const addRemote = async (remote: remote) => { } export const removeRemote = async (remote: remote) => { + sendToMatomo(gitEventTypes.RMREMOTE) try { await plugin.call('dgitApi', 'delremote', remote) await getRemotes()