Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Create content body link tracking component
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Mar 3, 2021
1 parent aeef990 commit 6d03788
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/marko-web-p1-events/browser/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
extends: [
'airbnb-base',
'plugin:vue/recommended',
],
env: {
browser: true,
},
rules: {
'vue/max-attributes-per-line': ['error', {
singleline: 3,
multiline: {
max: 1,
allowFirstLine: false,
},
}],
},
parserOptions: {
parser: 'babel-eslint',
},
};
5 changes: 5 additions & 0 deletions packages/marko-web-p1-events/browser/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const TrackContentBodyLinks = () => import(/* webpackChunkName: "p1-events-track-content-body-links" */ './track-content-body-links.vue');

export default (Browser) => {
Browser.register('P1EventsTrackContentBodyLinks', TrackContentBodyLinks);
};
49 changes: 49 additions & 0 deletions packages/marko-web-p1-events/browser/track-content-body-links.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div class="marko-web-p1-events-content-body-links" style="display: none;" />
</template>

<script>
export default {
props: {
entity: {
type: String,
required: true,
},
selector: {
type: String,
default: '.page-contents__content-body',
},
linkType: {
type: String,
default: 'external',
},
action: {
type: String,
default: 'Click',
},
category: {
type: String,
default: 'In-Body Content Link',
},
},
created() {
const { p1events } = window;
if (!p1events) return;
p1events('trackLinks', {
ancestor: this.selector,
linkType: this.linkType,
handler: ({ element }) => {
const url = element.getAttribute('href');
if (!url) return null;
return {
action: 'Click',
category: 'In-Body Content Link',
entity: this.entity,
props: { url },
};
},
});
},
};
</script>
17 changes: 17 additions & 0 deletions packages/marko-web-p1-events/components/marko.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
"template": "./track-content.marko",
"@node": "object"
},
"<marko-web-p1-events-track-content-body-links>": {
"template": "./track-content-body-links.marko",
"<content>": {
"@id": {
"type": "number",
"required": true
},
"@type": {
"type": "string",
"required": true
}
},
"@selector": "string",
"@link-type": "string",
"@action": "string",
"@category": "string"
},
"<marko-web-p1-events-track-website-section>": {
"template": "./track-website-section.marko",
"@node": "object"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getAsObject } from "@parameter1/base-cms-object-path";
import eventEntity from "../utils/base-content-entity";

$ const content = getAsObject(input, "content");

<marko-web-browser-component
name="P1EventsTrackContentBodyLinks"
props={
entity: eventEntity(content.id, content.type),
selector: input.selector,
linkType: input.linkType,
action: input.action,
category: input.category,
}
/>

0 comments on commit 6d03788

Please sign in to comment.