Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this.$matomo is not available in the context using TypeScript #21

Open
fbjorn opened this issue Mar 14, 2021 · 2 comments
Open

this.$matomo is not available in the context using TypeScript #21

fbjorn opened this issue Mar 14, 2021 · 2 comments

Comments

@fbjorn
Copy link

fbjorn commented Mar 14, 2021

Hi,

I installed the plugin this way:

    [
      "nuxt-matomo",
      {
        matomoUrl: "//matomo.my.domain/",
        siteId: 1,
        cookies: false,
      },
    ],

However during yarn generate I get the following error:

ERROR in components/ExportAs.vue:52:10
TS2339: Property '$matomo' does not exist on type 'ExportAs'.
    50 |
    51 |   foo() {
  > 52 |     this.$matomo.trackGoal(1)
       |          ^^^^^^^
    53 |   }
    54 |

As a result, I can't build my website.

FYI, I'm using JetBrains IDE, and they have rich autocomplete for such kind of injections, e.g nuxt-i18n:
image

Unfortunately, there's no for matomo:
image

Do you have any ideas how to resolve it, or at least bypass?

@azpery
Copy link

azpery commented Jul 23, 2021

I have the same issue. Did you find a solution for this?

@azpery
Copy link

azpery commented Jul 23, 2021

I found a fix : you have to declare $matomo yourself :

Create a file in ~/types/index.d.ts :

import Vue from 'vue'

declare module 'vue/types/vue' {
  interface Vue {
    $matomo: any | undefined
  }
}

Then add it in your tsconfig.json :

{
...
"types": [..., "types"]
...
}

Also keep in mind that matomo is disabled in dev mode. You can enable it by setting the debug option in your nuxt.config.js :

[
      'nuxt-matomo',
      { matomoUrl: '//eeee.matomo.cloud/', siteId: 1, debug: true },
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants