Thank you for your booking
function turitop_booking_system_thank_page() {}
turitop_booking_system_thank_page.prototype.init = function(){
/* ############################################ #### Parameter from google ads #### ############################################ */
this.send_to = []; this.send_to.push( ' ' ); /* ############################################ */
/* ############################################ */
/* ############################################ #### Parameter from google analytics 4 #### ############################################ */ this.ga4 = 'G-KZ7R6XGBJZ'; /* ############################################ */
this.current_url = window.location.search; this.current_url_params = new URLSearchParams( this.current_url );
/* ############################################ #### Parameter from facebook ads #### ############################################ */ this.fbpixel = '986689315098754'; if (typeof this.fbpixel === 'undefined' || typeof this.fbpixel === null || 0 === this.fbpixel.length){ this.fbpixel = this.current_url_params.get( 'fbpixel' ); }
this.sPageURL = decodeURIComponent( window.location.search.substring( 1 ) ); this.currency = this.current_url_params.get( 'currency' ); this.base_url = this.current_url_params.get( 'd' ); this.lang = this.current_url_params.get( 'lang' ); this.csid = this.current_url_params.get( 'csid' ); this.company_name = this.current_url_params.get( 'company_name' ); this.product_short_id = this.current_url_params.get( 'product_short_id' ); this.product_name = this.current_url_params.get( 'product_name' ); this.shopping_cart_id = this.current_url_params.get( 'shopping_cart_id' ); this.multiclient_hash = this.current_url_params.get( 'multi_client_hash' ); this.totals = 0; this.transaction_id = '';
this.tickets = [];
this.events();
};
turitop_booking_system_thank_page.prototype.events = function(){
this.get_totals();
this.get_transaction_id();
this.send_purchase_event_to_google_ads();
this.send_purchase_event_to_facebook_ads();
this.send_purchase_event_to_google_analytics_4();
};
turitop_booking_system_thank_page.prototype.getUrlParameter = function( sParam ){
var array =[] var sURLVariables = this.sPageURL.split('&'); for ( var i = 0; i < sURLVariables.length; i++ ) { var sParameterName = sURLVariables[ i ].split( '=' ); if ( sParameterName[ 0 ] == sParam ) { array.push( sParameterName[ 1 ] ); } } return array; }; turitop_booking_system_thank_page.prototype.get_totals = function(){ var total = this.getUrlParameter( 'total[]' ); if ( ! total || 0 === total.length || typeof total == 'undefined' ){ this.total = this.current_url_params.get( 'total' ); } else{ var out = parseFloat( 0 ); for ( var i in total ) { out = out + parseFloat( total[i] ); } this.total = out; } }; turitop_booking_system_thank_page.prototype.get_transaction_id = function(){ var booking_id = this.getUrlParameter( 'booking_id[]' ); if ( ! booking_id || 0 === booking_id.length || typeof booking_id == 'undefined' ){ this.transaction_id = this.current_url_params.get( 'booking_id' ); var ticket = { booking_id: this.transaction_id, url: this.base_url + this.current_url_params.get( 'link' ), price: this.total } this.tickets.push( ticket ); } else{ var link = this.getUrlParameter( 'link[]' ); var price = this.getUrlParameter( 'price[]' ); var out = ''; var cart_id = ''; var multiclient = ''; if ( this.shopping_cart_id || 0 != this.shopping_cart_id.length || typeof this.shopping_cart_id != 'undefined' ){ cart_id = this.shopping_cart_id; } if ( this.multiclient_hash || 0 != this.multiclient_hash.length || typeof this.multiclient_hash != 'undefined' ){ multiclient = this.multiclient_hash; } for ( var i in booking_id ) { var ticket = { booking_id: booking_id[ i ], url: this.base_url + link[ i ], price: price[ i ], cart_id: cart_id, multiclient: multiclient } this.tickets.push( ticket ); out += "-Booking-" + booking_id[ i ]; this.buttons = []; } this.transaction_id = out; } }; turitop_booking_system_thank_page.prototype.send_purchase_event_to_google_ads = function(){ for ( var i in this.send_to ) { gtag('event', 'conversion', { 'send_to': this.send_to[ i ], 'value': this.total, 'currency': this.currency, 'transaction_id': this.transaction_id }); } }; turitop_booking_system_thank_page.prototype.send_purchase_event_to_facebook_ads = function(){ if ( 0 != this.fbpixel.length ){ fbq( 'track', 'Purchase', { 'value': this.total, 'currency': this.currency }); } }; turitop_booking_system_thank_page.prototype.send_purchase_event_to_google_analytics_4 = function(){ if ( 0 != this.ga4.length ){ var tid = ''; gtag('config', this.ga4 ); for ( var i in this.tickets ) { if ( this.tickets[i].multiclient || 0 != this.tickets[i].multiclient.length || typeof this.tickets[i].multiclient != 'undefined' ){ tid = this.tickets[i].multiclient; } else if ( this.tickets[i].cart_id || 0 != this.tickets[i].cart_id.length || typeof this.tickets[i].cart_id != 'undefined'){ tid = this.tickets[i].cart_id; } else { tid = this.tickets[i].booking_id; } gtag('event', 'purchase', { 'transaction_id': tid, //IF shopping cart, shopping cart id, IF multiclient, multiclient hash, ELSE, booking number 'currency': this.currency, // local currency code 'value': this.total, //Valor total 'items': [ { //one item per product bought 'item_id': this.product_short_id, //Short_id product 'item_name': this.product_name, //Nombre del producto en idioma original 'item_brand': this.csid + '-' + this.company_name, //company short ID + nombre empresa. En caso de reventa, usar datos del proveedor 'item_category': this.lang, //Language 'price': this.tickets[i].price, //Valor pagado por producto comprado, ejemplo 9.99 'currency': this.currency, // local currency code product 'quantity': 1 //Aquí siempre se pone 1, aunque se hayan comprado varios tipos de tickets } ] }); } } }; turitop_booking_system_thank_page.prototype.fill_tickets = function(){ for ( var i in this.tickets ) { var html = '
html = html + '
';
html = html + '
';
html = html + '
';
document.getElementById( "turitop_thank_you_page_tickets" ).insertAdjacentHTML( "afterbegin", html );
}
if ( this.tickets.length > 1 ) var tickets_title ="Your reference numbers:";else var tickets_title ="Your reference number:"; document.getElementById( "turitop_thank_you_page_tickets" ).insertAdjacentHTML( "afterbegin", '
' ); }; var turitop_booking_system_thank_page_instance = new turitop_booking_system_thank_page(); turitop_booking_system_thank_page_instance.init();
turitop_booking_system_thank_page_instance.fill_tickets();