assets/themes/j1/adapter/js/advertising.js in j1-template-2022.0.13 vs assets/themes/j1/adapter/js/advertising.js in j1-template-2022.0.14
- old
+ new
@@ -109,15 +109,10 @@
var validProviderID;
var _this;
var logger;
var logText;
-// var domain;
-// var domainAttribute;
-// var cookie_option_domain;
-// var cookie_domain;
-
// ---------------------------------------------------------------------------
// Main object
// ---------------------------------------------------------------------------
return {
@@ -145,20 +140,10 @@
cookie_names = j1.getCookieNames();
user_consent = j1.readCookie(cookie_names.user_consent);
url = new liteURL(window.location.href);
hostname = url.hostname;
-// domain = hostname.substring(hostname.lastIndexOf('.', hostname.lastIndexOf('.') - 1) + 1);
-// cookie_option_domain = '{{cookie_options.domain}}';
-
- // // set domain used by cookies
- // if (cookie_option_domain == 'auto') {
- // domainAttribute = domain ;
- // } else {
- // domainAttribute = hostname;
- // }
-
{% case advertising_provider %}
{% when "google" %}
// [INFO ] [j1.adapter.advertising ] [ place provider: Google Adsense ]
_this = j1.adapter.advertising;
@@ -174,11 +159,11 @@
providerID = '{{advertising_options.google.publisherID}}';
advertisingProvider = 'Google Adsense';
validProviderID = (providerID.includes('your')) ? false : true;
if (!validProviderID) {
- logger.warn('\n' + 'invalid publisherID detected for Google Adsense: ' + providerID);
+ logger.warn('\n' + 'invalid publisherID detected for Google Adsense (GAS): ' + providerID);
logger.info('\n' + 'skip initialization for provider: ' + advertisingProvider);
clearInterval(dependencies_met_page_ready);
return false;
}
@@ -188,26 +173,26 @@
// -----------------------------------------------------------------
// _this.place_ads();
// add gad api dynamically in the head section
// -----------------------------------------------------------------
- logger.info('\n' + 'add gad api dynamically in section: head');
+ logger.info('\n' + 'add gas api in section: head');
gadScript.async = true;
- gadScript.id = 'gad-api';
+ gadScript.id = 'gas-api';
gadScript.src = '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
gadScript.setAttribute('data-ad-client', 'ca-pub-3885670015316130');
document.head.appendChild(gadScript);
// setup monitor for state changes on all ads configured
// ---------------------------------------------------------------
- logger.info('\n' + 'setup monitoring');
+ logger.debug('\n' + 'setup monitoring');
_this.monitor_ads();
// run protection check
// -------------------------------------------------------------------
if (checkTrackingProtection) {
- logger.info('\n' + 'run checks for tracking protection');
+ logger.debug('\n' + 'run checks for tracking protection');
_this.check_tracking_protection();
var dependencies_met_tracking_check_ready = setInterval (function (options) {
if (typeof tracking_protection !== 'undefined' ) {
@@ -298,24 +283,31 @@
}, // END init
// -------------------------------------------------------------------------
// monitor_ads()
// monitor for state changes on the ad placed in pages (if any)
+ //
+ // NOTE: Check visibility state of the adSlot to prevent multiple
+ // processing of the same slot
// -------------------------------------------------------------------------
monitor_ads: function () {
+ var logger = log4javascript.getLogger('j1.adapter.advertising.monitor.ads');
$('.adsbygoogle').attrchange({
trackValues: true,
callback: function (event) {
if (event.newValue === 'unfilled') {
- var elm = event.target.dataset;
- if (addBorderOnUnfilled) { $('.adsbygoogle').addClass('border--dotted'); }
- if (elm.adClient) {
- logger.warn('\n' + 'found ad state ' + event.newValue + ' for slot: ' + elm.adSlot);
- if (autoHideOnUnfilled) {
- logger.warn('\n' + ' hide ad for slot: ' + elm.adSlot);
- $('#' + elm.adSlot ).hide();
+ var elm = event.target.dataset;
+ var adSlotIsVisible = $('#' + elm.adSlot ).is(":visible");
+ if (adSlotIsVisible) {
+ if (addBorderOnUnfilled) { $('.adsbygoogle').addClass('border--dotted'); }
+ if (elm.adClient) {
+ logger.warn('\n' + 'found ad state ' + event.newValue + ' for slot: ' + elm.adSlot);
+ if (autoHideOnUnfilled) {
+ logger.warn('\n' + ' hide ad for slot: ' + elm.adSlot);
+ $('#' + elm.adSlot ).hide();
+ }
}
}
}
}
});
@@ -332,10 +324,10 @@
//
// See for more details:
// https://stackoverflow.com/questions/33959324/how-to-detect-if-a-user-is-using-tracking-protection-in-firefox-42
// -------------------------------------------------------------------------
check_tracking_protection: function () {
- var logger = log4javascript.getLogger('j1.adapter.advertising.tracking.monitor');
+ var logger = log4javascript.getLogger('j1.adapter.advertising.monitor.tracking');
logText = '\n' + 'check for trackingprotection';
logger.info(logText);
function checkTrackingProtection() {