PageSourceSearch

https://www.rtp.pt/common/js/analytics.js?ver=20180524

js rtp.pt collected 2026-10-01 08:00:06 UTC 18,581 bytes, 499 lines download raw bytes

1if (typeof RTPRequireScript !== 'function') {
2
3	var RTPRequireScriptBucketLevel = { dfp: '1', analytics: '1', pipe: '1', chartbeat: '1', peach: '1', gemius: '1', sharethis: '1', disqus: '1' }
4
5	var RTPRequireScript = function ( params ) {
6		var hasBucket = function () { return true; }
7		var loadTrusteScript = function () { return true; }
8
9		return { hasBucket: hasBucket, loadTrusteScript: loadTrusteScript }
10	}
11}
12
13
14// analytics
15if ( RTPRequireScript( RTPRequireScriptBucketLevel.analytics ).hasBucket() ) {
vendor: 329 bytes, lines 15-16
15
16	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', '
16UA-312913-1
vendor: 14 bytes, line 16
16', 'rtp.pt'); 
16ga('require', 'displayfeatures'); ga('send', 'pageview');ga('create', 'UA-312913-25', 'auto', 'playerTracker');
17
18  // window.addEventListener('locationchange', function () {
19  //   console.log('locationchange changed!');
20  // });
21  // window.addEventListener('hashchange', function() { 
22  //   console.log('hashchange changed!');
23  // });
24  // window.addEventListener('popstate', function() { 
25  //   console.log('popstate changed!');
26  // });
27  // console.log("document.referrer", encodeURIComponent(document.referrer));
28  
29  if (typeof window.navigation === 'object'){
30    window.navigation.addEventListener("navigate", (event) => {
31      _sensorAnalytics();
32    });
33  }else{
34    window.addEventListener('hashchange', function () {
35      _sensorAnalytics();
36    });
37  }
38
39
40  var _sensorAnalytics = function() {
41    const _sensorBaseUrl = 'https://www.rtp.pt/rtp-sensor/';
42    const _encodeReferrer = document.referrer;
43    const _encodeURL = document.URL;
44
45    const _path = window.location.host + window.location.pathname;
46
47    const _sensorRegistration = function(params) {
48      const callback_func = params.sensor.callback;
49      delete params.sensor.callback;
50      const queryParams = new URLSearchParams(params.sensor).toString();
51      const urlComQuery = `${params.baseUrl}?${queryParams}`;
52
53      const client = new XMLHttpRequest();
54console.log ("typeof params.callback" );
55console.log (typeof params.callback );
56
57      client.open("HEAD", urlComQuery, true);
58      client.onreadystatechange = () => {
59        // In local files, status is 0 upon success in Mozilla Firefox
60        if (client.readyState === XMLHttpRequest.DONE) {
61          const status = client.status;
62          if (status === 0 || (status >= 200 && status < 400)) {
63            // The request has been completed successfully
64            console.log("typeof params.callback",typeof callback_func);
65            console.log ("VAI CHAMAR O CALBACK");
66
67            if (typeof callback_func !== undefined && typeof callback_func === 'function') {
68              console.log ("CAHMEIR CArLLBACK");
69              callback_func()
70            } 
71          } else {
72            // Oh no! There has been an error with the request!
73          }
74        }
75      };
76      client.send();
77
78
79      //const client = new XMLHttpRequest();
80      //client.open("HEAD", urlComQuery, true);
81      //client.send();
82    };
83
84    var _sensorClick = function(params, callback=false) {
85      console.log ("_sensorClick params.sensor",params);
86     // const callback_func = params.sensor.callback;
87     // delete params.sensor.callback;
88      _sensorRegistration({ baseUrl: _sensorBaseUrl, sensor: params, callback: callback});
89    }
90
91    //const _allowedDomains = ['conta.rtp.pt', 'www.rtp.pt', 'media.rtp.pt'];
92
93    const queryString = window.location.search;
94    const urlParams = new URLSearchParams(queryString);
95     
96//
97//{
98//  app_url: 'conta.rtp.pt/realms/rtp/login-actions/registration',
99//  sensor_opts: [{ app_qstring: 'execution', sensor :{type: 'sso', action: 'registrationAttempt', referrer: _encodeReferrer, url: _encodeURL  }}
100//  ,                                      {  sensor :{ type: 'sso', action: 'registration', referrer: _encodeReferrer, url: _encodeURL  }}
101//]
102//},
103//{
104//  app_url: 'conta.rtp.pt/realms/rtp/login-actions/reset-credentials',
105//  sensor_opts: [{sensor: { type: 'sso', action: 'reset-credentials', referrer: _encodeReferrer, url: _encodeURL  }}]
106//}, 
107
108//{
109//  app_url: 'conta.rtp.pt/realms/rtp/login-actions/authenticate',
110//  sensor_opts: [{ app_qstring: 'execution', sensor :{type: 'sso', action: 'loginAttempt', referrer: _encodeReferrer, url: _encodeURL  }}
111//    ,                                      {  sensor :{ type: 'sso', action: 'login', referrer: _encodeReferrer, url: _encodeURL  }}
112//  ]
113//}
114
115
116    const _rules = [ 
117      {
118        app_url: 'conta.rtp.pt/realms/rtp/protocol/openid-connect/registrations',
119        sensor_opts: [{dom_string: ['Criar a sua conta RTP'], sensor: { type: 'sso', action: 'web_btn_abriu_registo', referrer: _encodeReferrer, url: _encodeURL  }}]
120
121      },
122      {
123        app_url: 'conta.rtp.pt/realms/rtp/login-actions/registration',
124        sensor_opts: [{dom_string: ['Criar a sua conta RTP'], sensor: { type: 'sso', action: 'web_btn_abriu_registo', referrer: _encodeReferrer, url: _encodeURL  }}]
125
126      },
127      {
128        app_url: 'conta.rtp.pt/realms/rtp/protocol/openid-connect/auth',
129        sensor_opts: [{ sensor: { type: 'sso', action: 'web_btn_abriu_login', referrer: _encodeReferrer, url: _encodeURL  }}
130        ,{ referrer_string: ['webview.html'],  sensor: { type: 'sso', action: 'app_btn_abriu_login', referrer: _encodeReferrer, url: _encodeURL  }}
131      ]
132      },
133      {
134        app_url: 'conta.rtp.pt/realms/rtp/login-actions/authenticate',
135        sensor_opts: [{dom_string: ['Inicie a sua sess'], sensor: { type: 'sso', action: 'web_btn_abriu_login', referrer: _encodeReferrer, url: _encodeURL  }
136      }
137      ]
138      },
139      {
140        // Paginad de confirmação de email e email verificado VERIFICADO OK
141        app_url: 'conta.rtp.pt/realms/rtp/login-actions/action-token',
142        sensor_opts: [ { dom_string: ['Confirme a validade do endere'], app_qstring: 'key',  sensor :{ type: 'sso', action: 'pagina_de_confirmacao_de_email', referrer: _encodeReferrer, url: _encodeURL  }},
143                      { dom_string: ['e-mail foi confirmado.'] , app_qstring: 'key',  sensor :{ type: 'sso', action: 'email_verificado', referrer: _encodeReferrer, url: _encodeURL  }}
144      ]
145      },
146      {
147        // Envio de email para confirmação  VERIFICADO OK
148        app_url: 'conta.rtp.pt/realms/rtp/login-actions/required-action',
149        sensor_opts: [ {  dom_string: ['Para confirmar o seu registo, aceda','Tem de verificar o seu endereço de e-mail para ativar sua conta'], sensor :{ type: 'sso', action: 'email_envio_confirmacao', referrer: _encodeReferrer, url: _encodeURL  }}
150        ]
151      }
152      
153    ];
154
155    // Function to check if all strings in dom_string exist in the DOM
156    var checkAllDomStringsExist = function(strings) {
157      console.log (strings);
158
159          // Check if all strings in dom_string exist in the document's body text
160          return strings.every(str => document.body.textContent.includes(str));
161     
162    }
163    // Function to check if all strings in dom_string exist in the DOM
164    var checkAllReferrerExist = function(strings) {
165      console.log (strings);
166
167          // Check if all strings in dom_string exist in the document's body text
168          return strings.every(str => _encodeReferrer.includes(str));
169
170    }
171    var _sensorFindString = function(param) {
172      return document.body.textContent.includes(param); 
173    }
174
175    // Function to check if all strings in dom_string exist in the DOM
176    var checkAllDomClassExist = function(classes) {
177      console.log (classes);
178      // Check if all strings in dom_string exist in the document's body text
179      return classes.every(str => !!document.querySelector(`.${str}`));
180     
181    }
182    var _sensorFindClass = function(param) {
183      return !!document.querySelector(`.${param}`);
184    }
185
186    // Function to check if all strings in dom_string exist in the DOM
187    var checkAllDomIDExist = function(ids) {
188      console.log (ids);
189      // Check if all strings in dom_string exist in the document's body text
190      return ids.every(str => !!document.getElementById(str));
191      
192    }
193    var _sensorFindId = function(param) {
194      return !!document.getElementById(param);
195    }
196
197
198
199    document.addEventListener('DOMContentLoaded', function() {
200 
201
202        _rules.forEach(rule => {
203          //console.log(`Processing URL: ${rule.app_url}`);
204      
205          let paramValue = null;
206          if ( urlParams.size > 0 && typeof rule.app_qstring !== 'undefined'){
207            paramValue = urlParams.get(rule.app_qstring);
208            //paramValue = urlParams.includes(rule.app_qstring);
209          }
210          let sensorKey = 0;
211          if (_path === rule.app_url ) {
212
213          rule.sensor_opts.forEach((option, index) => {
214            //console.log(`\nProcessing Sensor Option ${index + 1}:`);
215            
216            // Extract and display sensor information
217            if (option.sensor) {
218              const { type, action, referrer, url } = option.sensor;
219              //console.log(`  Sensor Type: ${type}`);
220              //console.log(`  Action: ${action}`);
221              //console.log(`  Referrer: ${referrer}`);
222              //console.log(`  URL: ${url}`);
223            }
224      
225            // Extract and display dom_string if available
226            let string_needed = 0;
227            if (option.dom_string) {
228              string_needed = 1;
229              //console.log('  DOM Strings:');
230              allStrings = checkAllDomStringsExist(option.dom_string);
231              //console.log(allStrings ? '------------------ All strings exist' : '------------------ Some strings are missing');
232              if (allStrings) {
233                string_needed = 2;
234              }
235
236              /*
237              option.dom_string.forEach((str, i) => {
238                console.log(`    [${i + 1}] ${str}`);
239                if (_sensorFindString(str)) {
240                  string_needed = 2;
241                  console.log(`String "${str}" encontrada na página.`);
242                }else{
243                  console.log(`String "${str}" NAO encontrada na página.`);
244                }
245
246              });
247              */
248            }
249
250            // Extract and display referrer_needed if available
251            let referrer_needed = 0;
252            if (option.referrer_string) {
253              referrer_needed = 1;
254              //console.log('  DOM referrer_string:');
255              allReferrerStrings = checkAllReferrerExist(option.referrer_string);
256              //console.log(allReferrerStrings ? '------------------ All REFERER_ strings exist' : '------------------ Some REFERRER_strings are missing');
257              if (allReferrerStrings) {
258                referrer_needed = 2;
259              }
260            }
261            // Extract and display dom_id if available
262            let id_needed = 0;
263            if (option.dom_id) {
264              id_needed = 1;
265              //console.log('  DOM IDs:');
266              allIDs = checkAllDomIDExist(option.dom_id);
267              //console.log(allIDs ? '------------------ All IDS exist' : '------------------ Some IDS are missing');
268              if (allIDs) {
269                id_needed = 2;
270              }
271
272              /*
273              option.dom_id.forEach((id, i) => {
274                console.log(`    [${i + 1}] ${id}`);
275                if (_sensorFindId(id)) {
276                  id_needed = 2;
277                  console.log(`ID "${id}" encontrado na página.`);
278                }else{
279                  console.log(`ID "${id}" NAO encontrado na página.`);
280                }
281
282              });
283              */
284            }
285      
286            // Extract and display dom_class if available
287            let class_needed = 0;
288            if (option.dom_class) {
289              class_needed = 1;
290              //console.log('  DOM Classes:');
291              allClasses = checkAllDomClassExist(option.dom_class);
292              //console.log(allClasses ? '------------------ All CLASSES exist' : '------------------ Some CLASSES are missing');
293              if (allClasses) {
294                class_needed = 2;
295              }
296/*
297              option.dom_class.forEach((cls, i) => {
298                console.log(`    [${i + 1}] ${cls}`);
299                if (_sensorFindClass(cls)) {
300                  console.log(`Classe "${cls}" encontrada na página.`);
301                  class_needed = 2;
302                } else{
303                  console.log(`Classe "${cls}" NAO encontrada na página.`);
304                }
305              });
306              */
307            }
308
309            if ((referrer_needed===0 || referrer_needed===2) && (string_needed===0 || string_needed===2) && (id_needed===0 || id_needed===2) && (class_needed===0 || class_needed===2)){
310              //console.log(`\nRULE PARA APLICAR ${index}:`);
311              //console.log(`\nRULE `,option);
312              sensorKey = index;
313
314            }
315      
316            //console.log('---');
317          });
318        
319
320        //console.log ("VAI ENVIAR ->>>>",rule.app_url, sensorKey);
321        //console.log ("VAI ENVIAR ->>>>",rule.sensor_opts[sensorKey]);
322
323        _sensorRegistration({ baseUrl: _sensorBaseUrl, sensor: rule.sensor_opts[sensorKey].sensor});
324
325
326      } 
327
328    });
329  });
330    //}
331    return {
332      _sensorClick: _sensorClick
333    }
334  };
335
336  _sensorAnalytics();
337 
338}
339
340
341
342
343// analytics
344
345
346// pipe
347//if (typeof hidepipe === 'undefined') {
348	if ( RTPRequireScript( RTPRequireScriptBucketLevel.pipe ).hasBucket() ) {
349		!function(){window.EBUPipeQName="_pipe","_pipe"in window||(window._pipe=function(){
350		window._pipe.q.push(arguments)},window._pipe.q=[]),window._pipe.startTime=(new Date).getTime();
351		var e=document.createElement("script");e.src="//d3kyk5bao1crtw.cloudfront.net/pipe-latest.min.js",
352		e.async=!0;var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(e,i)}();
353
354		_pipe('register', 'ptrtp00000000014');
355		_pipe('collect', 'pageview');
356	}
357//}
358// pipe
359
360// chartbeat
361if ( RTPRequireScript( RTPRequireScriptBucketLevel.chartbeat ).hasBucket() ) {
362
363  if (typeof CHARTBEAT_rtp_domain === 'undefined' || (CHARTBEAT_rtp_domain !== 'play.rtp.pt' && CHARTBEAT_rtp_domain !== 'noticias.rtp.pt')) {
364    CHARTBEAT_rtp_domain = false;
365  }
366
367  if (CHARTBEAT_rtp_domain) {
368
369    if (typeof CHARTBEAT_rtp_sections === 'undefined') {
370      CHARTBEAT_rtp_sections = 'RTP';
371    }
372
373    var _sf_async_config = _sf_async_config || {};
374    //CONFIGURATION START
375    _sf_async_config.uid = 60571;
376    _sf_async_config.domain = CHARTBEAT_rtp_domain;
377    _sf_async_config.useCanonical = true;
378    _sf_async_config.sections = CHARTBEAT_rtp_sections;
379    _sf_async_config.authors = 'RTP';
380    //CONFIGURATION END
381    (function () {
382        function loadChartbeat() {
383            window._sf_endpt = (new Date()).getTime();
384            var e = document.createElement('script');
385            e.setAttribute('language', 'javascript');
386            e.setAttribute('type', 'text/javascript');
387            e.setAttribute('src', '//static.chartbeat.com/js/chartbeat.js');
388            document.body.appendChild(e);
389        }
390        loadChartbeat();
391    })();
392  }
393}
394// chartbeat
395
396
397
398/*
399(function ()  {
400  document.addEventListener('DOMContentLoaded', function(event) {
401
402    var getCookie = function( cookieName ) {
403      var v = new RegExp(cookieName+"=([^;]+)").exec(document.cookie);
404      return (v != null) ? unescape(v[1]) : null;
405    }
406
407    var getParentUrl = function() {
408      var isInIframe = (parent !== window),
409          parentUrl = null;
410
411      if (isInIframe) {
412        parentUrl = document.referrer;
413      }
414      return parentUrl;
415    }
416
417    var getHostName = function(url) {
418      if (url == null) {
419        return null;
420      }
421
422      var match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i);
423      if (match != null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) {
424        return match[2];
425      }
426      else {
427        return null;
428      }
429    }
430
431    var getDomain = function(url) {
432      var hostName = getHostName(url);
433      var domain = hostName;
434
435      if (hostName != null) {
436        var parts = hostName.split('.').reverse();
437        if (parts != null && parts.length > 1) {
438          domain = parts[1] + '.' + parts[0];
439
440          if (hostName.toLowerCase().indexOf('.co.uk') != -1 && parts.length > 2) {
441            domain = parts[2] + '.' + domain;
442          }
443        }
444      }
445      return {'domain':domain};
446    }
447
448
449    var showCookie = true;
450    var parentUrl = getParentUrl();
451    var cookieName = '__rtpgeralcookie';
452    var cookie = getCookie( cookieName );
453    var mensage = 'Este site utiliza cookies para permitir uma melhor experi&ecirc;ncia por parte do utilizador. Ao navegar no site estar&aacute; a consentir a sua utiliza&ccedil;&atilde;o. ';
454
455
456    var tplContent = function( mensage, callback ) {
457      var html = '';
458        html += '<div id="rtpgeralcookiecontent" class="rtpgeralcookiecontent">';
459          html += '<p class="text-center">' + mensage;
460            html += '<a href="http://media.rtp.pt/empresa/utilizacao/cookies/"><u>Saber mais</u></a>';
461          html += '</p>';
462          html += '<span><button id="rtpgeralcookieagree" title="Concordar e esconder a barra durante 90 dias">OK</button></span>';
463        html += '</div>';
464
465      $("body").append(html);
466      $(".rtpgeralcookiecontent").css({ "border-top": "1px solid silver", "position": "fixed", "display": "table", "left": "0", "bottom": "0", "width": "100%", "z-index": "1000", "background-color": "white", "padding": "9px" });
467      $(".rtpgeralcookiecontent p, .rtpgeralcookiecontent button").css({ "display": "table-cell", "vertical-align": "middle" });
468      $(".rtpgeralcookiecontent button").css({ "float": "right" });
469
470      callback();
471    }
472
473
474    if ( parentUrl !== null ) {
475      var urlParts = getDomain( parentUrl );
476      if  (urlParts['domain'] !== "rtp.pt") {
477        showCookie = false;
478      }
479    }
480
481
482    if (cookie == null && showCookie) {
483      tplContent( mensage, function(){
484        var bar = document.getElementById( 'rtpgeralcookiecontent' );
485        var btn = document.getElementById( 'rtpgeralcookieagree' );
486
487        btn.addEventListener("click", function(){
488          bar.style.display = 'none';
489          var d = new Date;
490          d.setTime(d.getTime()+24*60*60*1000*90);
491          document.cookie = cookieName + "=ok;path=/;expires="+d.toGMTString();
492        });
493      });
494    }
495
496  });
497})();
498
499*/

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.