From 3c10d9ac195ad06c2d5d60c53ebb3b23312ed48a Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 24 Sep 2025 15:48:50 +0100 Subject: [PATCH 1/2] Override matomo window object --- apps/remix-ide/src/app.ts | 19 ++++++++----------- apps/remix-ide/src/app/components/preload.tsx | 17 +++++++++++------ apps/remix-ide/src/app/plugins/matomo.ts | 13 +++++++++---- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/apps/remix-ide/src/app.ts b/apps/remix-ide/src/app.ts index 6f524ae840e..d3e8742afd9 100644 --- a/apps/remix-ide/src/app.ts +++ b/apps/remix-ide/src/app.ts @@ -112,8 +112,6 @@ import TabProxy from './app/panels/tab-proxy.js' import { Plugin } from '@remixproject/engine' import BottomBarPanel from './app/components/bottom-bar-panel' -const _paq = (window._paq = window._paq || []) - export class platformApi { get name() { return isElectron() ? appPlatformTypes.desktop : appPlatformTypes.web @@ -160,7 +158,9 @@ class AppComponent { settings: SettingsTab params: any desktopClientMode: boolean - constructor() { + matomo: Matomo + constructor(matomo: Matomo) { + this.matomo = matomo const PlatFormAPi = new platformApi() Registry.getInstance().put({ api: PlatFormAPi, @@ -217,7 +217,7 @@ class AppComponent { this.workspace = pluginLoader.get() if (pluginLoader.current === 'queryParams') { this.workspace.map((workspace) => { - _paq.push(['trackEvent', 'App', 'queryParams-activated', workspace]) + this.matomo.push(['trackEvent', 'App', 'queryParams-activated', workspace]) }) } this.engine = new RemixEngine() @@ -246,7 +246,7 @@ class AppComponent { this.showMatomo = contextShouldShowMatomo && (!this.matomoConfAlreadySet || shouldRenewConsent) if (this.showMatomo && shouldRenewConsent) { - _paq.push(['trackEvent', 'Matomo', 'refreshMatomoPermissions']); + this.matomo.push(['trackEvent', 'Matomo', 'refreshMatomoPermissions']); } this.walkthroughService = new WalkthroughService(appManager) @@ -307,9 +307,6 @@ class AppComponent { //---- git const git = new GitPlugin() - //---- matomo - const matomo = new Matomo() - //---------------- Solidity UML Generator ------------------------- const solidityumlgen = new SolidityUmlGen(appManager) @@ -454,7 +451,7 @@ class AppComponent { templates, git, pluginStateLogger, - matomo, + this.matomo, templateSelection, scriptRunnerUI, remixAI, @@ -685,7 +682,7 @@ class AppComponent { if (callDetails.length > 1) { this.appManager.call('notification', 'toast', `initiating ${callDetails[0]} and calling "${callDetails[1]}" ...`) // @todo(remove the timeout when activatePlugin is on 0.3.0) - _paq.push(['trackEvent', 'App', 'queryParams-calls', this.params.call]) + this.matomo.push(['trackEvent', 'App', 'queryParams-calls', this.params.call]) //@ts-ignore await this.appManager.call(...callDetails).catch(console.error) } @@ -696,7 +693,7 @@ class AppComponent { // call all functions in the list, one after the other for (const call of calls) { - _paq.push(['trackEvent', 'App', 'queryParams-calls', call]) + this.matomo.push(['trackEvent', 'App', 'queryParams-calls', call]) const callDetails = call.split('//') if (callDetails.length > 1) { this.appManager.call('notification', 'toast', `initiating ${callDetails[0]} and calling "${callDetails[1]}" ...`) diff --git a/apps/remix-ide/src/app/components/preload.tsx b/apps/remix-ide/src/app/components/preload.tsx index 16f2d08cd8b..e514de095dd 100644 --- a/apps/remix-ide/src/app/components/preload.tsx +++ b/apps/remix-ide/src/app/components/preload.tsx @@ -8,7 +8,12 @@ import { localStorageFS } from '../files/filesystems/localStorage' import { fileSystemUtility, migrationTestData } from '../files/filesystems/fileSystemUtility' import './styles/preload.css' import isElectron from 'is-electron' +import { Matomo } from '../plugins/matomo' + const _paq = (window._paq = window._paq || []) +const matomo = new Matomo(_paq) + +window._paq = matomo // _paq.push(['trackEvent', 'App', 'Preload', 'start']) @@ -34,13 +39,13 @@ export const Preload = (props: any) => { function loadAppComponent() { import('../../app') .then((AppComponent) => { - const appComponent = new AppComponent.default() + const appComponent = new AppComponent.default(matomo) appComponent.run().then(() => { props.root.render() }) }) .catch((err) => { - _paq.push(['trackEvent', 'App', 'PreloadError', err && err.message]) + matomo.push(['trackEvent', 'App', 'PreloadError', err && err.message]) console.error('Error loading Remix:', err) setError(true) }) @@ -68,10 +73,10 @@ export const Preload = (props: any) => { ]) if (fsLoaded) { console.log(fsLoaded.name + ' activated') - _paq.push(['trackEvent', 'Storage', 'activate', fsLoaded.name]) + matomo.push(['trackEvent', 'Storage', 'activate', fsLoaded.name]) loadAppComponent() } else { - _paq.push(['trackEvent', 'Storage', 'error', 'no supported storage']) + matomo.push(['trackEvent', 'Storage', 'error', 'no supported storage']) setSupported(false) } } @@ -89,8 +94,8 @@ export const Preload = (props: any) => { return } async function loadStorage() { - ;(await remixFileSystems.current.addFileSystem(remixIndexedDB.current)) || _paq.push(['trackEvent', 'Storage', 'error', 'indexedDB not supported']) - ;(await remixFileSystems.current.addFileSystem(localStorageFileSystem.current)) || _paq.push(['trackEvent', 'Storage', 'error', 'localstorage not supported']) + ;(await remixFileSystems.current.addFileSystem(remixIndexedDB.current)) || matomo.push(['trackEvent', 'Storage', 'error', 'indexedDB not supported']) + ;(await remixFileSystems.current.addFileSystem(localStorageFileSystem.current)) || matomo.push(['trackEvent', 'Storage', 'error', 'localstorage not supported']) await testmigration() remixIndexedDB.current.loaded && (await remixIndexedDB.current.checkWorkspaces()) localStorageFileSystem.current.loaded && (await localStorageFileSystem.current.checkWorkspaces()) diff --git a/apps/remix-ide/src/app/plugins/matomo.ts b/apps/remix-ide/src/app/plugins/matomo.ts index 40c61e718e7..4a28c71b8a0 100644 --- a/apps/remix-ide/src/app/plugins/matomo.ts +++ b/apps/remix-ide/src/app/plugins/matomo.ts @@ -1,8 +1,6 @@ 'use strict' import { Plugin } from '@remixproject/engine' -const _paq = window._paq = window._paq || [] - const profile = { name: 'matomo', description: 'send analytics to Matomo', @@ -14,13 +12,20 @@ const profile = { const allowedPlugins = ['LearnEth', 'etherscan', 'vyper', 'circuit-compiler', 'doc-gen', 'doc-viewer', 'solhint', 'walletconnect', 'scriptRunner', 'scriptRunnerBridge', 'dgit', 'contract-verification', 'noir-compiler'] export class Matomo extends Plugin { + _paq: { push: (data: string[]) => void } - constructor() { + constructor(_paq: { push: (data: string[]) => void }) { super(profile) + this._paq = _paq } async track(data: string[]) { if (!allowedPlugins.includes(this.currentRequest.from)) return - _paq.push(data) + this._paq.push(data) + } + + push(data: string[]) { + console.log('data coming through matomo plugin:', ...data) + this._paq.push(data) } } \ No newline at end of file From 97ec21349ef1e02e261ee168f1e1423957a4d330 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Thu, 25 Sep 2025 14:10:28 +0100 Subject: [PATCH 2/2] Use _paq --- apps/remix-ide/src/app.ts | 12 +++++++----- apps/remix-ide/src/app/components/preload.tsx | 12 ++++++------ apps/remix-ide/src/app/plugins/matomo.ts | 1 - apps/remix-ide/src/assets/js/loader.js | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/remix-ide/src/app.ts b/apps/remix-ide/src/app.ts index d3e8742afd9..184c044f1a7 100644 --- a/apps/remix-ide/src/app.ts +++ b/apps/remix-ide/src/app.ts @@ -71,7 +71,7 @@ import { HardhatHandleDesktop } from './app/plugins/electron/hardhatPlugin' import { circomPlugin } from './app/plugins/electron/circomElectronPlugin' import { GitHubAuthHandler } from './app/plugins/electron/gitHubAuthHandler' import { GitPlugin } from './app/plugins/git' -import { Matomo } from './app/plugins/matomo' +import type { Matomo } from './app/plugins/matomo' import { DesktopClient } from './app/plugins/desktop-client' import { DesktopHost } from './app/plugins/electron/desktopHostPlugin' import { WalletConnect } from './app/plugins/walletconnect' @@ -112,6 +112,8 @@ import TabProxy from './app/panels/tab-proxy.js' import { Plugin } from '@remixproject/engine' import BottomBarPanel from './app/components/bottom-bar-panel' +const _paq = (window._paq = window._paq || []) + export class platformApi { get name() { return isElectron() ? appPlatformTypes.desktop : appPlatformTypes.web @@ -217,7 +219,7 @@ class AppComponent { this.workspace = pluginLoader.get() if (pluginLoader.current === 'queryParams') { this.workspace.map((workspace) => { - this.matomo.push(['trackEvent', 'App', 'queryParams-activated', workspace]) + _paq.push(['trackEvent', 'App', 'queryParams-activated', workspace]) }) } this.engine = new RemixEngine() @@ -246,7 +248,7 @@ class AppComponent { this.showMatomo = contextShouldShowMatomo && (!this.matomoConfAlreadySet || shouldRenewConsent) if (this.showMatomo && shouldRenewConsent) { - this.matomo.push(['trackEvent', 'Matomo', 'refreshMatomoPermissions']); + _paq.push(['trackEvent', 'Matomo', 'refreshMatomoPermissions']); } this.walkthroughService = new WalkthroughService(appManager) @@ -682,7 +684,7 @@ class AppComponent { if (callDetails.length > 1) { this.appManager.call('notification', 'toast', `initiating ${callDetails[0]} and calling "${callDetails[1]}" ...`) // @todo(remove the timeout when activatePlugin is on 0.3.0) - this.matomo.push(['trackEvent', 'App', 'queryParams-calls', this.params.call]) + _paq.push(['trackEvent', 'App', 'queryParams-calls', this.params.call]) //@ts-ignore await this.appManager.call(...callDetails).catch(console.error) } @@ -693,7 +695,7 @@ class AppComponent { // call all functions in the list, one after the other for (const call of calls) { - this.matomo.push(['trackEvent', 'App', 'queryParams-calls', call]) + _paq.push(['trackEvent', 'App', 'queryParams-calls', call]) const callDetails = call.split('//') if (callDetails.length > 1) { this.appManager.call('notification', 'toast', `initiating ${callDetails[0]} and calling "${callDetails[1]}" ...`) diff --git a/apps/remix-ide/src/app/components/preload.tsx b/apps/remix-ide/src/app/components/preload.tsx index e514de095dd..64660aefafe 100644 --- a/apps/remix-ide/src/app/components/preload.tsx +++ b/apps/remix-ide/src/app/components/preload.tsx @@ -45,7 +45,7 @@ export const Preload = (props: any) => { }) }) .catch((err) => { - matomo.push(['trackEvent', 'App', 'PreloadError', err && err.message]) + window._paq.push(['trackEvent', 'App', 'PreloadError', err && err.message]) console.error('Error loading Remix:', err) setError(true) }) @@ -62,7 +62,7 @@ export const Preload = (props: any) => { setShowDownloader(false) const fsUtility = new fileSystemUtility() const migrationResult = await fsUtility.migrate(localStorageFileSystem.current, remixIndexedDB.current) - _paq.push(['trackEvent', 'Migrate', 'result', migrationResult ? 'success' : 'fail']) + window._paq.push(['trackEvent', 'Migrate', 'result', migrationResult ? 'success' : 'fail']) await setFileSystems() } @@ -73,10 +73,10 @@ export const Preload = (props: any) => { ]) if (fsLoaded) { console.log(fsLoaded.name + ' activated') - matomo.push(['trackEvent', 'Storage', 'activate', fsLoaded.name]) + window._paq.push(['trackEvent', 'Storage', 'activate', fsLoaded.name]) loadAppComponent() } else { - matomo.push(['trackEvent', 'Storage', 'error', 'no supported storage']) + window._paq.push(['trackEvent', 'Storage', 'error', 'no supported storage']) setSupported(false) } } @@ -94,8 +94,8 @@ export const Preload = (props: any) => { return } async function loadStorage() { - ;(await remixFileSystems.current.addFileSystem(remixIndexedDB.current)) || matomo.push(['trackEvent', 'Storage', 'error', 'indexedDB not supported']) - ;(await remixFileSystems.current.addFileSystem(localStorageFileSystem.current)) || matomo.push(['trackEvent', 'Storage', 'error', 'localstorage not supported']) + ;(await remixFileSystems.current.addFileSystem(remixIndexedDB.current)) || window._paq.push(['trackEvent', 'Storage', 'error', 'indexedDB not supported']) + ;(await remixFileSystems.current.addFileSystem(localStorageFileSystem.current)) || window._paq.push(['trackEvent', 'Storage', 'error', 'localstorage not supported']) await testmigration() remixIndexedDB.current.loaded && (await remixIndexedDB.current.checkWorkspaces()) localStorageFileSystem.current.loaded && (await localStorageFileSystem.current.checkWorkspaces()) diff --git a/apps/remix-ide/src/app/plugins/matomo.ts b/apps/remix-ide/src/app/plugins/matomo.ts index 4a28c71b8a0..21827dfec74 100644 --- a/apps/remix-ide/src/app/plugins/matomo.ts +++ b/apps/remix-ide/src/app/plugins/matomo.ts @@ -20,7 +20,6 @@ export class Matomo extends Plugin { } async track(data: string[]) { - if (!allowedPlugins.includes(this.currentRequest.from)) return this._paq.push(data) } diff --git a/apps/remix-ide/src/assets/js/loader.js b/apps/remix-ide/src/assets/js/loader.js index 3d591f4ad4a..010f13ab64d 100644 --- a/apps/remix-ide/src/assets/js/loader.js +++ b/apps/remix-ide/src/assets/js/loader.js @@ -8,7 +8,7 @@ const domainsOnPrem = { 'alpha.remix.live': 1, 'beta.remix.live': 2, 'remix.ethereum.org': 3, - 'localhost': 4 // remix desktop + 'localhost': isElectron() ? 4 : 1, // remix desktop } let cloudDomainToTrack = domains[window.location.hostname]