Linking vue-gtm (Google Tag Manager) with a Router instance

Utilizing the following npm package: https://www.npmjs.com/package/vue-gtm

Within my router.js file (using vue cli 3), I am attempting to connect it to a router instance:

import Vue from 'vue'
import Router from 'vue-router'
import VueGtm from 'vue-gtm'

Vue.use(VueGtm, {
  id: 'GTM-xxxxxxx',
  enabled: true,
  debug: true,
  vueRouter: Router
})

export default new Router({
  mode: 'history'
})

However, it is evident that this approach will not function as intended. How can I properly link vue-gtm to a Router in my scenario, where I export the Router instance without assigning it to a variable?

const router = new Router({})

Answer №1

There is an error in how you are passing the Router class for vueRouter in the following code:

Vue.use(VueGtm, {
  //vueRouter: Router, // <-- DON'T DO THIS
})

The correct way to pass the vueRouter value is by using the router instance. For example, your router.js file should be structured like this:

const routes = [
  //...
]

const router = new Router({
  mode: 'history',
  routes
})

Vue.use(VueGtm, {
  vueRouter: router, // <-- router instance
  //...
})

export default router

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JQuery post request not providing the expected response after posting

I have a post request var prodId = getParameterByName('param'); var pass = $('#password1').val(); $.post("rest/forget/confirm", { "param" : prodId, "password" : pass }, function(data) { ...

Utilizing a variable within an Angular filter: A step-by-step guide

Currently, I am in the process of experimenting with Angular. I am able to retrieve some data from the controller and successfully apply a filter when passing it as a string. However, I encounter issues when attempting to use a variable for the filter inst ...

Hide the .prev button on the jQuery slider when it is on the first

Is there a way to hide the .prev button when it is the first one? Also, why does the slider go back to the first slide when the .prev button is clicked at the last slide? How can this issue be resolved? var nextPane = function (e) { e &&am ...

Display detailed images upon hovering

Top of the morning to everyone. I'm in search of a way to display higher resolution images when hovering over lower resolution ones. I want to create a rule or function that can handle this dynamically without manually adding hover effects and changi ...

How to resolve logic issues encountered during Jasmine testing with describe()?

I am encountering an issue while testing the following code snippet: https://i.sstatic.net/ImwLs.png dateUtility.tests.ts: import { checkDayTime } from "./dateUtility"; describe("utilities/dateUtility", () => { describe("ch ...

What is the process for implementing a CSS theme switch in a CHM file and ensuring that it remains persistent?

Welcome to my tech world Greetings! I am a tech writer with a side interest in scripting JavaScript/jQuery for our help file (CHM file). While I consider myself a beginner in JS scripting, I have ventured into the realm of dynamic theme swapping within CH ...

Is there a way to expand a pie chart into a new pie chart with PHP and Javascript?

I need help finding a code that can expand a pie chart into another pie chart. The original pie chart appears too congested with numerous entries when it first loads. I have only come across tutorials for accomplishing this in Excel online. Can someone a ...

Remaking the functionality of jQuery's $.ajax() method while utilizing the .done() method

As a junior javascript developer, I am working on creating my own "basic" javascript framework inspired by jQuery. I am particularly fond of method chaining instead of callbacks, but I am finding it challenging to implement this. Currently, I have develop ...

Determine the remaining days until the end of the month using moment.js

I need help figuring out how to dynamically display or hide a link based on whether there are less than two weeks remaining in the current month using moment.js. Currently, my code snippet looks like this: if (moment().endOf('month') <= (13, ...

Encountering Problem with Office Object Access in Vue.js Outlook Add-in

Just getting started with vue.js and encountering an issue when trying to access the Office object within Vue methods. In the code snippet below, calling load() from created function works fine, but attempting to call it from this.loadProps() does not wor ...

Tips for overriding ng-disable in AngularJSUnleashing the

This is a comment box using AngularJS: <tr> <td colspan="5"><br/>Comments* <div><textarea class="form-control" rows="3" cols="60" ng-model="final_data.drc_scope" placeholder="Add comments here" ng-disabled="is_team==0 || isDis ...

What could be causing the bootstrap 4 col-md-3 block to shrink when using position fixed?

When working with Bootstrap 4, I encountered an issue where changing the block position from relative to fixed using a script caused the block to decrease in size. The script I used includes a .sticky class: .sticky { position: fixed !important; top: ...

Preserve the form data in HTML even following redirection from a different HTML page

Currently, I am in the process of designing a Sample Registration form with the help of HTML and JS. Once all the fields in the form are filled out, there is an href link that, when clicked, leads to a new HTML page for document uploading. Upon clicking ...

Dynamically populate 7 select boxes with options using JQuery

I have a webpage that includes 14 different dropdown menus, one for each day of the week (Monday to Sunday). Each day has two dropdowns: one for opening time and one for closing time. I used jQuery to populate all 14 dropdowns with a pre-defined list of ho ...

Using useState in ReactJS does not allow setting state data

I am working with a react component that handles agreements. import React from "react"; import { AgreementInfo } from "../../../../models/shop"; import { MdClose } from "react-icons/md"; import moment from "moment"; ...

The art of sketching precise lines encircling a circular shape through the

What is the best way to use a for loop in JavaScript to draw lines around a circle, similar to those on a clock face? ...

Utilizing a d.ts Typescript Definition file for enhanced javascript intellisene within projects not using Typescript

I am currently working on a TypeScript project where I have set "declaration": true in tsconfig.json to generate a d.ts file. The generated d.ts file looks like this: /// <reference types="jquery" /> declare class KatApp implements IKatApp ...

What steps are involved in setting up server-side pagination in AngularJS with angular-ui bootstrap?

I am in need of suggestions for implementing server-side pagination with AngularJS and Angular-UI Bootstrap. The goal is to paginate a table listing using ng-repeat based on the current page selected in the Angular-UI Bootstrap pagination directive. To m ...

The alignment of Bootstrap v4.5 checkbox is limited as it cannot be positioned horizontally or vertically when placed next to an input field

As stated in the title: Bootstrap's checkbox is having trouble aligning Horizontally or Vertically when placed next to an input. Error Displayed: https://i.sstatic.net/hNHpm.png I have experimented with various solutions, but none have provided sat ...

Is there a way to ensure that axios.get runs synchronously?

Here is my Node.js code for scraping 1337x.to. Initially, I successfully scraped the search results and then proceeded to extract the URLs of the torrents along with their magnet links. While this process worked fine within different functions, I encounter ...