PageSourceSearch

https://marblehillpublishers.co.uk/js/ehaus.tracker.js

js marblehillpublishers.co.uk collected 2026-09-26 09:24:15 UTC 10,525 bytes, 349 lines download raw bytes

1// 
2/*
3 - EH TRACKER
4 - Switch off old ehTracker scripts: ehaus.functions.init()
5 - include this file in scripts.bottom.inc
6 
7	To track any click events simply ensure class="ehtracker"
8	ALL [data-item-xxx|data-track-yyy] attributes will be logged in the Tracker index
9	
10	Min. requirement data-track-event="some-description-of-the-event"
11	- PLEASE DON'T use underescores for the event description as old db.server's cannot handle this :)
12	
13*/
14// /<![CDATA[
15/******************************************************************************/
16	$(document).ready(function(){
17		
18	// Client IP + Country
19		var eh_data = {}; var geo_data = {}; 
20		var loc = $('body').data('loc');
21		
22		if(!empty(loc)){
23			
24			//console.log("Tracker:loc"); 
25			geo_data.ip =  $('body').data('user-ip');
26			geo_data.country = $('body').data('user-country');
27			geo_data.city =  $('body').data('user-city');
28			geo_data.postal =  $('body').data('user-zip');
29			eh_data = track_page_data(geo_data);
30			track_save(eh_data);	
31		
32		} else {
33			
34			console.log("Tracker:ipapi!! [loc]", loc); 			
35			$.getJSON('https://ipapi.co/json/', function(geo_data) {
36
37			})
38			.done(function(geo_data) { 
39			
40				//console.log("done"); 
41				eh_data = track_page_data(geo_data);
42				
43			})
44			.fail(function() {
45				
46				console.log("https://ipapi.co/json/ lookup failed"); 
47				eh_data = track_page_data();
48				
49			})
50			.always(function() {
51				
52				//console.log("always"); 
53				track_save(eh_data);	// Saves PAGE data per impression
54				//console.log(eh_data);
55				
56			});
57			
58		}
59		
60	// initialise eh_tracker
61		//eh_data = track_page_data();
62		//console.log(eh_data);
63		
64		track_links();			// Initialiases click EVENT listener
65		
66		
67	});	//end docready 
68
69/******************************************************************************/
70/******************************************************************************/
71	function track_links(){
72		
73		var bodyEle = $("body").get(0);
74		//console.log("Tracker:track_links"); 	
75		
76		if(bodyEle.addEventListener){
77			
78		// capture all bubblable click events 	
79			bodyEle.addEventListener("click", function(event){
80				
81				var elem = event.target;
82				
83				if( !$(elem).hasClass('ehtracker') ){
84					elem = event.target.parentNode;
85				}
86				//console.log(elem);
87
88			// if class="ehtracker" then log all data-track-xyz="some-value"
89				if( $(elem).hasClass('ehtracker') ){
90					
91					var $data = track_page_data();	// picks up basic page info
92					$data = track_extract(elem, $data);
93					//console.log( $data );
94					//console.log("Tracker:track_links-do"); 
95					track_save( $data );
96					
97				}
98					
99			}, true);
100			   
101		}else if(bodyEle.attachEvent){		
102		// IE :)	
103		
104			document.attachEvent("onclick", function(){
105				
106				var event = window.event;
107				console.log('InternetExplorer <=v8: eek!');
108				// do the same as above..
109				elem = event.target;
110				if( !$(elem).hasClass('ehtracker') ){
111					elem = event.target.parentNode;
112				}
113				//console.log( elem );
114
115				if( $(elem).hasClass('ehtracker') ){
116					
117					var $data = track_page_data();	
118					$data = track_extract(elem, $data);					
119					track_save( $data );
120					
121				}
122			   
123			});
124	
125		}	// End EventListener
126		
127		
128	}
129	
130/******************************************************************************/
131	function track_extract(elem, $data){
132		
133		
134		$.each($(elem).data(), function(i, v) {
135			
136			//jquery data object converts the keys according to these rules [http://stackoverflow.com/questions/22753629/jquery-get-html-5-data-attributes-with-hyphens-and-case-sensitivity]
137			// here we are restoring the original data-field-name attribute format..
138			// Also filtering data attributes to: [data-item|data-track]
139			if(i.match(/^item|^track/)){
140			
141				//console.log('i:['+i+'] v:['+v+']');
142				var key = i.replace(/(\w)([A-Z]+)/g, "$1\-$2").toLowerCase();
143				$data['data-' + key] =  v ;
144				
145			}
146
147		});
148					
149	// Overwrite the default data-track-type: 'page',
150		$data['data-track-type'] =  $(elem).data('track-type') || 'click';	// [click|page]
151		$data['data-track-event'] =  $(elem).data('track-event');
152		$data['data-track-link'] =  $(elem).attr('href');
153		
154		//console.log($data);
155		
156		return $data;
157		
158		
159	}
160	
161/******************************************************************************/
162/*
163*/
164	function track_save( data ) {
165	
166		data.ax = 'ehtracker';
167		
168		//console.log(data);	
169		//console.log("Tracker:track_save"); 
170		
171		var tbaseurl = give_me_a_baseref() + "include/xml.proxy.php";
172		return $.ajax({
173			type: 'POST',
174			url: tbaseurl,
175			data: data ,
176			dataType: 'html'
177		}).promise();
178		
179	}
180/******************************************************************************/
181/* Gather up as much info about the page that we can..
182	- You may need to modify the selector for picking up the data-user-id
183	- Basically this handles VIEWS
184	- See ehtrackLinks() for CLICK events tracking
185
186*/
187	function track_page_data(geo){
188
189		if (typeof geo === 'undefined'){
190			var geo = {};
191		}
192		//console.log(geo);
193		
194	// Get session_id from cookie
195		var sid = '';
196		if( typeof Cookie === 'object' ) {
197			
198			sid = Cookie.get('sid');
199			//console.log('ehaus.tracker::cookie:[' + sid + ']');
200			
201		}
202	
203	// Get QueryString params [DS/LANG/LOC]
204		var lang = '';
205		if( typeof GetQueryStringParams === 'function' ) {
206			
207			lang = (GetQueryStringParams('lang')) ? GetQueryStringParams('lang') 
208					: ($('body').data('lang')) ? $('body').data('lang') 
209					: ($('body').data('loc')) ? $('body').data('loc') 
210					: '';
211					
212		}
213		
214	// PageName:
215		var page_name = ''; 
216		page_name = $('<img src=>')[0].src; //(works in IE too!)
217		if(!empty(page_name)){
218			page_name = page_name.split('?')[0];
219		}
220		//console.log('page_name:' + page_name);
221	
222	// URL params
223		var pid = ''; var ds = '';
224		if(typeof  document.documentURI != 'undefined'){
225			
226			var idx = document.documentURI.split('/').indexOf('page');
227			if ( idx == -1){
228				// the <body> tag should look like this [<body data-geo-location="GB" data-user-name="[email protected]" data-page-id="index">]
229				pid = $('body').data('pid') || $('body').data('page-id') || 'index';
230			} else {
231				pid = document.documentURI.split('/')[idx+1];
232			}
233			
234			if( typeof GetQueryStringParams === 'function' ) {
235				
236				ds = (GetQueryStringParams('ds')) ? GetQueryStringParams('ds') 
237					: (document.documentURI.split('/')[idx+2]) ? document.documentURI.split('/')[idx+2]
238					: $('.breadcrumb').data('display-string') ;
239			
240			}
241
242		}
243
244	
245	
246	// This will pick up data from all banners on the page (for Banners Viewed)
247	// The Click Event will overwrite these values for Banner Clicks
248		var page_banner_titles = ''; var page_banner_ids = ''; var page_banner_cats = '';
249		$('.ehtracker').each(function(){
250			
251			if (typeof $(this).attr('data-banner-title') !== 'undefined') { page_banner_titles += $(this).attr('data-banner-title') + '|';  }
252			if (typeof $(this).attr('data-banner-id') !== 'undefined') { page_banner_ids += $(this).attr('data-banner-id') + '|';  }
253			if (typeof $(this).attr('data-banner-cat') !== 'undefined') { page_banner_cats += $(this).attr('data-banner-cat') + '|';  }
254
255		});
256				
257		var dataObj = {
258			'ax':						'ehtracker',
259			
260			'data-page-id':				pid,
261			'data-page-ds':				ds,
262			'data-page-title':			document.title,
263			'data-page-lang':			lang,
264			'data-page-cur':			($('body').data('cur')) ? $('body').data('cur') : '',
265			
266		// Lists ALL Banners on this page
267			'data-banner-title':		page_banner_titles,	
268			'data-banner-id':			page_banner_ids,		
269			'data-banner-cat':			page_banner_cats,		// e.g. [logical grouping e.g. free|subscribed|discounted| etc.] - set href		
270
271		// Set default Type = PAGE. This is then overwritten by a CLICK event
272			'data-track-type':			'page',			// e.g. [page|click] - set href/auto
273			'data-track-pagename':		page_name,
274					
275		// Set session-id	
276			'data-session-id': 			sid,
277			'data-user-name':			($('body').data('user-name')) ? $('body').data('user-name') : 'not-logged-in',
278			'data-user-company':		($('body').data('user-company')) ? $('body').data('user-company') : 'no-user-company',
279			'data-user-search':			($('body').data('user-search')) ? $('body').data('user-search') : '',
280			'data-geo-location':		geo.country || $('body').data('loc') || '',	
281			'data-geo-ip':				geo.ip || '',
282			'data-geo-city':			geo.city || '',			
283			'data-geo-postal':			geo.postal || '',			
284
285			
286			'data-uri-host':			location.host,
287			'data-uri-path':			location.pathname,
288			'data-uri-qs':				location.search.replace(/\?/g, ''),
289			'data-uri-domain':			document.domain,
290			'data-uri-referrer':		geo.ip || document.referrer,
291			
292		}
293		
294		var item_pages = ['detail', 'title-detail']; // i.e. list all page-names you want to log item details off of
295		if($.inArray(pid, item_pages) !== -1 ){
296			
297			dataObj['data-item-id'] = 			$('.ehtracker:first').attr('data-item-id') || $('.ehtracker:first').attr('data-id');
298			dataObj['data-item-category'] = 	$('.ehtracker:first').attr('data-item-category');
299			dataObj['data-item-name'] = 		$('.ehtracker:first').attr('data-item-name');
300			dataObj['data-item-price'] = 		strip($('.ehtracker:first').attr('data-item-price'));
301			dataObj['data-item-price-vip'] =	$('.ehtracker:first').attr('data-item-price-vip');
302			dataObj['data-item-price-url'] =	$('.ehtracker:first').attr('data-item-price-url');
303			dataObj['data-track-event'] =		'titledetail';
304			
305			
306		}
307		
308		//console.log(dataObj);
309		
310		return dataObj;
311
312	}
313
314		
315	function pairs_to_arr( str ) {
316		
317		
318		if(typeof URLSearchParams !== 'undefined'){
319			
320			var obj = Object.fromEntries(new URLSearchParams(str));
321			//console.log(obj);
322			return obj;
323			
324		} else {
325		// IE doesn't like URLSearchParams
326			var vars = str.split('&'); var obj = {};
327			for (var i = 0; i < vars.length; i++) {
328				
329				var pair = vars[i].split('=');
330				obj[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
331				
332		}
333			//console.log(obj);
334		return obj;
335		}
336		
337		
338	}
339
340/******************************************************************************/
341	function strip(html){
342		
343	   var tmp = document.implementation.createHTMLDocument("New").body;
344	   tmp.innerHTML = html;
345	   return tmp.textContent || tmp.innerText || "";
346	   
347	}
348
349// ]]>

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.