PageSourceSearch

https://www.prontomarketing.com/wp-content/plugins/if-so/public/js/if-so-public.js?ver=1.10.1

js prontomarketing.com collected 2026-09-25 18:42:07 UTC 11,793 bytes, 331 lines download raw bytes

1var ifso_viewed_triggers = {};
2
3var ifso_scope = {
4	evalScriptsFromHTML :function(html){
5		if(typeof(jQuery) !== 'function')
6			return false;
7
8		var el = document.createElement('div');
9		jQuery(el).append(html);
10		var scripts = '';
11		jQuery(el).find('script').each(function(index){
12			scripts += this.innerHTML;
13		});
14		eval.call(null, scripts);	//Indirect eval call - execute in global scope - (1,eval)(scripts);
15	},
16	createCookie : function(name, value, days) {
17		var expires;
18		if (days) {
19			var date = new Date();
20			date.setTime(date.getTime()+(days*24*60*60*1000));
21			expires = "; expires="+date.toGMTString();
22		}
23		else {
24			expires = "";
25		}
26		document.cookie = name+"="+value+expires+"; path=/";
27	},
28	getCookie : function(c_name) {
29		var c_value = document.cookie,
30			c_start = c_value.indexOf(" " + c_name + "=");
31		if (c_start == -1) c_start = c_value.indexOf(c_name + "=");
32		if (c_start == -1) {
33			c_value = null;
34		} else {
35			c_start = c_value.indexOf("=", c_start) + 1;
36			var c_end = c_value.indexOf(";", c_start);
37			if (c_end == -1) {
38				c_end = c_value.length;
39			}
40			c_value = unescape(c_value.substring(c_start, c_end));
41		}
42		return c_value;
43	},
44};
45
46var ajax_triggers_loaded = document.createEvent('Event');
47ajax_triggers_loaded.initEvent('ifso_ajax_triggers_loaded', true, true);
48ifso_scope.DispatchTriggersLoaded  =  function () {document.dispatchEvent(ajax_triggers_loaded);ifso_scope.DispatchAjaxContentLoaded();};
49
50var ajax_conditions_loaded = document.createEvent('Event');
51ajax_conditions_loaded.initEvent('ifso_ajax_conditions_loaded', true, true);
52ifso_scope.DispatchStandaloneCondLoaded  =  function () {document.dispatchEvent(ajax_conditions_loaded);ifso_scope.DispatchAjaxContentLoaded();};
53
54var ajax_content_loaded = document.createEvent('Event');
55ajax_content_loaded.initEvent('ifso_ajax_content_loaded', true, true);
56ifso_scope.DispatchAjaxContentLoaded  =  function () {document.dispatchEvent(ajax_content_loaded);};
57
58
59(function( $ ) {
60	'use strict';
61
62	$(document).ready(function () {
63		function if_so_public(){
64			for(var ifso_scope_member_name in ifso_scope ){
65				if(typeof(ifso_scope_member_name) !=='undefined' && typeof(ifso_scope[ifso_scope_member_name])!=='undefined'){
66					this[ifso_scope_member_name] = ifso_scope[ifso_scope_member_name];
67				}
68			}
69			ifso_scope.public_instance = this;
70		}
71
72		if_so_public.prototype = {
73			lookForLoadLaterTriggers : function(defer=false,ignoreAtts=true){
74				var _this = this;
75				var ret = [];
76				var tags = $('IfSoTrigger');
77				tags.each(function(index,el){
78					var tid = el.getAttribute('tid');
79					var ajaxAttsStr = JSON.stringify(_this.lookForAttrsForAjax(el));
80					var deferAttr =  el.getAttribute('defer');
81					if((deferAttr===null && !defer) ||  (deferAttr!==null && defer)){
82						if(null!== tid){
83							if($.inArray(tid,ret)<0 && (ignoreAtts || ajaxAttsStr==='{}')){
84								ret.push(tid);
85							}
86							else if(!ignoreAtts && ajaxAttsStr!=='{}' && $.inArray(ajaxAttsStr,ret)<0){
87								ret.push({...JSON.parse(ajaxAttsStr), 'id':tid});
88							}
89						}
90					}
91				});
92				return ret;
93			},
94
95			replaceLoadLaterTriggers : function(defer = false){
96				var toReplace = this.lookForLoadLaterTriggers(defer,false);
97				var _this = this;
98				if (toReplace.length>0){
99					this.sendAjaxReq('render_ifso_shortcodes',{triggers:toReplace,pageload_referrer:referrer_for_pageload},function(ret){	//Referrer from if-so public
100						if(ret && ret!== null){
101							try{
102								var data = JSON.parse(ret);
103								$.each(data, function(tid,tval){
104									var tagsInDom = _this.lookForTriggerTags(tid);
105									tagsInDom.each(function(i,tag){
106										tag.outerHTML = tval;
107										_this.evalScriptsFromHTML(tval);
108									})
109								});
110								ifso_scope.DispatchTriggersLoaded();
111							}
112							catch(e){
113								console.error('Error fetching if-so triggers!');
114								console.error(e);
115							}
116						}
117					})
118				}
119			},
120
121			lookForStandaloneConditions : function(tags){
122				var ret = [];
123				tags.each(function(index,el){
124					var _content = el.getAttribute('content');
125					var _default = el.getAttribute('default');
126					var _rule = el.getAttribute('rule');
127					var _hash = el.getAttribute('hash');
128					var _data = {'content':_content,'default':_default,'rule':_rule,'hash':_hash};
129					ret.push(_data);
130				});
131				return ret;
132			},
133
134			replaceStandaloneConditions : function(){
135				var elements = $('IfSoCondition');
136				var toReplace = this.lookForStandaloneConditions(elements);
137				var _this = this;
138				if(toReplace.length>0){
139					this.sendAjaxReq('render_ifso_shortcodes',{triggers:JSON.stringify(toReplace),pageload_referrer:referrer_for_pageload,is_standalone_condition:true},function(ret){	//Referrer from if-so public
140						try{
141							var data = JSON.parse(ret);
142							$.each(data, function(id,val){
143								elements[id].outerHTML = val;
144								_this.evalScriptsFromHTML(val);
145							});
146							ifso_scope.DispatchStandaloneCondLoaded();
147						}
148						catch(e){
149							console.error('Error fetching if-so standalone conditions!');
150							console.error(e);
151						}
152					});
153				}
154			},
155
156			lookForDKI : function(tags){
157				var ret = [];
158				tags.each(function(index,el){
159					var _dkiAtts = el.getAttribute('dkiAtts');
160					ret.push(_dkiAtts);
161				});
162				return ret;
163			},
164
165			replaceDkiElements : function(){
166				var dkiElements = $('IfSoDKI');
167				var toReplace = this.lookForDKI(dkiElements);
168				if(toReplace.length>0){
169					this.sendAjaxReq('render_ifso_shortcodes',{triggers:JSON.stringify(toReplace),pageload_referrer:referrer_for_pageload,is_dki:true},function(ret){	//Referrer from if-so public
170						try{
171							var data = JSON.parse(ret);
172							$.each(data, function(id,val){
173								dkiElements[id].outerHTML = val;
174							});
175						}
176						catch(e){
177							console.error('Error fetching if-so DKI!');
178							console.error(e);
179						}
180					});
181				}
182			},
183
184			sendAjaxReq : function(action, data, cb) {
185				data['action'] = action;
186				data['nonce'] = ifso_nonce;
187				//data['page_url'] = ifso_page_url;
188				data['page_url'] = window.location.href;
189
190				$.post(ajaxurl, data, function(response) {
191					if (cb)
192						cb(response);
193				});
194			},
195
196			deleteCookie : function( name ) {
197				document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;";
198			},
199
200			initialize_last_viewed_globals : function(){
201				var cookie = this.getCookie('_ifso_last_viewed');
202				try{
203					var cookieObj = JSON.parse(cookie);
204					ifso_viewed_triggers = cookieObj;
205				}
206				catch(err){console.log('ERR! ' + err)}
207			},
208
209			ifso_analytics_do_conversion : function(conversions){
210				var params = {an_action:'doConversion',postid:666, viewed_triggers:JSON.stringify(ifso_viewed_triggers),conversions:JSON.stringify(conversions)};
211				this.sendAjaxReq('ifso_analytics_req',params, function(){});
212			},
213
214			ifso_google_analytcis_events_run : function(){
215				if(!isAnalyticsOn || typeof(gtag)==='undefined' || $('ifsoTriggerAnalyticsEvent').length<=0)
216					return;
217				$.each($('ifsoTriggerAnalyticsEvent'),function(key,value){
218					var event_name = value.getAttribute('event_name');
219					try{var el_event_data = JSON.parse(value.getAttribute('event_data'));}
220					catch (err){el_event_data = {};}
221					var event_data = null;
222					if(event_name==='ifso-trigger-viewed'){
223						var ev_version_name = typeof(el_event_data['version_name'])!=='undefined' && el_event_data['version_name']!==null  ? el_event_data['version_name'] : '';
224						event_data = {ifso_trigger_id:el_event_data['trigger'],ifso_trigger_version:el_event_data['version'],event_label:'ifso-content-viewed'} ;
225						if(ev_version_name!=='')
226							event_data['ifso_trigger_version_name']  = ev_version_name;
227						event_data['event_category'] = 'if-so';
228					}
229					if(event_name==='custom'){
230						var event_data = {};
231						$.each(el_event_data,function(e_attr,e_val){
232							if(e_attr==='ga4_event_type')
233								event_name = e_val;
234							else
235								event_data[e_attr] = e_val;
236						});
237					}
238					if(event_data!==null)
239						gtag('event', event_name,event_data);
240					value.remove();
241				});
242			},
243			lookForAttrsForAjax : function (elem){
244				var ret = {};
245				$.each(ifso_attrs_for_ajax,function (key,value){
246					if(elem.getAttribute(value)!==null)
247						ret[value] = elem.getAttribute(value);
248				});
249				return ret;
250			},
251			lookForTriggerTags : function(trigger){
252				if(isNaN(trigger)){
253					var trigger_atts = JSON.parse(trigger);
254					var tagsSelector = 'IfSoTrigger[tid="'+trigger_atts.id+'"]';
255					Object.keys(trigger_atts).forEach(function (val){if(val!=='id') tagsSelector += '[' + val + '="' + trigger_atts[val] + '"]'});
256				}
257				else{
258					var tagsSelector = 'IfSoTrigger[tid="'+trigger+'"]';
259					ifso_attrs_for_ajax.forEach(function (val){tagsSelector += ':not([' + val + '])';})
260				}
261				return $(tagsSelector);
262			}
263		};
264
265		var ifso_public_instance = new if_so_public();
266
267		ifso_public_instance.replaceLoadLaterTriggers(false);
268		var replace_defered  = function(){
269			ifso_public_instance.replaceLoadLaterTriggers(true);
270			$(document).unbind("click keydown keyup mousemove",replace_defered);
271		};
272		$(document).on('click keydown keyup mousemove',replace_defered);
273		ifso_public_instance.replaceStandaloneConditions();
274		$(document).on('ifso_ajax_conditions_loaded',ifso_public_instance.replaceStandaloneConditions.bind(ifso_public_instance));
275		ifso_public_instance.replaceDkiElements();
276
277		ifso_public_instance.ifso_google_analytcis_events_run();
278		$(document).on('ifso_ajax_content_loaded',ifso_public_instance.ifso_google_analytcis_events_run);
279
280
281		if(isPageVisitedOn || isVisitCountEnabled){	//Passed form if-so public
282			ifso_public_instance.sendAjaxReq('ifso_add_page_visit', {ifso_count_visit:parseInt(isVisitCountEnabled),isfo_save_page_visit:parseInt(isPageVisitedOn)}, function(response){});
283		}
284
285		if(isAnalyticsOn){	//Passed from if-so public
286			ifso_public_instance.initialize_last_viewed_globals();
287
288			if($('.ifso-conversion-complete').length>0){
289				var conversions = [];
290				$.each($('.ifso-conversion-complete'),function(key,value){
291					if(value.getAttribute('completed')!==null) return;
292					var allowed_attr = value.getAttribute('allowed_triggers');
293					var disallowed_attr = value.getAttribute('disallowed_triggers');
294					var once_per_attr = value.getAttribute('once_per_time');
295					var name_attr = value.getAttribute('ifso_name');
296					var conv_type = value.getAttribute('conversion_type');
297					var conversion = {allowed:[],disallowed:[]};
298					if(conv_type!==null)
299						conversion.conversion_type = conv_type;
300					if(allowed_attr!=null && allowed_attr != 'all')
301						conversion.allowed = allowed_attr.split(',');
302					if(disallowed_attr!=null)
303						conversion.disallowed = disallowed_attr.split(',');
304					if(once_per_attr!==null && name_attr!==null){
305						conversion.once_per_time = once_per_attr;
306						conversion.name = name_attr
307					}
308					conversions.push(conversion);
309					value.setAttribute('completed',1);
310				});
311				if(conversions.length>
3110) ifso_public_instance.ifso_analytics_do_conversion(conversions);
312			}
313		}
314
315
316		//Bounce mechanism - not in use for now
317		/*if(getCookie('ifso_bounce')){
318            sendAjaxReq('ifso_analytics_req',{an_action:'decrementField',postid:ifso_last_viewed_trigger.triggerid, versionid:ifso_last_viewed_trigger.versionid, field:'bounce'}, function(){
319                deleteCookie('ifso_bounce')
320            });
321        }
322		window.addEventListener('beforeunload',function(e){
323		    if(!getCookie('ifso_bounce')){
324				createCookie('ifso_bounce');
325                sendAjaxReq('ifso_analytics_req',{an_action:'incrementField',postid:ifso_last_viewed_trigger.triggerid, versionid:ifso_last_viewed_trigger.versionid, field:'bounce'}, function(){});
326            }
327
328		});*/
329	});
330})( jQuery );
331

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.