Skip to content

Commit 915c33f

Browse files
Merge pull request #6152 from vuestorefront/docs-47/gtm
Add gtm and hubspot to VSF1 docs
2 parents 4a3b546 + 1070342 commit 915c33f

File tree

3 files changed

+169
-2
lines changed

3 files changed

+169
-2
lines changed

docs/.vuepress/config.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const GTM_TAG = 'GTM-WMDC3CP';
2+
13
module.exports = {
24
base: '/v1/',
35
port: 8081,
@@ -8,10 +10,21 @@ module.exports = {
810
},
911
head: [
1012
['link', { rel: 'icon', href: '/favicon.png' }],
11-
['script', { src: 'https://cdnjs.cloudflare.com/ajax/libs/diff2html/2.12.1/diff2html.min.js'}]
13+
['script', { src: 'https://cdnjs.cloudflare.com/ajax/libs/diff2html/2.12.1/diff2html.min.js'}],
14+
// HubSpot
15+
['script', { async: true, defer: true, src: 'https://js.hs-scripts.com/8443671.js', id: 'hs-script-loader' }],
16+
// Google Tag Manager
17+
['script', {}, [`
18+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
19+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
20+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
21+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
22+
})(window,document,'script','dataLayer','${GTM_TAG}');
23+
`]]
1224
],
1325
themeConfig: {
14-
repo: 'DivanteLtd/vue-storefront',
26+
GTM_TAG,
27+
repo: 'vuestorefront/vue-storefront',
1528
docsDir: 'docs',
1629
editLinks: true,
1730
sidebarDepth: 3,

docs/.vuepress/theme/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extend: '@vuepress/theme-default'
3+
};
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<template>
2+
<div
3+
class="theme-container"
4+
:class="pageClasses"
5+
@touchstart="onTouchStart"
6+
@touchend="onTouchEnd"
7+
>
8+
<!-- Google Tag Manager (noscript) -->
9+
<noscript>
10+
<iframe
11+
:src="`https://www.googletagmanager.com/ns.html?id=${ $site.themeConfig.GTM_TAG }`"
12+
height="0"
13+
width="0"
14+
style="display:none;visibility:hidden">
15+
</iframe>
16+
</noscript>
17+
<!-- End Google Tag Manager (noscript) -->
18+
19+
<Navbar
20+
v-if="shouldShowNavbar"
21+
@toggle-sidebar="toggleSidebar"
22+
/>
23+
24+
<div
25+
class="sidebar-mask"
26+
@click="toggleSidebar(false)"
27+
/>
28+
29+
<Sidebar
30+
:items="sidebarItems"
31+
@toggle-sidebar="toggleSidebar"
32+
>
33+
<template #top>
34+
<slot name="sidebar-top" />
35+
</template>
36+
<template #bottom>
37+
<slot name="sidebar-bottom" />
38+
</template>
39+
</Sidebar>
40+
41+
<Home v-if="$page.frontmatter.home" />
42+
43+
<Page
44+
v-else
45+
:sidebar-items="sidebarItems"
46+
>
47+
<template #top>
48+
<slot name="page-top" />
49+
</template>
50+
<template #bottom>
51+
<slot name="page-bottom" />
52+
</template>
53+
</Page>
54+
</div>
55+
</template>
56+
57+
<script>
58+
import Home from '@theme/components/Home.vue'
59+
import Navbar from '@theme/components/Navbar.vue'
60+
import Page from '@theme/components/Page.vue'
61+
import Sidebar from '@theme/components/Sidebar.vue'
62+
import { resolveSidebarItems } from '@vuepress/theme-default/util'
63+
export default {
64+
name: 'Layout',
65+
components: {
66+
Home,
67+
Page,
68+
Sidebar,
69+
Navbar
70+
},
71+
data () {
72+
return {
73+
isSidebarOpen: false
74+
}
75+
},
76+
computed: {
77+
shouldShowNavbar () {
78+
const { themeConfig } = this.$site
79+
const { frontmatter } = this.$page
80+
if (
81+
frontmatter.navbar === false
82+
|| themeConfig.navbar === false) {
83+
return false
84+
}
85+
return (
86+
this.$title
87+
|| themeConfig.logo
88+
|| themeConfig.repo
89+
|| themeConfig.nav
90+
|| this.$themeLocaleConfig.nav
91+
)
92+
},
93+
shouldShowSidebar () {
94+
const { frontmatter } = this.$page
95+
return (
96+
!frontmatter.home
97+
&& frontmatter.sidebar !== false
98+
&& this.sidebarItems.length
99+
)
100+
},
101+
sidebarItems () {
102+
return resolveSidebarItems(
103+
this.$page,
104+
this.$page.regularPath,
105+
this.$site,
106+
this.$localePath
107+
)
108+
},
109+
pageClasses () {
110+
const userPageClass = this.$page.frontmatter.pageClass
111+
return [
112+
{
113+
'no-navbar': !this.shouldShowNavbar,
114+
'sidebar-open': this.isSidebarOpen,
115+
'no-sidebar': !this.shouldShowSidebar
116+
},
117+
userPageClass
118+
]
119+
}
120+
},
121+
mounted () {
122+
this.$router.afterEach(() => {
123+
this.isSidebarOpen = false
124+
})
125+
},
126+
methods: {
127+
toggleSidebar (to) {
128+
this.isSidebarOpen = typeof to === 'boolean' ? to : !this.isSidebarOpen
129+
this.$emit('toggle-sidebar', this.isSidebarOpen)
130+
},
131+
// side swipe
132+
onTouchStart (e) {
133+
this.touchStart = {
134+
x: e.changedTouches[0].clientX,
135+
y: e.changedTouches[0].clientY
136+
}
137+
},
138+
onTouchEnd (e) {
139+
const dx = e.changedTouches[0].clientX - this.touchStart.x
140+
const dy = e.changedTouches[0].clientY - this.touchStart.y
141+
if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 40) {
142+
if (dx > 0 && this.touchStart.x <= 80) {
143+
this.toggleSidebar(true)
144+
} else {
145+
this.toggleSidebar(false)
146+
}
147+
}
148+
}
149+
}
150+
}
151+
</script>

0 commit comments

Comments
 (0)