-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.htlbid.ts
80 lines (76 loc) · 1.83 KB
/
5.htlbid.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
interface htlbidType {
cmd: (() => void)[]
layout: (type: string) => void
setTargeting: (keys: string, targetingParams: string[]) => void
clearTargeting: (key: string) => void
forceRefresh: () => void
}
type WindowWithHtlbid = Window & {
htlbid: htlbidType
}
declare const window: WindowWithHtlbid
declare const htlbid: htlbidType
export default defineNuxtPlugin(() => {
const config = useRuntimeConfig()
useHead({
link: [{
rel: 'stylesheet',
href: config.public.HTL_CSS,
type: 'text/css',
}],
script: [{
src: config.public.HTL_JS,
async: true,
}],
})
if (!process.server) {
window.htlbid = window.htlbid || {}
htlbid.cmd = htlbid.cmd || []
const init = () => {
htlbid.cmd.push(() => {
htlbid.layout('universal')
})
}
const setTargeting = (targetingParams) => {
htlbid.cmd.push(() => {
for (const key in targetingParams)
htlbid.setTargeting(key, targetingParams[key])
})
}
const clearTargeting = (targetingParams) => {
const targetingKeys = Object.keys(targetingParams)
htlbid.cmd.push(() => {
targetingKeys.forEach((key) => {
htlbid.clearTargeting(key)
})
})
}
const setTargetingForRoute = (route) => {
setTargeting({
is_home: route.name === 'index' ? 'yes' : 'no',
host: location.host,
url: route.path,
urlSegments: route.path
.split('/')
.filter(segment => segment.length > 0),
})
}
const clearAds = () => {
htlbid.cmd.push(() => {
htlbid.forceRefresh()
})
}
return {
provide: {
htlbid: {
init,
setTargeting,
clearTargeting,
setTargetingForRoute,
clearAds,
},
},
}
}
return null
})