PageSourceSearch

https://www.tvu.cl/_templates/desktop/includes/js/publicity.js?v=1.1

js tvu.cl collected 2026-10-02 12:00:37 UTC 11,816 bytes, 273 lines download raw bytes

1function cargarPublicidad() {
2
3    //Verifica si en la vista hay div's con la clase rtb_slot ya que aqui se carga la publicidad
4    if (!$(".rtb_slot")[0]) return false;
5
6    // Se verifica si googletag esta inicializado
7    if (typeof googletag == 'undefined') return false;
8
9    //Se inicia con la contruccion de la publicidad.
10    googletag.cmd.push(function() {
11
12        if(global_section === "single_page"){
13            add_box_ads_content();
14        }
15
16        //Se buscan todos los elemntos que contenga la clase "rtb_slot" y a su vez que no tengan las clases ".loaded,.only-focus"
17        // con el each empizo a iterar sobre acada elemento encontrado que cumpla con la condicion anterior.
18        $(".rtb_slot:not(.loaded,.only-focus)").each(function() {
19
20            //Se agrega la clase "Loaded" al elemento iterado para que en la siguiente vuelta no sea considerado.
21            $(this).addClass("loaded");
22
23            //Se optiene los datos del elemento que esta como atributos
24            var slot = $(this).data("slot");
25            var id = $(this).data("adunit");
26            var dimensions = $(this).data("dimensions");
27            // var div_ads_name = $(this).attr('id');
28
29            //Se definen los tamaños de la publicidad que puede mostrar cada bloque, en funcion del tamaño de la pantalla.
30            switch (true) {
31                case id.includes('header'):
32                    mappingSize = googletag.sizeMapping()
33                                    .addSize([992, 0], [970, 90])
34                                    .addSize([768, 0], [728, 90])
35                                    .addSize([320, 0], [[320, 50], [300, 50], [320, 100]])
36                                    .addSize([0, 0], [[320, 50], [300, 50], [320, 100]])
37                                    .build();
38                break;
39
40                case id.includes('top'):
41                    mappingSize =  googletag.sizeMapping()
42                                    .addSize([992, 0], [728, 90])
43                                    .addSize([768, 0], [728, 90])
44                                    .addSize([320, 0], [[320, 50], [300, 50], [320, 100]])
45                                    .addSize([0, 0], [[320, 50], [300, 50], [320, 100]])
46                                    .build(); 
47                break;
48
49                case id.includes('box'):
50                    mappingSize =  googletag.sizeMapping()
51                                    .addSize([992, 0], [[300, 250], [336, 280]])
52                                    .addSize([768, 0], [[300, 250], [336, 280]])
53                                    .addSize([320, 0], [[300, 250], [336, 280]])
54                                    .addSize([0, 0], [[300, 250], [336, 280]])
55                                    .build();
56                break;
57
58                case id.includes('side1'):
59                    mappingSize = googletag.sizeMapping()
60                                    .addSize([992, 0], [[300, 250], [336, 280], [320, 100]])
61                                    .addSize([768, 0], [[300, 250], [336, 280]])
62                                    .addSize([320, 0], [[300, 250], [300, 50], [320, 100]])
63                                    .addSize([0, 0], [[300, 250], [300, 50], [320, 100]])
64                                    .build();
65                break;
66
67                case id.includes('side'):
68                    mappingSize = googletag.sizeMapping()
69                                    .addSize([992, 0], [[300, 250], [336, 280]])
70                                    .addSize([768, 0], [[300, 250], [336, 280]])
71                                    .addSize([320, 0], [[300, 250], [336, 280]])
72                                    .addSize([0, 0], [[300, 250], [336, 280]])
73                                    .build();
74                break;
75
76                case id.includes('lateral'):
77                    mappingSize = googletag.sizeMapping()
78                                    .addSize([992, 0], [160, 600])
79                                    .addSize([768, 0], [])
80                                    .build();   
81                break;
82            
83                default:
84                    mappingSize = null;
85                break;
86            }
87
88            var valid = true;
89            var slot_ads;
90
91            if (valid == true) {
92                
93                var REFRESH_KEY = "refresh";
94                var REFRESH_VALUE = "true";
95
96                // Create a div for the slot
97                var slotDiv = document.createElement('div');
98                slotDiv.id = id; // Id must be the same as slotName
99                $(this).html(slotDiv);
100
101                //Se define el espacio publicitario.
102                slot_ads = googletag.defineSlot(slot, dimensions, id);
103
104                if(id.includes('slider_ad')){
105                    googletag.defineOutOfPageSlot('/21634495618/tvu/bottom-anchor',googletag.enums.OutOfPageFormat.BOTTOM_ANCHOR).addService(googletag.pubads());
106                }
107
108                //Establece las dimenciones de la publicidad que puede mostrar el espacio publicitario.
109                if(mappingSize !== null){
110                    slot_ads.defineSizeMapping(mappingSize);
111                }
112
113                //???????????????????????????????????????????
114                slot_ads.setTargeting(REFRESH_KEY, REFRESH_VALUE);
115
116                //SI ES NOTA, AGREGAMOS EL ID,CATEGORIAS Y TAGS A LA SECMENTACION
117                if(typeof global_post_id !== 'undefined' && global_post_id !=''){
118
119                    //CATEGORIES
120                    var categories_targeting_slugs = [];
121                    global_post_categories.forEach(function(value,index){
122                        categories_targeting_slugs.push(value.slug);
123                    });
124                    slot_ads.setTargeting('Seccion',categories_targeting_slugs);
125
126                    //TAGS
127                    var tags_targeting_slugs = [];
128                    global_post_tags.forEach(function(value,index){
129                        tags_targeting_slugs.push(value.slug);
130                    });
131                    slot_ads.setTargeting('Tipo',tags_targeting_slugs);
132
133                    //ID
134                    slot_ads.setTargeting('Nota',global_post_id);
135
136                    //Demo
137                    slot_ads.setTargeting('Demo',dfp_demo);
138
139                }
140
141                //Indica que el espacio publicitario definido debe ser gestionado por el servicio de publicidad de Google Ad Manager.
142                slot_ads.addService(googletag.pubads());
143
144                //Inicia la solicitud de toda la puplicidad de la pagina en una solo peticion.
145                googletag.pubads().enableSingleRequest();
146
147                //Oculta los espacion publicitarios que estan vacios. (No se recomienda usarlo cuando se usa el refresh)
148                // googletag.pubads().collapseEmptyDivs(true, true);
149
150                //Centra la publicitadad en el div que lo contiene.
151                googletag.pubads().setCentering(true);
152
153                //Especifica la URL de la página asociada a los anuncios que se están gestionando con Google Ad Manager.
154                // googletag.pubads().set('page_url', 'https://www.diarioconcepcion.cl/');
155                googletag.pubads().set('page_url', 'https://www.tvu.cl/');
156
157                //Habilitar los servicios de publicidad de Google Ad Manager
158                googletag.enableServices();
159
160                //Se muestra el anuncio en el contenedor específicado en el "id"
161                googletag.cmd.push(function() { 
162                    googletag.display(id); 
163                });
164
165                //Verifica si en dicha seccion del sitio se debe refrescar la publicidad
166                if(global_ads_refresh === "true"){
167
168                    //Se actualiza los anuncios que tengan REFRESH_KEY = "refresh"
169                    var SECONDS_TO_WAIT_AFTER_VIEWABILITY = 30; // 30 seconds
170                    googletag.pubads().addEventListener("impressionViewable", function (event) {
171                        var slot = event.slot;
172                          if (slot.getTargeting(REFRESH_KEY).indexOf(REFRESH_VALUE) > -1) {
173                            setTimeout(function () {
174                              if (slot.getTargeting("refreshed_slot")) {
175                                slot.setTargeting("refreshed_slot", "true");
176                              }
177                              googletag.pubads().refresh([slot]);
178                            }, SECONDS_TO_WAIT_AFTER_VIEWABILITY * 1000);
179                          }
180                        });
181                    //End refresh
182
183                }
184
185
186            }
187
188
189        });
190    });
191}
192
193function add_box_ads_content(){
194
195    //Se optienen todos los elemento que tienen la clase '.the-single__text' ya que aqui se carga el contenido de la nota.
196    var elementos = document.querySelectorAll('.main-article-content');
197
198    //Se crea el div para los box de publicidad y se añaden sus atributos
199    var adsDiv = document.createElement('div');
200    adsDiv.setAttribute('class', 'rtb_slot');
201    adsDiv.setAttribute('data-dimensions', '[[300, 250], [336, 280]]');
202    adsDiv.setAttribute('data-section', 'single_page');
203    // adsDiv.setAttribute('style', 'width: 300px; height: 250px; background-color: #58D68D;');
204
205    //Se decraran variables de iteracion.
206    var box = 1;
207    var contador = 0;
208
209    //Inicia la iteracion sobre cada elemento encontrado que tiene la clase '.the-single__text'
210    elementos.forEach(function(elemento) {
211
212        //Se verifica si el elemento ya fue procesado viendo si tiene la clase '.ads_content_succes'.
213        if(!elemento.classList.contains("ads_content_succes")){
214
215            //Se agrega la clase '.ads_content_succes' al elemento para que no sea considerado en la proxima vuelta.
216            elemento.classList.add("ads_content_succes");
217
218            var id_post = elemento.querySelector('.post_id_by_ads').value;
219
220            //Se optienen todos los hijos del elemento.
221            var hijos = elemento.children;
222
223            // Obtener todos los elementos <p> dentro del div
224            // var parrafos = elemento.getElementsByTagName('p');
225            var parrafos = Array.from(hijos).filter(function(hijo) { return hijo.tagName === 'P'; });
226            
227            //Se calcula un proporcional de cada cuantos parrafos de muestra un anuncio
228            //Esto porque solo hay 3 box_ad disponibles porque un box1 se utiliza en el lateral.
229            var p_proporcional = Math.floor(parrafos.length / 2); //anterior '3'
230
231            //Inicia iteracion sobre los hijos del elemento.
232            for (var i = 0; i < hijos.length; i++) {
233
234                //Se verifica si el elemento es una etiqueta 'P'.
235                if(hijos[i].tagName == 'P'){
236
237                    //Se aumenta el contados para saber cuando agregar la publicidad.
238                    contador += 1;
239
240                    //Se verifica si el contador para determinar si agrega la publicidad
241                    if(contador == p_proporcional){
242
243                        box += 1;
244
245                        if(box <= 3){ //anterior '4'
246
247                            //Se agregas los atributos faltaste para la publicidad
248                            adsDiv.setAttribute('data-slot', '/21634495618/tvu/box'+box);
249                            adsDiv.setAttribute('data-adunit', 'box'+box+'_ad_'+id_post);
250
251                            //Se inserta la publicidad despues del parrafo indicado.
252                            elemento.insertBefore(adsDiv.cloneNode(true), hijos[i + 1]);
253                            contador = 0;
254
255                        }
256
257                    }
258                }
259            }
260
261        }
262            
263    });
264
265
266}
267
268
269// $(function() {
270    
271//     cargarPublicidad();
272   
273// });

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.