vue.js - Vue 中的 Matomo 标签管理器实现
问题描述
我正在使用 Matomo 的 Vue 插件,可在此处找到:https ://github.com/AmazingDreams/vue-matomo
我在 main.js 入口文件中导入了 VueMatomo 插件,如下所示:
import VueMatomo from 'vue-matomo';
然后,我将 VueMatomo 分配为我的 main.js 文件中的全局方法,如下所示:
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:
// Overrides the autogenerated tracker endpoint entirely
// Default: undefined
trackerUrl: 'https://mycontainer.js'
另外我如何发送自定义数据。例如:
'user':{
'role':'consumer',
'type':'purchaser'
}
编辑:在 Matomo 标签管理器文档中,它说把它放在 head 标签中。
<!-- 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 插件是否仍然需要它,或者你可以把
g.src='https://mycontainer.js'
别的地方?
解决方案
在引擎盖下,Vue Plugin
简单地向您展示Matomo tracking client SDK
. 您可以通过.this.$matomo
您实际上可以在源代码中看到他们这样做:
const Matomo = MatomoJS.getTracker(trackerEndpoint, siteId)
// Assign matomo to Vue
Vue.prototype.$piwik = Matomo
Vue.prototype.$matomo = Matomo
解决的地方MatomoJS
是通过import Matomojs from './matomo'
哪个只是一个flat javascript file
打包了他们的公共SDK。
推荐阅读
- c# - 如何在 WinAPI 中获取按钮状态?
- iphone - 使用 RxSwift 在 DispatchGroup 之后返回对象
- java - 将数据从 TreeMap 传输到 TreeSet 时丢失数据。
- r - How to remove the empty documents from the Document Term Matrix in R
- data-structures - 为什么用段树时间复杂度解决范围最小查询是 O(Log n)?
- node.js - 节点 JS:编辑 .hbs 文件不反映浏览器视图中的更改
- mysql - MySQL 中 BIT(64) 列的奇怪行为
- jsp - request.setAttribute inside a loop
- ios - Swift - 为什么即使在分配值之后,我也会从隐式解包的可选变量中获取可选值?
- ruby-on-rails - RSpec Rails - subject + assigns as one liner?