PageSourceSearch

https://datilim.co.il/wp-content/plugins/advanced-ads-tracking/public/assets/js/script.js?ver=1.20

js datilim.co.il collected 2026-09-30 06:07:48 UTC 11,825 bytes, 383 lines download raw bytes

1// ads loaded by passive cache busting
2window.advadsGAAjaxAds = {};
3
4// ads loaded by ajax cache busting
5window.advadsGAPassiveAds = {};
6
7( function( $ ) {
8    /**
9     * If cache-busting module is enabled.
10     * With 'document.ready' this function will be called after 'document.ready'
11     * from cache-busting when 'defer' attribute is added to scripts.
12     * It is too late, hence do not use 'document.ready'.
13     */
14    if ( typeof advanced_ads_pro !== 'undefined' ) {
15        advanced_ads_pro.observers.add( function( event ) {
16            // waiting for the moment when all passive cache-busting ads will be inserted into html
17            if ( event.event === 'inject_passive_ads' ) {
18				
19				var server = 'all';
20				if ( $.isArray( event.ad_ids ) && !event.ad_ids.length ) {
21					event.ad_ids = {};
22				}
23				advadsGAPassiveAds = advads_tracking_utils( 'concat', advadsGAPassiveAds, event.ad_ids );
24				var filteredIds = removeDelayedAdId( event.ad_ids );
25				
26                var advads_ad_ids;
27                if ( advadsTracking.method === 'frontend' ) {
28                    // cache-busting: off + cache-busting: passive
29                    advads_ad_ids = advads_tracking_utils( 'concat', advads_tracking_ads, filteredIds );
30                    // clean cache-busting: off
31                    advads_tracking_ads = [];
32                } else {
33                    // select only passive cache-busting ads
34                    advads_ad_ids = filteredIds;
35					server = 'passive';
36                }
37				
38				advads_track_ads( advads_ad_ids, server );
39				
40            }
41            if ( event.event === 'inject_ajax_ads' ) {
42				
43				if ( $.isArray( event.ad_ids ) && !event.ad_ids.length ) {
44					event.ad_ids = {};
45				}
46				
47				for ( var blogID in event.ad_ids ) {
48					
49					if ( 'ga' == advads_tracking_methods[ blogID ] ) {
50						
51						for ( var i in event.ad_ids[ blogID ] ) {
52							
53							if ( $( '[data-advadstrackid="' + event.ad_ids[ blogID ][ i ] + '"][data-advadstrackbid="' + blogID + '"]' ).length ) {
54								
55								var HTMLID = $( '[data-advadstrackid="' + event.ad_ids[ blogID ][ i ] + '"][data-advadstrackbid="' + blogID + '"]' ).attr( 'id' );
56								if ( 'undefined' != typeof advads_items.showed && -1 !== advads_items.showed.indexOf( HTMLID ) ) {
57									// this is a trigger-able ad. will be tracked on display if using frontend or ga method
58									continue;
59								}
60								
61							} else {
62								if ( 'undefined' == typeof advadsGAAjaxAds[ blogID ] ) {
63									advadsGAAjaxAds[ blogID ] = [];
64								}
65								advadsGAAjaxAds[ blogID ].push( event.ad_ids[ blogID ][ i ] );
66							}
67							
68						}
69						
70					}
71					advads_track_ads( advadsGAAjaxAds, 'analytics' );
72				}
73				
74			}
75			
76        } );
77    }
78	
79	function triggerTrack( ev ) {
80		var bid = $( ev.target ).attr( 'data-advadstrackbid' );
81		var id = parseInt( $( ev.target ).attr( 'data-advadstrackid' ) );
82		
83		if ( ! bid ) {
84			if ( $( ev.target ).find( '[data-advadstrackbid]' ).length ) {
85				var ads = {};
86				$( ev.target ).find( '[data-advadstrackbid]' ).each( function() {
87					bid = $( this ).attr( 'data-advadstrackbid' );
88					id = parseInt( $( this ).attr( 'data-advadstrackid' ) );
89					if ( 'undefined' == typeof ads[ bid ] ) {
90						ads[ bid ] = [];
91					}
92					ads[ bid ].push( id );
93				} );
94				for ( var bid in ads ) {
95					
96					if ( 'ga' == advads_tracking_methods[ bid ] || advads_tracking_parallel[ bid ] ) {
97						advads_gadelayed_track_event( ev );
98					} else {
99						$.post( advads_tracking_urls[ bid ],{action:advadsTracking.ajaxActionName,ads:ads[ bid ]}, function(response) {} );
100					}
101					
102				}
103			} else {
104				return;
105			}
106		} else {
107			if ( 'ga' == advads_tracking_methods[ bid ] || advads_tracking_parallel[ bid ] ) {
108				advads_gadelayed_track_event( ev );
109			} else {
110				$.post( advads_tracking_urls[ bid ],{action:advadsTracking.ajaxActionName,ads:[ id ]}, function(response) {} );
111			}
112		}
113		
114	}
115	
116	/**
117	 * On DOM ready.
118	 */
119	$(function(){
120		if ( 'undefined' != typeof advanced_ads_layer_settings ) {
121			$( document ).on( advanced_ads_layer_settings.layer_class + '-trigger', function ( ev ) {
122				triggerTrack( ev );
123			} );
124		}
125		if ( 'undefined' != typeof advanced_ads_sticky_check_position_fixed ) {
126			$( document ).on( 'advads-sticky-trigger', function ( ev ) {
127				triggerTrack( ev );
128			} );
129		}
130	});
131	
132}( jQuery ) );
133
134/**
135 * remove delayed ad ids
136 *
137 * @param [arr] ids, the original array of ids
138 * @return [arr] ids, the filtered array
139 */
140function removeDelayedAdId( ids ) {
141	if ( jQuery( '[data-advadstrackid]' ).length ) {
142		jQuery( '[data-advadstrackid]' ).each(function(){
143			var id = parseInt( jQuery( this ).attr( 'data-advadstrackid' ) );
144			var bid = parseInt( jQuery( this ).attr( 'data-advadstrackbid' ) );
145			if ( advads_tracking_utils( 'hasAd', ids ) ) {
146				if ( 'undefined' != typeof ids[bid] ) {
147					var index = ids[bid].indexOf( id );
148					if ( -1 != index ) {
149						ids[bid].splice( index, 1 );
150					}
151				}
152			}
153		});
154	}
155	return ids;
156}
157
158/**
159 * on DOM ready 
160 */
161jQuery(document).ready(function($){
162	if ( 'undefined' == typeof advads_tracking_ads ) return;
163	advads_tracking_ads = removeDelayedAdId( advads_tracking_ads );
164	
165    if ( typeof advanced_ads_pro === 'undefined' ) {
166		if ( advads_tracking_utils( 'hasAd', advads_tracking_ads ) ) {
167			for ( var bid in advads_tracking_ads ) {
168				if ( 'frontend' == advads_tracking_methods[bid] ) {
169					// cache-busting: off
170					advads_track_ads( advads_tracking_ads );
171					// clean cache-busting: off
172					advads_tracking_ads = {1:[]};
173				}
174			}
175		}
176    }
177	
178});
179
180jQuery( document ).on( 'advads_track_ads', function( e, ad_ids ) {
181    advads_track_ads( ad_ids );
182});
183
184/**
185 *  delayed tracking event
186 */
187function advads_gadelayed_track_event( ev ) {
188	/**
189	 * Retrieve the node with ad ids, can be the sticky/layer placement wrapper, or the ads themselves in case of groups 
190	 */
191	var $el = jQuery( ev.target );
192	var $vector = [];
193	if ( $el.attr( 'data-advadstrackid' ) ) {
194		$vector = $el;
195	} else {
196		$vector = $el.find( '[data-advadstrackid]' );
197	}
198	
199	if ( $vector.length ) {
200		var ids = {};
201		
202		// collect ad ids
203		$vector.each(function(){
204			var bid = parseInt( jQuery( this ).attr( 'data-advadstrackbid' ) );
205			if ( 'undefined' == typeof ids[bid] ) {
206				ids[bid] = [];
207			}
208			ids[bid].push( parseInt( jQuery( this ).attr( 'data-advadstrackid' ) ) );
209		});
210		if ( 'undefined' == typeof advadsGATracking.delayedAds ) {
211			advadsGATracking.delayedAds = {};
212		}
213		
214		// then send the delayed tracking request
215		advadsGATracking.delayedAds = advads_tracking_utils( 'concat', advadsGATracking.delayedAds, ids );
216		advads_track_ads( advadsGATracking.delayedAds, 'delayed' );
217	}
218}
219
220function advads_tracking_utils() {
221	if ( !arguments.hasOwnProperty( 0 ) ) return;
222	var fn = arguments[0];
223	var args = Array.prototype.slice.call( arguments, 1 );
224	
225	var utils = {
226		hasAd: function( data ) {
227			for ( var i in data ) {
228				if ( jQuery.isArray( data[i] ) ) {
229					if ( data[i].length ) {
230						return true;
231					}
232				}
233			}
234			return false;
235		},
236		concat: function() {
237			var result = {};
238			for ( var i in args ) {
239				for ( var j in args[i] ) {
240					if ( 'undefined' == typeof result[j] ) {
241						result[j] = args[i][j];
242					} else {
243						if ( 'function' == typeof result[j].concat ) {
244							result[j] = result[j].concat( args[i][j] );
245						}
246					}
247				}
248			}
249			return result;
250		},
251		blogUseGA: function( bid ) {
252			if ( 'ga' != advads_tracking_methods[bid] && false === advads_tracking_parallel[bid] ) {
253				return false;
254			}
255			if ( '' == advads_gatracking_uids[bid] ) {
256				return false;
257			}
258			return true;
259		},
260		adsByBlog: function( ads, bid ) {
261			var result = {};
262			if ( 'undefined' != typeof ads[bid] ) {
263				result[bid] = ads[bid];
264				return result;
265			}
266			return {};
267		},
268	};
269	if ( 'function' == typeof utils[fn] ) {
270		return utils[fn].apply( null, args );
271	}
272}
273
274/**
275 * track ads
276 *
277 * @param {arr} advads_ad_ids
278 * @param {str} server, to which server the tracking request should be sent all|local|analytics
279 */
280function advads_track_ads( advads_ad_ids, server ) {
281    if ( !advads_tracking_utils( 'hasAd', advads_ad_ids ) ) return; // do not send empty array
282	if ( 'undefined' == typeof server ) server = 'all';
283	
284	for ( var bid in advads_ad_ids ) {
285		var data = {
286			ads: advads_ad_ids[bid],
287		};
288        
289		if ( advads_tracking_utils( 'blogUseGA', bid ) ) {
290			// send tracking data to Google
291			if ( 'undefined' == typeof advadsGATracking ) {
292				window.advadsGATracking = {};
293			}
294			if ( 'undefined' == typeof advadsGATracking.deferedAds ) {
295				window.advadsGATracking.deferedAds = {};
296			}
297			if ( 'local' != server ) {
298				// ads ID-s already collected and will be sent automatically once the Analytics tracker is ready
299				advadsGATracking.deferedAds = advads_tracking_utils(
300					'concat',
301					advadsGATracking.deferedAds,
302					advads_tracking_utils( 'adsByBlog', advads_ad_ids, bid )
303				);
304				if ( 'delayed' == server ) {
305					
306					// "Delayed" tracking. Explicitly defined for placements that initially hide ads (timeout/scroll)
307					jQuery( document ).trigger( 'advadsGADelayedTrack' );
308					var passiveDelayed = {};
309					passiveDelayed[bid] = [];
310					// also track locally if needed ( passive cache busting )
311					if ( -1 == ['frontend','ga'].indexOf( advads_tracking_methods[bid] ) ) {
312						
313						if ( advads_tracking_utils( 'hasAd', advads_tracking_utils( 'adsByBlog', advadsGAPassiveAds, bid ) ) ) {
314							for ( var i in advads_ad_ids[bid] ) {
315								if ( -1 != advadsGAPassiveAds[bid].indexOf( advads_ad_ids[bid][i] ) ) {
316									passiveDelayed[bid].push( advads_ad_ids[i] );
317								}
318							}
319						}
320						if ( passiveDelayed[bid].length ) {
321							for( var j in passiveDelayed[bid] ) {
322								advadsGAPassiveAds[bid].splice( advadsGAPassiveAds[bid].indexOf( passiveDelayed[j] ), 1 );
323							}
324							jQuery.post( advads_tracking_urls[bid], {ads:passiveDelayed[bid],action:advadsTracking.ajaxActionName}, function(response) {} );
325						}
326					}
327					
328				} else {
329					
330					// normal passive cache busting in parallel tracking
331					if (
332						'passive' == server &&
333						advads_tracking_utils( 'hasAd', advads_tracking_utils( 'adsByBlog', advads_ad_ids, bid ) ) &&
334						-1 != ['onrequest','shutdown'].indexOf( advads_tracking_methods[bid] )
335					) {
336						data.action = advadsTracking.ajaxActionName;
337						jQuery.post( advads_tracking_urls[bid], data, function(response) {} );
338					}
339					
340					// the "usual" deferred tracking (once the GA tracker is ready)
341					jQuery( document ).trigger( 'advadsGADeferedTrack' );
342					
343				}
344				
345			}
346			
347			if ( advads_tracking_parallel[bid] && 'analytics' != server && advads_tracking_methods[bid] == 'frontend' ) {
348				// if concurrent tracking, also send data to the server
349				if ( advads_tracking_utils( 'hasAd', advads_tracking_utils( 'adsByBlog', advadsGAAjaxAds, bid ) ) ) {
350					
351					// remove first all ajax ads (already tracked)
352					var removed = [];
353					for ( var i in advadsGAAjaxAds[bid] ) {
354						var index = data.ads.indexOf( advadsGAAjaxAds[bid][i] );
355						if ( -1 != index ) {
356							data.ads.splice( index, 1 );
357							removed.push( advadsGAAjaxAds[bid][i] );
358						}
359					}
360					if ( removed.length ) {
361						for ( var j in removed ) {
362							index = advadsGAAjaxAds[bid].indexOf( removed[j] );
363							advadsGAAjaxAds[bid].splice( index, 1 );
364						}
365					}
366				}
367				
368				if ( data.ads.length ) {
369					data.action = advadsTracking.ajaxActionName;
370					jQuery.post( advads_tracking_urls[bid], data, function(response) {} );
371				}
372			}
373		} else {
374			if ( 'analytics' != server ) {
375				// just send tracking data to the server
376				jQuery.post( advads_tracking_urls[bid], {ads:data.ads,action:advadsTracking.ajaxActionName}, function(response) {} );
377			}
378		}
379		
380	}
381	
382	
383}

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.