title: vuejs - google tag manager
body: <p>I have a <code>vuejs</code> project with various pages:</p>
  
  <ul>
  <li>study.vue</li>
  <li>result.vue</li>
  </ul>
  
  <p>My client want me to add in the <code>Google Tag Manager</code> code so that they can use google analytic to track. Where should I add the code in my <code>.vue</code> file? Or should I just add it in the <code>index.html</code>?</p>
  
  <p><strong>Update01</strong></p>
  
  <p>This is what I do so far:</p>
  
  <ol>
  <li><p>I add the <code>Google Tag Manager</code> code to the <code>index.html</code>.</p></li>
  <li><p>I installed <a href="https://www.npmjs.com/package/vue-gtm" rel="nofollow noreferrer">vue-gtm</a>.</p></li>
  <li><p>I have <code>app.js</code> and <code>bootstrap.js</code>. basically, <code>bootstrap.js</code> will have all my other js frameworks added. Like <code>lodash.js</code> or 'jquery.js'. I add the sample code from <code>vue-gtm</code> into <code>bootstrap.js</code>:</p>
  
  <p>window._ = require('lodash');
  window.moment = require('moment');</p>
  
  <p>window.Vue = require('vue');</p>
  
  <p>import VueRouter from 'vue-router';
  Vue.use(VueRouter)</p>
  
  <p>import VueGtm from 'vue-gtm';
  Vue.use(VueGtm, {
    debug: true
  })</p></li>
  <li><p>In all the <code>vue</code> file, I add this code:</p>
  
  <p>this.$ua.trackView('Sample', 'samplepath');</p></li>
  </ol>
  
  <p>However I got error:</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'trackView' of undefined</p>
  </blockquote>
  
  <p>What seems to be the error? </p>