1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | module.exports = (tomlData, animateTemplate, skPkg) => {
|
9 | const manifest = {}
|
10 | const trackableEvents = tomlData.tvEvents.trackableEvents || tomlData.tvEvents.thirdPartyPixels || []
|
11 | const clickThruEvents = tomlData.tvEvents.uri || []
|
12 | const allConfigurables = new Set(trackableEvents.concat(clickThruEvents))
|
13 | manifest.tvCustomEvents = [...allConfigurables].map((k) => {
|
14 | const parts = k.split('_')
|
15 | const configurable = {
|
16 | name: k,
|
17 | kind: parts[0] || '',
|
18 | context: parts[1] || '',
|
19 | args: parts.slice(2),
|
20 | uri: clickThruEvents.includes(k)
|
21 | }
|
22 | return configurable
|
23 | })
|
24 | const videosJson = JSON.stringify(tomlData.videos, null, 2)
|
25 | .split('\n')
|
26 | .map((line) => ` ${line}`)
|
27 | .join('\n')
|
28 | .slice(4)
|
29 |
|
30 | const bunnerInitScript = `function adInit() {
|
31 | var banner = new window.Banner( {
|
32 | tvCustomEvents:${JSON.stringify(manifest.tvCustomEvents)},
|
33 | width:$WT,
|
34 | height:$HT,
|
35 | fromAnimate:true,
|
36 | videos:${videosJson},
|
37 | bridgeId:'${tomlData.general.bridgeId}',
|
38 | adParameters: {geoInfo: ${JSON.stringify(tomlData.geoInfo)}}
|
39 | })
|
40 | }`
|
41 |
|
42 | let newTemplate = animateTemplate.replace(/(<script>)function[\d\s\w|&_\(\)\{\}=<>`'"#:\+\*\.\/,-\[\]\\$]+?(<\/script>)/i, `$1${bunnerInitScript}$2`)
|
43 | return newTemplate
|
44 | }
|