Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 5 additions & 6 deletions apps/remix-ide/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -160,7 +160,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 @@ -307,9 +309,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 +453,7 @@ class AppComponent {
templates,
git,
pluginStateLogger,
matomo,
this.matomo,
templateSelection,
scriptRunnerUI,
remixAI,
Expand Down
19 changes: 12 additions & 7 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])
window._paq.push(['trackEvent', 'App', 'PreloadError', err && err.message])
console.error('Error loading Remix:', err)
setError(true)
})
Expand All @@ -57,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()
}

Expand All @@ -68,10 +73,10 @@ export const Preload = (props: any) => {
])
if (fsLoaded) {
console.log(fsLoaded.name + ' activated')
_paq.push(['trackEvent', 'Storage', 'activate', fsLoaded.name])
window._paq.push(['trackEvent', 'Storage', 'activate', fsLoaded.name])
loadAppComponent()
} else {
_paq.push(['trackEvent', 'Storage', 'error', 'no supported storage'])
window._paq.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)) || 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())
Expand Down
14 changes: 9 additions & 5 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,19 @@ 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)
}
}
2 changes: 1 addition & 1 deletion apps/remix-ide/src/assets/js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down