PageSourceSearch

https://www.cementtileshop.com/mm5/clientside.mvc?T=c9e80f5d&Module_Code=mvga&Filename=mvga.js

js cementtileshop.com collected 2026-09-25 20:33:29 UTC 23,153 bytes, 817 lines download raw bytes

1// Miva Merchant
2//
3// This file and the source codes contained herein are the property of
4// Miva, Inc.  Use of this file is restricted to the specific terms and
5// conditions in the License Agreement associated with this file.  Distribution
6// of this file or portions of this file for uses not covered by the License
7// Agreement is not allowed without a written agreement signed by an officer of
8// Miva, Inc.
9//
10// Copyright 1998-2021 Miva, Inc.  All rights reserved.
11// http://www.miva.com
12//
13
14function MVGA_Tracker( product_link_prefix, category_name, product_code, product_name, mvga_basketitems, mvga_orderitems )
15{
16	this.category_name			= category_name;
17	this.product_link_prefix	= product_link_prefix;
18	this.product_code 			= product_code;
19	this.product_name 			= product_name;
20	this.basketitems			= mvga_basketitems;
21	this.orderitems				= mvga_orderitems;
22
23	this.basketitems_lookup		= [];
24	this.orderitems_lookup		= [];
25
26	this.product_links			= [];
27	this.product_attributes		= [];
28	this.upsell_products		= [];
29
30	this.main_product_form		= null;
31	
32	this.Page_Dispatch();
33}
34
35MVGA_Tracker.prototype.Page_Dispatch = function()
36{
37	if ( Screen == 'BASK' )			this.Process_BASK();
38	else if ( Screen == 'PROD' )	this.Process_PROD();
39	else if ( Screen == 'OUS1' ) 	this.Process_OUS1(); 
40	else if ( Screen == 'OUSM' ) 	this.Process_OUSM(); 
41	else if ( Screen == 'OSEL' ) 	this.Process_OSEL(); 
42
43	if ( Screen == 'CTGY' ||
44  		 Screen == 'PLST' ||
45  		 Screen == 'PROD' ||
46		 Screen == 'SRCH' )		
47	{
48		this.Process_List_Page();
49	}
50}
51
52MVGA_Tracker.prototype.Process_BASK = function()
53{
54	var self = this;
55	var i, i_len, form_action, page_remove_links, page_remove_forms;
56
57	page_remove_links = document.getElementsByTagName( 'a' );
58	page_remove_forms = document.getElementsByTagName( 'form' );
59
60	for ( i = 0, i_len = page_remove_links.length; i < i_len; i++ )
61	{
62		if ( page_remove_links[ i ].href.indexOf( 'Action=RGRP' ) == -1 && page_remove_links[ i ].href.indexOf( 'Action=RPRD' ) == -1 ) continue;
63		
64		AddEvent( page_remove_links[ i ], 'click', function( e )
65		{
66			return self.RemoveFromBasketLinks( e );
67		} );
68	}
69
70	for ( i = 0, i_len = page_remove_forms.length; i < i_len; i++ )
71	{
72		form_action = page_remove_forms[ i ].elements[ 'Action' ];
73
74		if ( !form_action ) continue;
75
76		if ( form_action.value == 'RGRP' || form_action.value == 'RPRD' )
77		{
78			AddEvent( page_remove_forms[ i ], 'submit', function( e )
79			{
80				return self.RemoveFromBasketForms( e );
81			} );
82		}
83		else if ( form_action.value == 'QNTY' || form_action.value == 'QTYG' )
84		{
85			AddEvent( page_remove_forms[ i ], 'submit', function( e )
86			{
87				return self.UpdateBasketQuantity( e );
88			} );
89		}
90	}
91
92	this.Build_BasketAndOrderItem_Lookup();
93}
94
95MVGA_Tracker.prototype.RemoveFromBasketForms = function( e )
96{
97	var remove_form, basketitem_id;
98
99	e 				= e || window.event;
100	remove_form 	= e.srcElement || e.target;
101
102	if ( !remove_form || !remove_form.elements ) return true;
103
104	basketitem_id	= remove_form.elements[ 'Basket_Group' ] || remove_form.elements[ 'Basket_Line' ];
105
106	if ( !basketitem_id ) return true;
107
108	ga( 'require', 'ec' );
109
110	ga( 'ec:addProduct', 
111	{
112		'id'		: this.basketitems_lookup[ basketitem_id.value ].code,
113		'name'		: this.basketitems_lookup[ basketitem_id.value ].name,
114		'quantity'	: this.basketitems_lookup[ basketitem_id.value ].quantity
115	} );
116
117	ga( 'ec:setAction', 'remove' );
118
119	ga( 'send', 'event', 'remove_button', 'click', 'remove from cart', { 'hitCallback': function()
120	{
121		remove_form.submit();
122	} } );
123
124	return eventPreventDefault( e );
125}
126
127MVGA_Tracker.prototype.RemoveFromBasketLinks = function( e )
128{
129	var i, i_len, remove_element, parameters, basketitem_id;
130
131	e 				= e || window.event;
132	remove_element 	= e.srcElement || e.target;
133
134	if ( !remove_element.href ) return true;
135
136	parameters = remove_element.href.split( '&' );
137
138	for ( i = 0, i_len = parameters.length; i < i_len; i++ )
139	{
140		if ( parameters[ i ].indexOf( 'Basket_Group=' ) != -1 )			basketitem_id = parameters[ i ].substring( parameters[ i ].indexOf( 'Basket_Group=' ) + 13 );
141		else if ( parameters[ i ].indexOf( 'Basket_Line=' ) != -1 )		basketitem_id = parameters[ i ].substring( parameters[ i ].indexOf( 'Basket_Line=' ) + 12 );
142	}
143
144	if ( !basketitem_id ) return true;
145
146	ga( 'require', 'ec' );
147
148	ga( 'ec:addProduct', 
149	{
150		'id'		: this.basketitems_lookup[ basketitem_id ].code,
151		'name'		: this.basketitems_lookup[ basketitem_id ].name,
152		'quantity'	: this.basketitems_lookup[ basketitem_id ].quantity
153	} );
154
155	ga( 'ec:setAction', 'remove' );
156
157	ga( 'send', 'event', 'remove_button', 'click', 'remove from cart', { 'hitCallback': function()
158	{
159		document.location.href = remove_element.href;
160	} } );
161
162	return eventPreventDefault( e );
163}
164
165MVGA_Tracker.prototype.UpdateBasketQuantity = function( e )
166{
167	var quantity_form, basketitem_id, quantity;
168
169	e 				= e || window.event;
170	quantity_form 	= e.srcElement || e.target;
171
172	if ( !quantity_form || !quantity_form.elements ) return true;
173
174	basketitem_id	= quantity_form.elements[ 'Basket_Line' ] || quantity_form.elements[ 'Basket_Group' ];
175	quantity		= quantity_form.elements[ 'Quantity' ];
176
177	if ( !basketitem_id || !quantity ) return true;
178
179	ga( 'require', 'ec' );
180
181	if ( quantity.value > this.basketitems_lookup[ basketitem_id.value ].quantity )
182	{
183		ga( 'ec:addProduct', 
184		{
185			'id'		: this.basketitems_lookup[ basketitem_id.value ].code,
186			'name'		: this.basketitems_lookup[ basketitem_id.value ].name,
187			'quantity'	: quantity.value - this.basketitems_lookup[ basketitem_id.value ].quantity
188		} );
189
190		ga( 'ec:setAction', 'add' );
191
192		ga( 'send', 'event', 'update_quantity', 'click', 'Update basket quantity', { 'hitCallback': function()
193		{
194			quantity_form.submit();
195		} } );
196	}
197	else if ( quantity.value < this.basketitems_lookup[ basketitem_id.value ].quantity )
198	{
199		ga( 'ec:addProduct', 
200		{
201			'id'		: this.basketitems_lookup[ basketitem_id.value ].code,
202			'name'		: this.basketitems_lookup[ basketitem_id.value ].name,
203			'quantity'	: this.basketitems_lookup[ basketitem_id.value ].quantity - quantity.value 
204		} );
205
206		ga( 'ec:setAction', 'remove' );
207
208		ga( 'send', 'event', 'update_quantity', 'click', 'Update basket quantity', { 'hitCallback': function()
209		{
210			quantity_form.submit();
211		} } );
212	}
213
214	return eventPreventDefault( e );
215}
216
217MVGA_Tracker.prototype.Process_PROD = function()
218{
219	this.Find_PROD_ADPR_Forms();
220}
221
222MVGA_Tracker.prototype.Find_PROD_Attributes = function()
223{
224	var i, name, index;
225
226	if ( !this.main_product_form || !this.main_product_form.elements ) return;
227
228	for ( i = 0; i < this.main_product_form.elements.length; i++ )
229	{
230		if ( typeof this.main_product_form.elements[ i ].type !== 'string' ||
231			 typeof this.main_product_form.elements[ i ].name !== 'string' )															continue;
232		if ( this.main_product_form.elements[ i ].type.toLowerCase() != 'hidden' )														continue;
233		if ( this.main_product_form.elements[ i ].name.indexOf( ']:code' ) != this.main_product_form.elements[ i ].name.length - 6 )	continue;
234		if ( this.main_product_form.elements[ i ].name.indexOf( 'Product_Attributes[' ) != 0 )											continue;
235
236		name	= this.main_product_form.elements[ i ].name.replace( /Product_Attributes\[/g, '' );
237		name	= name.replace( / /g, '' );
238		name	= name.replace( /\]:code/g, '' );
239
240		index	= parseInt( name );
241
242		this.product_attributes[ index ] 		= new Object();
243		this.product_attributes[ index ].code	= this.main_product_form.elements[ i ].value; 
244		this.product_attributes[ index ].value	= '';
245	}
246
247	for ( i = 0; i < this.main_product_form.elements.length; i++ )
248	{
249		if ( typeof this.main_product_form.elements[ i ].type !== 'string' ||
250			 typeof this.main_product_form.elements[ i ].name !== 'string' )															continue;
251		if ( this.main_product_form.elements[ i ].name.indexOf( ']:value' ) != this.main_product_form.elements[ i ].name.length - 7 )	continue;
252		if ( this.main_product_form.elements[ i ].name.indexOf( 'Product_Attributes[' ) != 0 )											continue;
253		if ( this.main_product_form.elements[ i ].disabled )																			continue;
254
255		name	= this.main_product_form.elements[ i ].name.replace( /Product_Attributes\[/g, '' );
256		name	= name.replace( / /g, '' );
257		name	= name.replace( /\]:value/g, '' );
258		name 	= parseInt( name );
259
260		if ( this.main_product_form.elements[ i ].type.toLowerCase() == 'select-one' )
261		{
262			this.product_attributes[ name ].value = encodeURIComponent( this.main_product_form.elements[ i ].options[ this.main_product_form.elements[ i ].selectedIndex ].value );
263		}
264		else if ( this.main_product_form.elements[ i ].type.toLowerCase() == 'radio' )
265		{
266			if ( this.main_product_form.elements[ i ].checked ) this.product_attributes[ name ].value = encodeURIComponent( this.main_product_form.elements[ i ].value );
267		}
268		else if ( this.main_product_form.elements[ i ].type.toLowerCase() == 'checkbox' )
269		{
270			if ( this.main_product_form.elements[ i ].checked )	this.product_attributes[ name ].value = encodeURIComponent( this.main_product_form.elements[ i ].value );
271		}
272		else if ( this.main_product_form.elements[ i ].type == 'text' )
273		{
274			if ( this.main_product_form.elements[ i ].value.length ) this.product_attributes[ name ].value = 'populated';
275		}
276		else if ( this.main_product_form.elements[ i ].type == 'textarea' )
277		{
278			if ( this.main_product_form.elements[ i ].value.length ) this.product_attributes[ name ].value = 'populated';
279		}
280	}
281}
282
283MVGA_Tracker.prototype.Find_PROD_ADPR_Forms = function()
284{
285	var self = this;
286	var i, i_len, action, page_forms, product_code;
287
288	page_forms = document.getElementsByTagName( 'form' );
289
290	for ( i = 0, i_len = page_forms.length; i < i_len; i++ )
291	{
292		action			= page_forms[ i ].elements[ 'Action' ];
293		product_code	= page_forms[ i ].elements[ 'Product_Code' ];
294
295		if ( !action || !product_code ) 			continue;
296		if ( action.value != 'ADPR' )				continue;
297
298		if ( product_code.value != Product_Code )	continue;
299	
300		AddEvent( page_forms[ i ], 'submit', function( e )
301		{
302			self.Find_PROD_Attributes();
303			self.AddToBasketSubmit( e );
304		} );
305
306		this.main_product_form = page_forms[ i ];
307		break;
308	}
309}
310
311MVGA_Tracker.prototype.Process_OUS1 = function()
312{
313	var self = this;
314	var i, i_len, action, page_forms, product_code;
315
316	page_forms = document.getElementsByTagName( 'form' );
317
318	for ( i = 0, i_len = page_forms.length; i < i_len; i++ )
319	{
320		action			= page_forms[ i ].elements[ 'Action' ];
321		product_code	= page_forms[ i ].elements[ 'Product_Code' ];
322
323		if ( !action || !product_code )	continue;
324		if ( action.value != 'AUPR' )	continue;
325
326		AddEvent( page_forms[ i ], 'submit', function( e )
327		{
328			return self.UpsellOUS1FormSubmit( e );
329		} );
330	}
331}
332
333MVGA_Tracker.prototype.Process_OUSM = function()
334{
335	var self = this;
336	var i, i_len, action, page_forms;
337
338	page_forms = document.getElementsByTagName( 'form' );
339
340	for ( i = 0, i_len = page_forms.length; i < i_len; i++ )
341	{
342		action = page_forms[ i ].elements[ 'Action' ];
343
344		if( !action || action.value != 'AUPM' )	continue;
345
346		AddEvent( page_forms[ i ], 'submit', function( e )
347		{
348			self.Find_OUSM_Selection( e );
349			return self.UpsellFormSubmit( e );
350		} );
351
352		break;
353	}
354}
355
356MVGA_Tracker.prototype.UpsellOUS1FormSubmit = function( e )
357{
358	var upsell_form, product_code;
359
360	e 			= e || window.event;
361	upsell_form = e.srcElement || e.target;
362
363	if ( !upsell_form || !upsell_form.elements ) return true;
364
365	product_code	= upsell_form.elements[ 'Product_Code' ];	
366
367	if ( !product_code ) return true;
368
369	ga( 'require', 'ec' );
370
371	ga( 'ec:addProduct', 
372	{
373		'name'		: product_code.value,
374		'quantity'	: 1 
375	} );
376
377	ga( 'ec:setAction', 'add' );
378
379	ga( 'send', 'event', 'upsell_add_to_cart', 'click', 'Upsell', { 'hitCallback': function()
380	{
381		upsell_form.submit();
382	} } );
383
384	return eventPreventDefault( e );
385}
386
387MVGA_Tracker.prototype.UpsellFormSubmit = function( e )
388{
389	var i, upsell_form;
390
391	e 			= e || window.event;
392	upsell_form = e.srcElement || e.target;
393
394	if ( !upsell_form || !upsell_form.elements ) return true;
395
396	ga( 'require', 'ec' );
397
398	for ( i = 0; i < this.upsell_products.length; i++ )
399	{
400		if ( !this.upsell_products[ i ] ) continue;
401
402		ga( 'ec:addProduct', 
403		{
404			'name'		: this.upsell_products[ i ].code,
405			'quantity'	: 1 
406		} );
407	}
408	
409	ga( 'ec:setAction', 'add' );
410
411	ga( 'send', 'event', 'upsell_add_to_cart', 'click', 'Upsell', { 'hitCallback': function()
412	{
413		upsell_form.submit();
414	} } );
415
416	return eventPreventDefault( e );
417}
418
419MVGA_Tracker.prototype.Find_OUSM_Selection = function( e )
420{
421	var i, name, index, ousm_form;
422	
423	e 			= e || window.event;
424	ousm_form 	= e.srcElement || e.target;
425
426	if ( !ousm_form || !ousm_form.elements ) return;
427
428	for ( i = 0; i < ousm_form.elements.length; i++ )
429	{
430		if ( typeof ousm_form.elements[ i ].type !== 'string' ||
431			 typeof ousm_form.elements[ i ].name !== 'string' )												continue;
432		if ( ousm_form.elements[ i ].type.toLowerCase() != 'hidden' )										continue;
433		if ( ousm_form.elements[ i ].name.indexOf( ']:code' ) != ousm_form.elements[ i ].name.length - 6 )	continue;
434		if ( ousm_form.elements[ i ].name.indexOf( 'Product[' ) != 0 )										continue;
435
436		name	= ousm_form.elements[ i ].name.replace( /Product\[/g, '' );
437		name	= name.replace( / /g, '' );
438		name	= name.replace( /\]:code/g, '' );
439
440		index	= parseInt( name );
441
442		this.upsell_products[ index ] 		= new Object();
443		this.upsell_products[ index ].code	= ousm_form.elements[ i ].value; 
444		this.upsell_products[ index ].value	= '';
445	}
446
447	for ( i = 0; i < ousm_form.elements.length; i++ )
448	{
449		if ( typeof ousm_form.elements[ i ].type !== 'string' ||
450			 typeof ousm_form.elements[ i ].name !== 'string' )											continue;
451		if ( ousm_form.elements[ i ].type.toLowerCase() != 'checkbox' )									continue;
452		if ( ousm_form.elements[ i ].name.indexOf( ']' ) != ousm_form.elements[ i ].name.length - 1 )	continue;
453		if ( ousm_form.elements[ i ].name.indexOf( 'Upsell_Selected[' ) != 0 )							continue;
454		if ( ousm_form.elements[ i ].disabled )															continue;
455
456		name	= ousm_form.elements[ i ].name.replace( /Upsell_Selected\[/g, '' );
457		name	= name.replace( / /g, '' );
458		name	= name.replace( /\]/g, '' );
459		name 	= parseInt( name );
460
461		if ( ousm_form.elements[ i ].checked )
462		{
463			this.upsell_products[ name ].value = encodeURIComponent( ousm_form.elements[ i ].value );
464		}
465	}
466}
467
468MVGA_Tracker.prototype.Process_OSEL = function()
469{
470	var self = this;
471	var i, page_forms, form_payment, form_shipping;
472
473	page_forms = document.getElementsByTagName( 'form' );
474
475	for ( i = 0; i < page_forms.length; i++ )
476	{
477		form_shipping 	= page_forms[ i ].elements[ 'ShippingMethod' ];
478		form_payment 	= page_forms[ i ].elements[ 'PaymentMethod' ];
479
480		if ( !form_shipping || !form_payment ) continue;
481
482		this.Build_BasketAndOrderItem_Lookup();
483
484		AddEvent( page_forms[ i ], 'submit', function( e )
485		{
486			return self.OSELFormSubmit( e );
487		} );
488
489		break;
490	}
491}
492
493MVGA_Tracker.prototype.OSELFormSubmit = function( e )
494{
495	var osel_form, shipping_selector, payment_selector, shipping_selection, payment_selection;
496
497	e 					= e || window.event;
498	osel_form			= e.srcElement || e.target; 
499
500	if ( !osel_form || !osel_form.elements ) return true;
501
502	shipping_selector	= osel_form.elements[ 'ShippingMethod' ];
503	payment_selector	= osel_form.elements[ 'PaymentMethod' ];
504
505	if ( shipping_selector instanceof HTMLSelectElement )	shipping_selection	= shipping_selector.selectedIndex < 0 ? '' : shipping_selector.options[ shipping_selector.selectedIndex ].value;
506	else if ( shipping_selector )							shipping_selection	= shipping_selector.value;
507	else													shipping_selection	= '';
508
509	if ( payment_selector instanceof HTMLSelectElement )	payment_selection	= payment_selector.selectedIndex < 0 ? '' : payment_selector.options[ payment_selector.selectedIndex ].value;
510	else if ( payment_selector )							payment_selection	= payment_selector.value;
511	else													payment_selection	= '';
512
513	ga( 'ec:setAction', 'checkout_option', { 'step': 1, 'option': shipping_selection + ', ' + payment_selection } );
514
515	ga( 'send', 'event', 'Checkout', 'Option', 
516	{
517		hitCallback: function()
518		{
519			if ( osel_form ) osel_form.submit();
520		}
521	} );
522
523	return eventPreventDefault( e );
524}
525
526MVGA_Tracker.prototype.AddToBasketSubmit = function( e )
527{
528	var product_form, product_code, quantity;
529	
530	e 				= e || window.event;
531	product_form 	= e.srcElement || e.target;
532
533	if ( !product_form || !product_form.elements ) return true; 
534
535	product_code	= product_form.elements[ 'Product_Code' ];
536	quantity		= product_form.elements[ 'Quantity' ];
537
538	if ( !product_code || !quantity ) return true;
539
540	ga( 'require', 'ec' );
541
542	ga( 'ec:addProduct', 
543	{
544		'id'		: product_code.value,
545		'name'		: product_code.value,
546		'quantity'	: quantity ? parseInt( quantity.value ) : 1,
547		'variant'	: this.Generate_Variant_Label(),
548		'category'	: this.category_name
549	} );
550
551	ga( 'ec:setAction', 'add' );
552
553	ga( 'send', 'event', 'detail_add_to_cart', 'click', 'add to cart', { 'hitCallback': function()
554	{
555		product_form.submit();
556	} } );
557
558	return eventPreventDefault( e );
559}
560
561MVGA_Tracker.prototype.Generate_Variant_Label = function()
562{
563	var i, i_len, label;
564
565	label = '';
566
567	for ( i = 0, i_len = this.product_attributes.length; i < i_len; i++ )
568	{
569		if ( !this.product_attributes[ i ] ) continue;
570
571		if ( this.product_attributes[ i ].value )
572		{
573			if ( label.length ) label += ', ';
574			label += this.product_attributes[ i ].code + ': ' + this.product_attributes[ i ].value;
575		}	
576	}
577
578	return label;
579}
580
581MVGA_Tracker.prototype.List_AddToBasketSubmit = function( e )
582{
583	var product_form, product_code;
584
585	e 				= e || window.event;
586	product_form	= e.srcElement || e.target;
587	
588	if ( !product_form || !product_form.elements ) return true;
589
590	product_code	= product_form.elements[ 'Product_Code' ];
591
592	if ( !product_code ) return true;
593
594	ga( 'require', 'ec' );
595
596	ga( 'ec:addProduct', 
597	{
598		'id'		: product_code.value,
599		'name'		: product_code.value,
600		'quantity'	: 1,
601		'category'	: this.category_name
602	} );
603	
604	ga( 'ec:setAction', 'add', { 'list' : this.Get_Listing_Label( Screen ) } );
605
606	ga( 'send', 'event', 'list_add_to_cart', 'click', 'add to cart', { 'hitCallback': function()
607	{
608		product_form.submit();
609	} } );
610
611	return eventPreventDefault( e );
612}
613
614MVGA_Tracker.prototype.Find_List_ADPR_Forms = function()
615{
616	var self = this;
617	var i, i_len, action, page_forms, product_code;
618
619	page_forms = document.getElementsByTagName( 'form' );
620
621	for ( i = 0, i_len = page_forms.length; i < i_len; i++ )
622	{
623		action			= page_forms[ i ].elements[ 'Action' ];
624		product_code	= page_forms[ i ].elements[ 'Product_Code' ];
625
626		if ( !action || !product_code ) 			continue;
627		if ( product_code.value == Product_Code ) 	continue;
628		if ( action.value != 'ADPR' )				continue;
629	
630		AddEvent( page_forms[ i ], 'submit', function( e )
631		{
632			return self.List_AddToBasketSubmit( e );
633		} );
634	}
635}
636
637MVGA_Tracker.prototype.Process_List_Page = function()
638{
639	var self = this;
640	var i, i_len, page_links;
641
642	page_links	= document.getElementsByTagName( 'a' );
643
644	for ( i = 0, i_len = page_links.length; i < i_len; i++ )
645	{
646		if ( page_links[ i ].getAttribute( 'data-mm-linktype' ) === 'product-list-link' )
647		{
648			AddEvent( page_links[ i ], 'click', function( e )
649			{
650				return self.ProductLinkClick( e );
651			} );
652		}
653	}
654
655	this.Find_List_ADPR_Forms();
656}
657
658MVGA_Tracker.prototype.ProductLinkClick = function( e )
659{
660	var i, i_len, product, product_code, product_link, element_product;
661
662	e				= e || window.event;
663	product			= null;
664	element_product	= e.srcElement || e.target;
665
666	if ( !( element_product instanceof HTMLElement ) )
667	{
668		return true;
669	}
670
671	if ( element_product.nodeName == 'IMG' )
672	{
673		element_product = element_product.parentNode;
674	}
675
676	if ( typeof element_product.href !== 'string' || element_product.href.length === 0 )
677	{
678		return true;
679	}
680
681	if ( element_product.hasAttribute( 'data-product-code' ) )
682	{
683		product_code = element_product.getAttribute( 'data-product-code' );
684
685		for ( i = 0, i_len = mvga_productlist.length; i < i_len; i++ )
686		{
687			if ( mvga_productlist[ i ].code === product_code )
688			{
689				product = mvga_productlist[ i ];
690				break;
691			}
692		}
693	}
694
695	if ( product === null )
696	{
697		product_link = element_product.href;
698
699		for ( i = 0, i_len = mvga_productlist.length; i < i_len; i++ )
700		{
701			if ( mvga_productlist[ i ].link === product_link )
702			{
703				product = mvga_productlist[ i ];
704				break;
705			}
706		}
707	}
708
709	if ( product === null )
710	{
711		return true;
712	}
713
714	ga( 'require', 'ec' );
715
716	ga( 'ec:addProduct', 
717	{
718		'id'		: product.code,
719		'name'		: product.name,
720		'category'	: this.category_name,
721		'position'	: product.position
722	} );
723
724	ga( 'ec:setAction', 'click', { 'list' : this.Get_Listing_Label( Screen ) } );
725
726	ga( 'send', 'event', 'product_list_click', 'click', 'View Product Details', { 'hitCallback': function()
727	{ 
728		document.location.href = element_product.href;
729	} } );
730
731	return eventPreventDefault( e );
732}
733
734MVGA_Tracker.prototype.Build_BasketAndOrderItem_Lookup = function()
735{
736	var i, i_len;
737
738	for ( i = 0, i_len = this.basketitems.length; i < i_len; i++ )
739	{
740		this.basketitems_lookup[ this.basketitems[ i ].line_id ] 			= new Object();
741		this.basketitems_lookup[ this.basketitems[ i ].line_id ].code 		= this.basketitems[ i ].code;
742		this.basketitems_lookup[ this.basketitems[ i ].line_id ].name		= this.basketitems[ i ].name;
743		this.basketitems_lookup[ this.basketitems[ i ].line_id ].price 		= this.basketitems[ i ].price;
744		this.basketitems_lookup[ this.basketitems[ i ].line_id ].quantity 	= this.basketitems[ i ].quantity;
745	}
746
747	for ( i = 0, i_len = this.orderitems.length; i < i_len; i++ )
748	{
749		this.orderitems_lookup[ this.orderitems[ i ].line_id ] 				= new Object();
750		this.orderitems_lookup[ this.orderitems[ i ].line_id ].code 		= this.orderitems[ i ].code;
751		this.orderitems_lookup[ this.orderitems[ i ].line_id ].name			= this.orderitems[ i ].name;
752		this.orderitems_lookup[ this.orderitems[ i ].line_id ].price		= this.orderitems[ i ].price;
753		this.orderitems_lookup[ this.orderitems[ i ].line_id ].quantity 	= this.orderitems[ i ].quantity;
754	}
755}
756
757MVGA_Tracker.prototype.Get_Listing_Label = function( screen )
758{
759	switch ( screen )
760	{
761		case 'PROD' :	return 'Related Products';
762		case 'CTGY' :	return 'Category Listing';
763		case 'PLST' :	return 'All Products';
764		case 'SRCH' :	return 'Search Results';
765	}
766}
767
768function getScopedElementsByClassName( className, scope )
769{
770    var regex_match, all_elements, results, i;
771    
772    regex_match     = new RegExp( "(?:^|\\s)" + className + "(?:$|\\s)" );
773    all_elements    = scope.getElementsByTagName( '*' );
774    results         = [];
775    
776    for ( i = 0; all_elements[ i ] != null; i++ )
777    {
778		if ( all_elements[ i ].className && ( all_elements[ i ].className.indexOf( className ) != -1 ) && regex_match.test( all_elements[ i ].className ) )
779		{
780			results.push( all_elements[ i ] );
781		}
782    }
783    
784    return results;
785}
786
787function AddEvent( obj, eventType, fn  )
788{
789	try
790	{
791		obj.addEventListener( eventType, fn, false );
792		return true;
793	}
794	catch ( e )
795	{
796		try
797		{
798			return obj.attachEvent( 'on' + eventType, fn );
799		}
800		catch ( e )
801		{
802			return false;
803		}
804	}
805}
806
807function eventPreventDefault( event )
808{
809	if ( event.preventDefault )
810	{
811		return event.preventDefault();
812	}
813
814	event.returnValue = false;
815
816	return false;
817}

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.