assets/themes/j1/adapter/js/advertising.js in j1-template-2022.0.12 vs assets/themes/j1/adapter/js/advertising.js in j1-template-2022.0.13
- old
+ new
@@ -87,10 +87,12 @@
j1.adapter.advertising = (function (j1, window) {
{% comment %} Set global variables
-------------------------------------------------------------------------------- {% endcomment %}
var environment = '{{environment}}';
+var date = new Date();
+var timestamp_now = date.toISOString();
var gadScript = document.createElement('script');
var adInitializerScript = document.createElement('script');
var autoHideOnUnfilled = {{advertising_options.google.autoHideOnUnfilled}};
var addBorderOnUnfilled = {{advertising_options.google.addBorderOnUnfilled}};
var checkTrackingProtection = {{advertising_options.google.checkTrackingProtection}};
@@ -100,18 +102,22 @@
var url;
var baseUrl;
var hostname;
var cookie_names;
var user_consent;
-var domain;
-var domainAttribute;
-var cookie_option_domain;
-var cookie_domain;
+var advertisingProvider;
+var providerID;
+var validProviderID;
var _this;
var logger;
var logText;
+// var domain;
+// var domainAttribute;
+// var cookie_option_domain;
+// var cookie_domain;
+
// ---------------------------------------------------------------------------
// Main object
// ---------------------------------------------------------------------------
return {
@@ -123,42 +129,61 @@
{% if advertising %}
// [INFO ] [j1.adapter.advertising ] [ detected advertising provider (j1_config): {{advertising_provider}}} ]
// [INFO ] [j1.adapter.advertising ] [ start processing load region head, layout: {{page.layout}} ]
+ // -----------------------------------------------------------------------
+ // Default module settings
+ // -----------------------------------------------------------------------
+ var settings = $.extend({
+ module_name: 'j1.adapter.advertising',
+ generated: '{{site.time}}'
+ }, options);
+
+ // -----------------------------------------------------------------------
+ // Global variable settings
+ // -----------------------------------------------------------------------
cookie_names = j1.getCookieNames();
user_consent = j1.readCookie(cookie_names.user_consent);
url = new liteURL(window.location.href);
- baseUrl = url.origin;
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;
- }
+// 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;
logger = log4javascript.getLogger('j1.adapter.advertising.google');
+
// initialize state flag
_this.setState('started');
logger.info('\n' + 'state: ' + _this.getState());
logger.info('\n' + 'module is being initialized');
- // default module settings
- var settings = $.extend({
- module_name: 'j1.adapter.advertising',
- generated: '2021-12-18 18:55:38 +0000'
- }, options);
var dependencies_met_page_ready = setInterval(function() {
if (j1.getState() == 'finished') {
+
+ 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.info('\n' + 'skip initialization for provider: ' + advertisingProvider);
+ clearInterval(dependencies_met_page_ready);
+ return false;
+ }
+
if (user_consent.personalization) {
// place all ads configured for the page
// NOTE: currently NOT implemented/used
// -----------------------------------------------------------------
// _this.place_ads();
@@ -215,26 +240,30 @@
logger.info('\n' + 'module initialized successfully');
clearInterval(dependencies_met_tracking_check_ready);
}
clearInterval(dependencies_met_page_ready);
} else {
- var gaCookies = j1.findCookie('_ga');
+ // manage GAD cookies if no consent is given|rejected
+ // -----------------------------------------------------------------
+ var gasCookies = j1.findCookie('__ga');
logger.warn('\n' + 'consent on cookies disabled for personalization');
logger.warn('\n' + 'initialization of module advertising skipped');
- // jadams, 2021-12-19: remove cookies on invalid GAD config
- // or left cookies from previous session
- // -----------------------------------------------------------------
- j1.removeCookie({ name: '__gads' });
+ // remove cookies on invalid GAS config or left from a previous
+ // session/page view if they exists
+ // ---------------------------------------------------------------------
+ gasCookies.forEach(function (item) {
+ // Remove cookies from Google Ads
+ if (hostname == 'localhost') {
+ j1.removeCookie({ name: item, domain: false, secure: false });
+ } else {
+ j1.removeCookie({ name: item, domain: '.' + hostname, secure: false });
+ }
+ });
- // jadams, 2021-12-19: delete cookies in loop doesn't work
- // gaCookies.forEach(function (item) {
- // logger.warn('\n' + 'delete GAD cookie: ' + item);
- // // j1.removeCookie({ name: item, domain: domainAttribute });
- // // j1.removeCookie({ name: item });
- // });
-
+ // manage tracking protection
+ // -----------------------------------------------------------------
if (checkTrackingProtection) {
if (!user_consent.personalization) {
logText = '\n' + 'consent on cookies disabled for personalization';
logger.warn(logText);
@@ -268,10 +297,10 @@
return;
}, // END init
// -------------------------------------------------------------------------
// monitor_ads()
- // monitor for state changes on the ad
+ // monitor for state changes on the ad placed in pages (if any)
// -------------------------------------------------------------------------
monitor_ads: function () {
$('.adsbygoogle').attrchange({
trackValues: true,