首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Matomo标记管理器在Vue中的实现

Matomo标记管理器在Vue中的实现
EN

Stack Overflow用户
提问于 2019-05-01 00:30:33
回答 1查看 564关注 0票数 2

我使用的是Matomo的Vue插件,可以在这里找到:https://github.com/AmazingDreams/vue-matomo

我在我的main.js入口文件中导入了VueMatomo插件,如下所示:

代码语言:javascript
运行
复制
import VueMatomo from 'vue-matomo';

然后,我在main.js文件中将VueMatomo指定为全局方法,如下所示:

代码语言:javascript
运行
复制
Vue.use(VueMatomo, {
  // Configure your matomo server and site
  host: 'https://matomo.example.com', 
  siteId: 1, 

  // Enables link tracking on regular links. Note that this won't
  // work for routing links (ie. internal Vue router links)
  // Default: true
  enableLinkTracking: true,

  // Require consent before sending tracking information to matomo
  // Default: false
  requireConsent: false,

  // Whether to track the initial page view
  // Default: true
  trackInitialView: true,

  // Changes the default .js and .php endpoint's filename
  // Default: 'piwik'
  trackerFileName: 'piwik',

  // Whether or not to log debug information
  // Default: false
  debug: false
});

如何在这个插件中实现标签?我是否可以像这样将trackerUrl设置为容器url:

代码语言:javascript
运行
复制
// Overrides the autogenerated tracker endpoint entirely
// Default: undefined
trackerUrl: 'https://mycontainer.js'

另外,我如何发送自定义数据。例如:

代码语言:javascript
运行
复制
'user':{        
    'role':'consumer', 
    'type':'purchaser'
}

编辑:在Matomo标签管理器文档中,它说要将这个放在head标签中。

代码语言:javascript
运行
复制
<!-- MTM -->
<script type="text/javascript">
var _mtm = _mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src='https://mycontainer.js'; s.parentNode.insertBefore(g,s);
</script>
<!-- End MTM -->

那么vue-matomo插件是否仍然需要这样做,或者您是否可以将

代码语言:javascript
运行
复制
g.src='https://mycontainer.js'

其他地方?

EN

回答 1

Stack Overflow用户

发布于 2019-05-01 00:50:21

在幕后,Vue Plugin简单地向您公开了Matomo tracking client SDK。您可以通过this.$matomo调用任何原生SDK函数listed in their SDK on their website

实际上,你可以在源代码中看到他们这样做:

代码语言:javascript
运行
复制
const Matomo = MatomoJS.getTracker(trackerEndpoint, siteId)

// Assign matomo to Vue
Vue.prototype.$piwik = Matomo
Vue.prototype.$matomo = Matomo

其中MatomoJS是通过import Matomojs from './matomo'解析的,它只是一个打包了他们的public SDK的flat javascript file

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55925235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档