Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions apps/remix-ide/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -307,9 +307,6 @@ class AppComponent {
//---- git
const git = new GitPlugin()

//---- matomo
const matomo = new Matomo()

//---------------- Solidity UML Generator -------------------------
const solidityumlgen = new SolidityUmlGen(appManager)

Expand Down Expand Up @@ -454,7 +451,7 @@ class AppComponent {
templates,
git,
pluginStateLogger,
matomo,
this.matomo,
templateSelection,
scriptRunnerUI,
remixAI,
Expand Down Expand Up @@ -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)
}
Expand All @@ -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]}" ...`)
Expand Down
17 changes: 11 additions & 6 deletions apps/remix-ide/src/app/components/preload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't that slow down the loading? did you notice some latency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it does not slow it down.


const _paq = (window._paq = window._paq || [])
const matomo = new Matomo(_paq)

window._paq = matomo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redefining window._paq here may be tricky, we don't actually know if loader.js has completed its task async loading the tracker code into _paq, and if the window._paq init object has been properly handled by the matomo initializing script. the point of matomo async loading is prevent any delays that would be caused by sync loading the script. so at this point the _paq may just be an array of the init we set in loader, it may not be the tracker at all @yann300 @ioedeveloper


// _paq.push(['trackEvent', 'App', 'Preload', 'start'])

Expand All @@ -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(<RemixApp app={appComponent} />)
})
})
.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)
})
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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())
Expand Down
13 changes: 9 additions & 4 deletions apps/remix-ide/src/app/plugins/matomo.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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)
}
}