-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
90 lines (78 loc) · 2.35 KB
/
index.js
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
81
82
83
84
85
86
87
88
89
90
'use strict';
export default {
sizes : {
banner: [[1200, 600], [1200, 400], [300, 250], [300, 300]],
rectangle: [ [300, 250], [300, 300], [300, 600]]
},
/**
* Install DoubleClick Plugin
* @param Vue
* @param options
*/
install(Vue, options){
Vue.component('google-ad', require('./components/BannerAd'));
this.init(options, Vue)
},
/**
* Initialize google tag manager
* @param options
*/
init(options, Vue){
window.googletag = {};
let googledfpviewable = 0;
googletag.cmd = googletag.cmd || [];
let gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
let useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
let node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
googletag.cmd.push(() => {
this.extractOptions(options, Vue);
googletag.pubads().enableSingleRequest();
//googletag.pubads().enableSyncRendering();
googletag.pubads().collapseEmptyDivs();
// googletag.pubads().disableInitialLoad();
googletag.enableServices();
//googletag.display('dynamicload');
// googletag.pubads().refresh();
});
},
/**
* Extract plugin options
* @param options
*/
extractOptions(options, Vue){
options.sizes = Object.assign(this.sizes, options.sizes);
options.mappings = this.prepareMappings(options.mappings);
if(!options.default_size) {
options.default_size = "banner";
}
Vue.prototype.$doubleclick = options;
},
/**
* Prepare mapped sizes
* @param mappings
* @returns {*}
*/
prepareMappings(mappings){
Object.keys(mappings).forEach((key) => {
mappings[key] = this.mapSize(mappings[key])
});
return mappings;
},
/**
* Map single size
* @param mapping
* @returns {*}
*/
mapSize(mapping){
let mapper = googletag.sizeMapping();
mapping.forEach((map) => {
mapper.addSize(map.window, map.sizes)
});
return mapper.build();
},
}