Track your multimedia articles with ease
⚠⚠⚠ The content of this repository is auto-generated from @optimics/analytics multirepo, because Google Tag Manager does not have it's own artifact repository. The contents are overwritten with each release.
The template has inline documentation, so please refer to it, while configuring it.
Set up the article selector, which points to element containing the entire article content, including videos and main headings.
Generally, you want to "Track all Default Content Types", unless you have created your custom replacement trackers for each Content Type. You can provide your custom Content Type providers by defining a function, that returns a class extending the ArticleElement or one of it's subclasses.
window.customArticleTypes = {
customVideoPlayer({ ArticleElement, ArticleParagraph, VisualArticleElement }) {
return class CustomVideoPlayer extends ArticleElement {
static selector = '.what-the-player'
constructor(el) {
super(el)
this.subscribeToMyPlayer()
}
getMetadata () {
return JSON.parse(this.el.dataset.metadata)
}
estimateFastestTime() {
return this.getMetadata().totalTime * 0.76
}
estimateSlowestTime() {
return this.getMetadata().totalTime
}
subscribeToMyPlayer() {
magicPlayer.on('play', () => this.recordConsumptionTime())
magicPlayer.on('pause', () => this.stopConsumption())
}
}
}
}
Article Tracker produces a lot of events, so you must choose, which ones you want to track in your datalayer by pairing the Article Tracker Event Name with the desired data layer event name.
Article Tracker Event: consumptionStartedFirst
GTM Event: article_consumption_started
Extra properties can be bundled with each event binding. See the Extra properties for examples.
For example:
Extra properties will be appended to each event triggered by Article Tracker. They must be JSON encoded. Invalid JSON inputs will crash the code. GTM Template Tags may be used in the JSON.
{"pageTitle": "{{PAGE TITLE VARIABLE}}", "staticVariable": true}