This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create content body link tracking component
- Loading branch information
1 parent
aeef990
commit 6d03788
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
49
packages/marko-web-p1-events/browser/track-content-body-links.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/marko-web-p1-events/components/track-content-body-links.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
/> |