PageSourceSearch

https://www.businesspost.ie/wp-content/themes/business-post/assets/js/piano-essentials.js?v=3.0

js businesspost.ie collected 2026-09-24 08:39:58 UTC 17,068 bytes, 523 lines download raw bytes

1(function (src) {
2    var a = document.createElement("script");
3    a.type = "text/javascript";
4    a.async = true;
5    a.src = src;
6    a.dataset.cookieconsent = "ignore"
7    var b = document.getElementsByTagName("script")[0];
8    b.parentNode.insertBefore(a, b)
9})("https://c2.businesspost.ie/xbuilder/experience/load?aid=K2MpsKrmpe");
10
11// Load cx.js for Piano Audience identity linking
12(function(d, s, e, r) {
13    e = d.createElement(s);
14    e.async = 1;
15    e.src = 'https://scdn.cxense.com/cx.js';
16    r = d.getElementsByTagName(s)[0];
17    r.parentNode.insertBefore(e, r);
18})(document, 'script');
19var cX = window.cX = window.cX || {};
20cX.callQueue = cX.callQueue || [];
21cX.callQueue.push(['setSiteId', '1151013584956204420']);
22
23tp = window["tp"] || [];
24tp.push(['setApplePayMerchantId', 'acct_182FsyGDdPUI72UM']);
25
26let template_article = document.querySelector('body.single-article');
27if (template_article) {
28    tp.push(['addHandler', 'loginSuccess', function () {
29// Get list of all access data
30    tp.api.callApi('/access/list', {}, function (data) {
31        if (typeof data.data != "undefined") {
32            // Loop through all possible access objects
33            for (var i in data.data) {
34                // Was access granted?
35                if (data.data[i].granted) {
36                    // All good, user just logged in, we can close the offer
37                    tp.offer.close();
38                    // Additionally we can refresh the page
39                    location.reload();
40                }
41            }
42        }
43        });
44    }]);
45}
46
47tp.push(['addHandler', 'logout', function () {
48    location.reload();
49    eraseCookie('googleid');
50    eraseCookie('googlereg');
51    eraseCookie('grantType');
52    eraseCookie('checkoutDone');
53}]);
54
55tp.push(["addHandler", "subscriptionSignup", function (conversion) {
56    if (typeof fbq !== 'undefined' && fbq.version > '2.0') {
57        fbq('track', 'CompleteRegistration');
58    }
59    if (typeof twq !== 'undefined') {
60        twq('track', 'Purchase');
61    }
62    if (typeof window.instgrm !== 'undefined') {
63        window.instgrm('track', 'Lead');
64    }
65    if (typeof window.lintrk !== 'undefined') {
66        window.lintrk('track', {
67            conversion_id: 8423770,
68            event_name: 'CompleteRegistration'
69        });
70    }
71}]);
72
73var botPattern = "(googlebot\/|bot|Googlebot-Mobile|Googlebot-Image|Google favicon|Mediapartners-Google|bingbot|Googlebot smartphone|Googlebot Desktop)";
74
75var re = new RegExp(botPattern, 'i'); 
76var userAgent = navigator.userAgent; 
77if (re.test(userAgent)) { 
78   tp = window.tp || []; 
79   tp.push(["setCustomVariable", "isBot", "true"]); 
80}
81  
82function add_email_to_newsletter( email ){
83//add to newsletter 
84    try{
85        let data_ajax = {
86            action : 'newsletter_subscribe',
87            type : 'POST',
88            data : {email: email },
89            dataType : 'json',
90            contentType : 'application/json'
91        };
92
93        jQuery.ajax({
94            type : 'POST',
95            url : bp_ajaxurl || admin_url,
96            data : data_ajax,
97            success : function( data ){
98                console.log( data );
99            }
100        });
101    }catch( error ){
102        console.log( error )
103    }
104}
105
106function add_email_to_marketing( email ){
107    //add to newsletter 
108    try{
109        let data_ajax = {
110            action : 'newsletter_subscribe_marketing',
111            type : 'POST',
112            data : {email: email },
113            dataType : 'json',
114            contentType : 'application/json'
115        };
116
117        jQuery.ajax({
118            type : 'POST',
119            url : bp_ajaxurl || admin_url,
120            data : data_ajax,
121            success : function( data ){
122                console.log( data );
123            }
124        });
125    }catch( error ){
126        console.log( error )
127    }
128}
129
130function add_email_to_daily( email ){
131    //add to newsletter 
132    try{
133        let data_ajax = {
134            action : 'newsletter_subscribe_daily',
135            type : 'POST',
136            data : {email: email },
137            dataType : 'json',
138            contentType : 'application/json'
139        };
140
141        jQuery.ajax({
142            type : 'POST',
143            url : bp_ajaxurl || admin_url,
144            data : data_ajax,
145            success : function( data ){
146                console.log( data );
147            }
148        });
149    }catch( error ){
150        console.log( error )
151    }
152}
153
154tp = window.tp || [];
155
156tp.push(['addHandler', 'loginSuccess', function () {
157    // Link Piano VX uid to Piano Audience cXense profile
158    var uid = tp.user.getProvider().getUser().uid;
159    if (uid) {
160        cX.callQueue.push(['addExternalId', { id: uid, type: 'uws' }
160]);
161    }
162    // Get list of all access data
163    setTimeout(function() {
164        tp.api.callApi('/access/list', {}, function (data) {
165            if (typeof data.data != "undefined") {
166                // Loop through all possible access objects
167                for (var i in data.data) {
168                    // Was access granted?
169                    if (data.data[i].granted) {
170                        // All good, user just logged in, we can close the offer
171                        tp.offer.close();
172                        // Additionally we can refresh the page
173                        location.reload();
174                    }
175                }
176            }
177        });
178    }, 300);
179}]);
180tp.push(["addHandler", "customEvent", function(event, b, c, d) {
181
182switch (event.eventName) {
183    case 'newsletter-submit-button':
184    var email = '';
185    var params;
186    var iframeId;
187    /*
188    // We are parsing the params object sent from the template to find out which iframe triggered it
189    params = JSON.parse(event.params.params);
190    // And here's the iframeId we're looking for
191    iframeId = params.iframeId;
192    */
193    if ((typeof event.params.userEmail != 'undefined') && (event.params.userEmail.length > 0)) {
194        email = event.params.userEmail;
195    }
196
197    if(location.pathname == "/"){
198    pa.sendEvent('newsletter.inscription', {
199                'page': 'Home Page',
200                'goal_type': 'newsletter-signup'
201            });
202}
203    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
204    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
205    // Here you'll need to pass the relevant data to your newsletter vendor or any other third-party system
206    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
207    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
208    //
209    var emailIsInvalid = false;
210    
211    if( is_valid_email( email ))
212        add_email_to_newsletter( email );
213    else
214        emailIsInvalid = true;
215
216    // Additionally, we can check the response from the vendor.
217    // For example, if email is invalid:
218    
219    if ( emailIsInvalid ) {
220        sendPostMessageToPiano(iframeId, false, 'You have entered an invalid email', 'email');
221    } else {
222        // If the email was added successfully set a cookie for Composer tracking.
223        pianoSetCustomVariableCookie('newsletter', 'true');
224        //We can close the offer now.
225        tp.offer.close();
226    }
227
228    break;
229}
230}]);
231
232tp.push(["addHandler", "checkoutComplete", function( conversion ){ 
233if(conversion.termId == 'TMPJVJT8TQT3'){
234
235    const cleanTags = (Array.isArray(piano_tags) ? piano_tags : [piano_tags])
236    .flatMap(v => String(v || '').split(/[,\|]/))
237    .map(s => s.trim())
238    .filter(Boolean);
239
240    const cleanCats = (Array.isArray(piano_categories) ? piano_categories : [piano_categories])
241    .flatMap(v => String(v || '').split(/[,\|]/))
242    .map(s => s.trim())
243    .filter(Boolean);
244
245    const cleanAuthors = (Array.isArray(piano_authors) ? piano_authors : [piano_authors])
246    .flatMap(v => String(v || '').split(/[,\|]/))
247    .map(s => s.trim())
248    .filter(Boolean);
249
250    jQuery.ajax({
251    url: bp_ajaxurl || admin_url,
252    type: 'POST',
253    data: {
254        action: 'piano_consent_reg',
255        email: conversion.email,
256        piano_tags: cleanTags,
257        piano_authors: cleanAuthors,
258        piano_categories: cleanCats
259    },
260    success: function(response) {
261    
262        // if(response == "true"){
263        //     add_email_to_marketing( conversion.email );
264                
265        
266        // }
267    },
268    error: function(error) {
269    // Handle any errors that occur during the AJAX request
270    console.error('AJAX request error:', error);
271    }
272    });
273    
274}else{
275    jQuery.ajax({
276        url: bp_ajaxurl || admin_url,
277        type: 'POST',
278        data: {
279            action: 'piano_consent_reg',
280            email: conversion.email,
281        },
282        success: function(response) {
283        console.log(response);
284            // if(response == "true"){
285            // add_email_to_marketing( conversion.email );
286            // }
287        
288            // }else{
289            // add_email_to_daily( conversion.email );
290            // }
291        },
292        error: function(error) {
293        // Handle any errors that occur during the AJAX request
294        console.error('AJAX request error:', error);
295        }
296    });
297}
298
299if (conversion.type === "payment") {
300    // Google ads
301    gtag('event', 'conversion', {
302    'send_to': 'AW-11200717057/3KzjCPHyr6gYEIHC9dwp',
303    'transaction_id': ''
304    });
305    // Linkedin
306    window.lintrk('track', { conversion_id: 13043002 });
307
308}
309}]);
310
311// Store term when user starts/selects checkout
312var _abandonedTerm = null;
313tp.push(["addHandler", "startCheckout", function(event) {
314    _abandonedTerm = { termId: event.termId, offerId: event.offerId };
315}]);
316
317tp.push(["addHandler", "checkoutClose", function(event){
318switch (event.state){
319    case 'checkoutCompleted':
320        // check the URL before going back or redirecting
321        if(window.location.pathname !== "/offers/irish-business-london/") {
322            history.back();
323        }
324        break;
325    case 'alreadyHasAccess':
326        // User already has access
327        // This state could be a result of user logging in during checkout process
328        // Usually it's a good practice to reload the page here as well
329        break;
330    case 'voucherRedemptionCompleted':
331        // User redeemed a gift voucher
332        // Normally gift redemption happens on a landing page, 
333        // so logically it makes sense to redirect user to a home page after this
334        break;
335    case 'close':
336         _sendAbandonBeacon();
337        break;
338        // User did not complete the purchase and simply closed the modal
339}
340}]);
341
342document.addEventListener('visibilitychange', function() {
343    if (document.visibilityState === 'hidden') {
344        _sendAbandonBeacon();
345    }
346});
347
348function _sendAbandonBeacon() {
349    console.log(_abandonedTerm);
350    if (_abandonedTerm && tp.user && tp.user.isUserValid()) {
351        var uid = tp.user.getProvider().getUser().uid;
352        if (uid) {
353            var url = 'https://checkoutabandons.businesspost.ninja/track';
354            var blob = new Blob([JSON.stringify({
355                uid: uid,
356                termId: _abandonedTerm.termId,
357                offerId: _abandonedTerm.offerId,
358                abandonedAt: new Date().toISOString()
359            })], { type: 'application/json' });
360
361            var sent = navigator.sendBeacon ? navigator.sendBeacon(url, blob) : false;
362
363            if (!sent) {
364                fetch(url, {
365                    method: 'POST',
366                    body: JSON.stringify({
367                        uid: uid,
368                        termId: _abandonedTerm.termId,
369                        offerId: _abandonedTerm.offerId,
370                        abandonedAt: new Date().toISOString()
371                    }),
372                    headers: { 'Content-Type': 'application/json' },
373                    keepalive: true
374                }).catch(function() {});
375            }
376            _abandonedTerm = null;
377        }
378    }
379}
380
381
382
383function is_valid_email( $email ){
384    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test( $email )){
385    return true;
386    }
387
388return false;
389}
390
391/* Add all new signups to Sendy Lists - WP Config for more detail */
392tp.push(["addHandler", "registrationSuccess", function(data){
393    const user_email = tp.user.getProvider().getUser().email || '';
394    jQuery.ajax({
395    url: bp_ajaxurl || admin_url,
396    type: 'POST',
397    data: {
398        action: 'piano_consent',
399        email: user_email,
400    },
401    success: function(response) {
402        if(response == "true"){
403            add_email_to_newsletter(user_email);
404                
405            location.reload();
406        }
407    },
408    error: function(error) {
409    // Handle any errors that occur during the AJAX request
410    console.error('AJAX request error:', error);
411    }
412});
413}]);
414
415tp.push(["init", function () {
416
417    let login_a = document.querySelector('.btn-signin-desktop');
418    let login_mob = document.querySelector('.btn-signin-mobile');
419    let btn_subs = document.querySelector('.btn-subscribe-mobile');
420    let btn_acc = document.querySelector('.menu-mobile .my-account-btn');
421    let btn_acc_desktop = document.querySelector('.nav-right a.my-acc-desktop');
422    let btn_sub_dekstop= document.querySelector('.nav-right a.btn-sub-desktop');
423    let logout_mob = document.querySelector('.menu-item-389039');
424
425    if( login_a !== null ){
426        login_a.textContent = 'Sign in';
427        login_a.addEventListener( 'click', function( e ){
428
429            e.preventDefault();
430            // const newsletter_tab = document.querySelector('.newsletter-tab-screen');
431            if( tp.user && tp.user.isUserValid() ){  //logged in
432                let has_logged_out = tp.user.logout();
433                this.textContent = 'Logout';
434                // if( newsletter_tab !== null ) newsletter_tab.style.display = 'none';
435            }else{
436                
437                tp.pianoId.show({
438                    displayMode: 'modal',
439                    screen: 'login',
440                    loggedIn: function (data) {
441                        if( login_a !== null )login_a.textContent = 'Logout';
442                        // pa.getUser(function (userData) {
443                        //     pa.setUser(userData.id, 'subscribe', true);
444                        // });
445                        btn_sub_dekstop.style.display = 'none';
446                        btn_acc_desktop.style.display = 'flex';
447                    },
448                    loggedOut: function () {
449                        if( login_a !== null ) login_a.textContent = 'Sign in';
450                        // if( newsletter_tab !== null ) newsletter_tab.style.display = 'none';
451                        btn_sub_dekstop.style.display = 'flex';
452                        btn_acc_desktop.style.display = 'none';
453                    }
454                });
455            }
456
457        });
458    }
459
460    if( login_mob !== null ){
461        login_mob.addEventListener( 'click', function( e ){
462
463            e.preventDefault();
464            // const newsletter_tab = document.querySelector('.newsletter-tab-screen');
465            if( tp.user && tp.user.isUserValid() ){  //logged in
466                let has_logged_out = tp.user.logout();
467                login_a.textContent = 'Logout';
468            }else{
469                
470                tp.pianoId.show({
471                    displayMode: 'modal',
472                    screen: 'login',
473                    loggedIn: function (data) {
474                        if( login_mob !== null )login_mob.style.display = 'none';
475                        // pa.getUser(function (userData) {
476                        //     pa.setUser(userData.id, 'subscribe', true);
477                        // });
478                    },
479                    loggedOut: function () {
480                        if( login_mob !== null ) login_mob.style.display = 'block';
481                        // if( newsletter_tab !== null ) newsletter_tab.style.display = 'none';
482                    }
483                });
484            }
485
486        });
487    }
488
489    if( logout_mob !== null ){
490        logout_mob.addEventListener( 'click', function( e ){
491
492            e.preventDefault();
493            // const newsletter_tab = document.querySelector('.newsletter-tab-screen');
494            if( tp.user && tp.user.isUserValid() ){  //logged in
495                let has_logged_out = tp.user.logout();
496                login_a.textContent = 'Logout';
497            }
498
499        });
500    }
501
502    if( tp.user && tp.user.isUserValid() ){ 
503        var uid = tp.user.getProvider().getUser().uid;
504        if (uid) {
505            cX.callQueue.push(['addExternalId', { id: uid, type: 'uws' }
505]);
506        }
507        login_mob.style.display = 'none';
508        btn_subs.style.display = 'none';
509        login_a.textContent = 'Logout';
510        btn_acc.style.display = 'flex';
511        btn_sub_dekstop.style.display = 'none';
512        btn_acc_desktop.style.display = 'flex';
513    } else {
514        logout_mob.style.display = 'none';
515    }
516
517}]);
518
519if(location.pathname == "/"){
520    pa.sendEvent('page.display',{
521    'page':'Home Page'
522    });
523}

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.