Plugin Directory

Changeset 3386465


Ignore:
Timestamp:
10/29/2025 01:38:25 PM (5 months ago)
Author:
bhvreddy
Message:

v4.30 enhance google analytics

Location:
click-to-chat-for-whatsapp
Files:
266 added
4 edited

Legend:

Unmodified
Added
Removed
  • click-to-chat-for-whatsapp/trunk/click-to-chat.php

    r3369409 r3386465  
    88 * Plugin URI:  https://wordpress.org/plugins/click-to-chat-for-whatsapp/
    99 * Description: Lets make your Web page visitors contact you through WhatsApp with a single click/tap
    10  * Version:     4.29
     10 * Version:     4.30
    1111 * Author:      HoliThemes
    1212 * Author URI:  https://holithemes.com/plugins/click-to-chat/
     
    2222// ctc - Version - update version at readme 'Stable tag'.
    2323if ( ! defined( 'HT_CTC_VERSION' ) ) {
    24     define( 'HT_CTC_VERSION', '4.29' );
     24    define( 'HT_CTC_VERSION', '4.30' );
    2525}
    2626
  • click-to-chat-for-whatsapp/trunk/new/inc/assets/js/app.js

    r3353804 r3386465  
    1 (()=>{var e;(e=jQuery)(function(){var t=window.location.href,c=void 0!==document.title?document.title:"",n="no",a=document.querySelector(".ht-ctc-chat");try{n=void 0!==navigator.userAgent&&navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i)?"yes":"no"}catch(e){}"no"==n&&(n=void 0!==screen.width&&screen.width>1025?"no":"yes");var o={};function r(){localStorage.getItem("ht_ctc_storage")&&(o=localStorage.getItem("ht_ctc_storage"),o=JSON.parse(o))}function _(e){return!!o[e]&&o[e]}function i(e,t){r(),o[e]=t;var c=JSON.stringify(o);localStorage.setItem("ht_ctc_storage",c)}r();var s={},l={};function u(){var t=document.querySelector(".ht_ctc_chat_data");t&&t.remove(),document.dispatchEvent(new CustomEvent("ht_ctc_event_settings",{detail:{ctc:s}})),function(){if(a){document.dispatchEvent(new CustomEvent("ht_ctc_event_chat")),function(e){s.schedule&&"yes"==s.schedule?document.dispatchEvent(new CustomEvent("ht_ctc_event_display",{detail:{ctc:s,display_chat:g,ht_ctc_chat:e,online_content:f}})):(g(e),f())}(a),a.addEventListener("click",function(){document.querySelector(".ht_ctc_chat_greetings_box")||b(a)}),function(){if(a){var e=document.querySelector(".ht_ctc_chat_greetings_box");e&&a.addEventListener("click",function(t){t.target.closest(".ht_ctc_chat_style")&&(e.classList.contains("ctc_greetings_opened")?v("user_closed"):d("user_opened"))}),a.addEventListener("click",function(e){e.target.closest(".ctc_greetings_close_btn")&&v("user_closed")})}}(),a&&a.addEventListener("click",function(e){if(e.target.closest(".ht_ctc_chat_greetings_box_link")){e.preventDefault();var t=document.querySelector("#ctc_opt");if(t)if(t.checked||_("g_optin"))b(a),h();else{var c=document.querySelector(".ctc_opt_in");c&&(c.style.display="block",c.style.opacity="0",setTimeout(function(){c.style.transition="opacity 0.4s",c.style.opacity="1"},10))}else b(a),h();document.dispatchEvent(new CustomEvent("ht_ctc_event_greetings"))}});var e=document.querySelector("#ctc_opt");e&&e.addEventListener("change",function(){if(e.checked){var t=document.querySelector(".ctc_opt_in");t&&(t.style.transition="opacity 0.1s ease-out",t.style.opacity="0",setTimeout(function(){t.style.display="none"},100)),i("g_optin","y"),setTimeout(function(){b(a),h()},500)}})}}(),e(document).on("click",".ht-ctc-sc-chat",function(){b(this)}),document.addEventListener("click",function(e){var t=e.target.closest(".ctc_chat, #ctc_chat");t&&(b(t),t.classList.contains("ctc_woo_place")&&e.preventDefault());var c=e.target.closest('[href="#ctc_chat"]');c&&(e.preventDefault(),b(c))})}function d(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"open";y();var c=document.querySelector(".ht-ctc-chat .ctc_cta_stick");c&&c.remove();var n=document.querySelector(".ht_ctc_chat_greetings_box");n&&("init"==t?e(".ht_ctc_chat_greetings_box").show(70):e(".ht_ctc_chat_greetings_box").show(400),n.classList.add("ctc_greetings_opened"),n.classList.remove("ctc_greetings_closed")),i("g_action",t),"user_opened"==t&&i("g_user_action",t),function(){if(document.querySelector(".ctc_greetings_modal")&&!document.querySelector(".ht_ctc_modal_backdrop")){var e=function(t){"Escape"===t.key&&(v("user_closed"),document.removeEventListener("keydown",e))},t=document.createElement("div");t.className="ht_ctc_modal_backdrop",document.body.appendChild(t),t.addEventListener("click",function(){v("user_closed")}),document.addEventListener("keydown",e)}}()}function h(){m(),setTimeout(function(){v("chat_clicked")},500)}function v(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"close";m(),"element"==t?e(".ht_ctc_chat_greetings_box").hide(70):e(".ht_ctc_chat_greetings_box").hide(400);var c=document.querySelector(".ht_ctc_chat_greetings_box");c&&(c.classList.add("ctc_greetings_closed"),c.classList.remove("ctc_greetings_opened")),i("g_action",t),"user_closed"==t&&i("g_user_action",t)}function m(){var e=document.querySelector(".ht_ctc_modal_backdrop");e&&e.remove()}function g(e){var t;"yes"==n?"show"==s.dis_m&&((t=document.querySelector(".ht_ctc_desktop_chat"))&&t.remove(),e.style.cssText=s.pos_m+s.css,p(e)):"show"==s.dis_d&&((t=document.querySelector(".ht_ctc_mobile_chat"))&&t.remove(),e.style.cssText=s.pos_d+s.css,p(e))}function p(t){try{e(t).show(parseInt(s.se))}catch(e){t.style.display="block"}!function(){var e=document.querySelector(".ht_ctc_chat_greetings_box");if(e){if(s.g_device){if("yes"!==n&&"mobile"===s.g_device)return void e.remove();if("yes"===n&&"desktop"===s.g_device)return void e.remove()}document.dispatchEvent(new CustomEvent("ht_ctc_event_after_chat_displayed",{detail:{ctc:s,greetings_open:d,greetings_close:v}})),s.g_init&&"user_closed"!==_("g_user_action")&&("default"===s.g_init?"yes"!==n&&d("init"):"open"===s.g_init&&d("init"));var t=document.querySelectorAll('.ctc_greetings, #ctc_greetings, .ctc_greetings_now, [href="#ctc_greetings"]');t.length>0&&t.forEach(function(e){e.addEventListener("click",function(e){e.preventDefault(),v("element"),d("element")})})}}(),function(){if(document.querySelector(".ht_ctc_notification")&&"stop"!==_("n_badge")){var t=document.querySelector(".ctc_nb");if(t){var c=t.closest(".ht_ctc_style"),n=document.querySelector(".ht_ctc_badge");if(c&&n){var a,o,r=null===(a=c.querySelector(".ctc_nb"))||void 0===a?void 0:a.getAttribute("data-nb_top"),i=null===(o=c.querySelector(".ctc_nb"))||void 0===o?void 0:o.getAttribute("data-nb_right");null!==r&&(n.style.top=r),null!==i&&(n.style.right=i)}}var l=s.n_time?1e3*s.n_time:150;setTimeout(function(){e(".ht_ctc_notification").show(400)},l)}}(),function(t){var c=t.classList.contains("ht_ctc_entry_animation")?1200:120;setTimeout(function(){t.classList.add("ht_ctc_animation",s.ani)},c),e(".ht-ctc-chat").hover(function(){e(".ht-ctc-chat .ht-ctc-cta-hover").show(120)},function(){e(".ht-ctc-chat .ht-ctc-cta-hover").hide(100)})}(t)}function f(){document.querySelector(".for_greetings_header_image_badge")&&(document.querySelectorAll(".for_greetings_header_image_badge").forEach(function(e){e.classList.add("g_header_badge_online")}),e(".for_greetings_header_image_badge").show())}function y(){var e=document.querySelector(".ht_ctc_notification");e&&(i("n_badge","stop"),e.remove())}function b(a){document.dispatchEvent(new CustomEvent("ht_ctc_event_number",{detail:{ctc:s}}));var o=s.number,r=s.pre_filled;if(a.hasAttribute("data-number")&&""!==a.getAttribute("data-number")&&(o=a.getAttribute("data-number")),a.hasAttribute("data-pre_filled")){var _=a.getAttribute("data-pre_filled")||"";r=(s.prefix_pre_filled?s.prefix_pre_filled:"")+_}try{r=r.replaceAll("%","%25");var i=window.location.href;r=r.replace(/\[url]/gi,i),r=encodeURIComponent(decodeURI(r))}catch(e){}if(""!=o||s.custom_url_m&&""!==s.custom_url_m||s.custom_url_d&&""!==s.custom_url_d){var u="https://wa.me/"+o+"?text="+r,d=s.url_target_d?s.url_target_d:"_blank";"yes"==n?(s.url_structure_m&&"wa_colon"==s.url_structure_m&&(u="whatsapp://send?phone="+o+"&text="+r,d="_self"),s.custom_url_m&&""!==s.custom_url_m&&(u=s.custom_url_m)):(s.url_structure_d&&"web"==s.url_structure_d&&(u="https://web.whatsapp.com/send?phone="+o+"&text="+r),s.custom_url_d&&""!==s.custom_url_d&&(u=s.custom_url_d));var h="popup"==d?"scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=788,height=514,left=100,top=100":"noopener";window.open(u,d,h),s.chat_number=o,function(){if(s.analytics&&"session"==s.analytics){if(sessionStorage.getItem("ht_ctc_analytics"))return;sessionStorage.setItem("ht_ctc_analytics","done")}function e(e){var n=s.chat_number&&""!==s.chat_number?s.chat_number:s.number;try{document.dispatchEvent(new CustomEvent("ht_ctc_event_apply_variables",{detail:{v:e}})),e=(e=(e=(e=void 0!==window.apply_variables_value?window.apply_variables_value:e).replace("{number}",n)).replace("{title}",c)).replace("{url}",t)}catch(e){}return e}var n;n="event_"+Math.floor(1e4+9e4*Math.random()),s.ctc_pixel_event_id=n,document.dispatchEvent(new CustomEvent("ht_ctc_event_analytics"));var a=s.chat_number&&""!==s.chat_number?s.chat_number:s.number,o={},r="Click to Chat for WhatsApp",_="chat: "+a,i=c+", "+t;if(s.ga){var u=s.g_an_event_name&&""!==s.g_an_event_name?s.g_an_event_name:"click to chat";u=e(u),l.g_an_params&&l.g_an_params.forEach(function(t){if(l[t]){var c=l[t],n=c.key,a=c.value;n=e(n),a=e(a),o[n]=a}});var d=0,h="no";if("undefined"!=typeof dataLayer)try{var v=function(e){e=e.toUpperCase(),m.includes(e)||(m.push(e),(e.startsWith("G-")||e.startsWith("GT-"))&&(o.send_to=e,gtag("event",u,o),d++))};"undefined"==typeof gtag&&(window.gtag=function(){dataLayer.push(arguments)},h="yes");var m=[];if(window.google_tag_data&&window.google_tag_data.tidr&&window.google_tag_data.tidr.destination)for(var g in window.google_tag_data.tidr.destination)v(g);dataLayer.forEach(function(e){"config"==e[0]&&e[1]&&(g=e[1],v(g))})}catch(e){}0==d&&"no"==h&&("undefined"!=typeof gtag?gtag("event",u,o):"undefined"!=typeof ga&&void 0!==ga.getAll?ga.getAll()[0].send("event",r,_,i):"undefined"!=typeof __gaTracker&&__gaTracker("send","event",r,_,i))}if("undefined"!=typeof dataLayer&&dataLayer.push({event:"Click to Chat",type:"chat",number:a,title:c,url:t,event_category:r,event_label:i,event_action:_,ref:"dataLayer push"}),s.ads&&"undefined"!=typeof gtag_report_conversion&&gtag_report_conversion(),s.fb&&"undefined"!=typeof fbq){var p=s.pixel_event_name&&""!==s.pixel_event_name?s.pixel_event_name:"Click to Chat by HoliThemes",f=l.pixel_event_type&&""!==l.pixel_event_type?l.pixel_event_type:"trackCustom",y={};l.pixel_params&&l.pixel_params.forEach(function(t){if(l[t]){var c=l[t],n=c.key,a=c.value;n=e(n),a=e(a),y[n]=a}}),s.ctc_pixel_event_id="",fbq(f,p,y,{eventID:n})}}(),function(t){if(s.hook_url){var c={};if(s.hook_v){c=void 0!==k?k:s.hook_v;var n={},a=1;c.forEach(function(e){n["value"+a]=e,a++}),s.hook_v=n}document.dispatchEvent(new CustomEvent("ht_ctc_event_hook",{detail:{ctc:s,number:t}}));var o=s.hook_url;if(c=s.hook_v,s.webhook_format&&"json"==s.webhook_format)var r=c;else r=JSON.stringify(c);e.ajax({url:o,type:"POST",mode:"no-cors",data:r,success:function(e){}})}}(o),y()}else if(s.no_number){var v=document.querySelector(".ctc-no-number-message");v&&(v.style.display="block")}}"undefined"!=typeof ht_ctc_chat_var&&(s=ht_ctc_chat_var),"undefined"!=typeof ht_ctc_variables&&(l=ht_ctc_variables),0===Object.keys(s).length||0===Object.keys(l).length?function(){if(0===Object.keys(s).length&&document.querySelector(".ht_ctc_chat_data"))try{var e,t=(null===(e=document.querySelector(".ht_ctc_chat_data"))||void 0===e?void 0:e.getAttribute("data-settings"))||"";s=JSON.parse(t),window.ht_ctc_chat_var=s}catch(e){}0===Object.keys(l).length&&(l={g_an_event_name:"click to chat",pixel_event_name:"Click to Chat by HoliThemes",pixel_event_type:"trackCustom",g_an_params:["g_an_param_1","g_an_param_2","g_an_param_3"],g_an_param_1:{key:"number",value:"{number}"},g_an_param_2:{key:"title",value:"{title}"},g_an_param_3:{key:"url",value:"{url}"},pixel_params:["pixel_param_1","pixel_param_2","pixel_param_3","pixel_param_4"],pixel_param_1:{key:"Category",value:"Click to Chat for WhatsApp"},pixel_param_2:{key:"return_type",value:"chat"},pixel_param_3:{key:"ID",value:"{number}"},pixel_param_4:{key:"Title",value:"{title}"}},window.ht_ctc_variables=l),u()}():u();var k=s.hook_v?s.hook_v:""})})();
     1(()=>{function t(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(t);e&&(c=c.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,c)}return n}function e(e){for(var c=1;c<arguments.length;c++){var o=null!=arguments[c]?arguments[c]:{};c%2?t(Object(o),!0).forEach(function(t){n(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}function n(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=c(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!=c(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==c(e)?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}var o;(o=jQuery)(function(){var t=window.location.href,n=void 0!==document.title?document.title:"",a="no",r=document.querySelector(".ht-ctc-chat");try{a=void 0!==navigator.userAgent&&navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i)?"yes":"no"}catch(t){}"no"==a&&(a=void 0!==screen.width&&screen.width>1025?"no":"yes");var i={};function _(){localStorage.getItem("ht_ctc_storage")&&(i=localStorage.getItem("ht_ctc_storage"),i=JSON.parse(i))}function s(t){return!!i[t]&&i[t]}function u(t,e){_(),i[t]=e;var n=JSON.stringify(i);localStorage.setItem("ht_ctc_storage",n)}_();var l={},d={};function h(){var t=document.querySelector(".ht_ctc_chat_data");t&&t.remove(),document.dispatchEvent(new CustomEvent("ht_ctc_event_settings",{detail:{ctc:l}})),function(){if(r){document.dispatchEvent(new CustomEvent("ht_ctc_event_chat")),function(t){l.schedule&&"yes"==l.schedule?document.dispatchEvent(new CustomEvent("ht_ctc_event_display",{detail:{ctc:l,display_chat:g,ht_ctc_chat:t,online_content:b}})):(g(t),b())}(r),r.addEventListener("click",function(){document.querySelector(".ht_ctc_chat_greetings_box")||S(r)}),function(){if(r){var t=document.querySelector(".ht_ctc_chat_greetings_box");t&&r.addEventListener("click",function(e){e.target.closest(".ht_ctc_chat_style")&&(t.classList.contains("ctc_greetings_opened")?p("user_closed"):v("user_opened"))}),r.addEventListener("click",function(t){t.target.closest(".ctc_greetings_close_btn")&&p("user_closed")})}}(),r&&r.addEventListener("click",function(t){if(t.target.closest(".ht_ctc_chat_greetings_box_link")){t.preventDefault();var e=document.querySelector("#ctc_opt");if(e)if(e.checked||s("g_optin"))S(r),m();else{var n=document.querySelector(".ctc_opt_in");n&&(n.style.display="block",n.style.opacity="0",setTimeout(function(){n.style.transition="opacity 0.4s",n.style.opacity="1"},10))}else S(r),m();document.dispatchEvent(new CustomEvent("ht_ctc_event_greetings"))}});var t=document.querySelector("#ctc_opt");t&&t.addEventListener("change",function(){if(t.checked){var e=document.querySelector(".ctc_opt_in");e&&(e.style.transition="opacity 0.1s ease-out",e.style.opacity="0",setTimeout(function(){e.style.display="none"},100)),u("g_optin","y"),setTimeout(function(){S(r),m()},500)}})}}(),o(document).on("click",".ht-ctc-sc-chat",function(){S(this)}),document.addEventListener("click",function(t){var e=t.target.closest(".ctc_chat, #ctc_chat");e&&(S(e),e.classList.contains("ctc_woo_place")&&t.preventDefault());var n=t.target.closest('[href="#ctc_chat"]');n&&(t.preventDefault(),S(n))})}function v(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"open";w();var e=document.querySelector(".ht-ctc-chat .ctc_cta_stick");e&&e.remove();var n=document.querySelector(".ht_ctc_chat_greetings_box");n&&("init"==t?o(".ht_ctc_chat_greetings_box").show(70):o(".ht_ctc_chat_greetings_box").show(400),n.classList.add("ctc_greetings_opened"),n.classList.remove("ctc_greetings_closed")),u("g_action",t),"user_opened"==t&&u("g_user_action",t),function(){if(document.querySelector(".ctc_greetings_modal")&&!document.querySelector(".ht_ctc_modal_backdrop")){var t=function(e){"Escape"===e.key&&(p("user_closed"),document.removeEventListener("keydown",t))},e=document.createElement("div");e.className="ht_ctc_modal_backdrop",document.body.appendChild(e),e.addEventListener("click",function(){p("user_closed")}),document.addEventListener("keydown",t)}}()}function m(){f(),setTimeout(function(){p("chat_clicked")},500)}function p(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"close";f(),"element"==t?o(".ht_ctc_chat_greetings_box").hide(70):o(".ht_ctc_chat_greetings_box").hide(400);var e=document.querySelector(".ht_ctc_chat_greetings_box");e&&(e.classList.add("ctc_greetings_closed"),e.classList.remove("ctc_greetings_opened")),u("g_action",t),"user_closed"==t&&u("g_user_action",t)}function f(){var t=document.querySelector(".ht_ctc_modal_backdrop");t&&t.remove()}function g(t){var e;"yes"==a?"show"==l.dis_m&&((e=document.querySelector(".ht_ctc_desktop_chat"))&&e.remove(),t.style.cssText=l.pos_m+l.css,y(t)):"show"==l.dis_d&&((e=document.querySelector(".ht_ctc_mobile_chat"))&&e.remove(),t.style.cssText=l.pos_d+l.css,y(t))}function y(t){try{o(t).show(parseInt(l.se))}catch(e){t.style.display="block"}!function(){var t=document.querySelector(".ht_ctc_chat_greetings_box");if(t){if(l.g_device){if("yes"!==a&&"mobile"===l.g_device)return void t.remove();if("yes"===a&&"desktop"===l.g_device)return void t.remove()}document.dispatchEvent(new CustomEvent("ht_ctc_event_after_chat_displayed",{detail:{ctc:l,greetings_open:v,greetings_close:p}})),l.g_init&&"user_closed"!==s("g_user_action")&&("default"===l.g_init?"yes"!==a&&v("init"):"open"===l.g_init&&v("init"));var e=document.querySelectorAll('.ctc_greetings, #ctc_greetings, .ctc_greetings_now, [href="#ctc_greetings"]');e.length>0&&e.forEach(function(t){t.addEventListener("click",function(t){t.preventDefault(),p("element"),v("element")})})}}(),function(){if(document.querySelector(".ht_ctc_notification")&&"stop"!==s("n_badge")){var t=document.querySelector(".ctc_nb");if(t){var e=t.closest(".ht_ctc_style"),n=document.querySelector(".ht_ctc_badge");if(e&&n){var c,a,r=null===(c=e.querySelector(".ctc_nb"))||void 0===c?void 0:c.getAttribute("data-nb_top"),i=null===(a=e.querySelector(".ctc_nb"))||void 0===a?void 0:a.getAttribute("data-nb_right");null!==r&&(n.style.top=r),null!==i&&(n.style.right=i)}}var _=l.n_time?1e3*l.n_time:150;setTimeout(function(){o(".ht_ctc_notification").show(400)},_)}}(),function(t){var e=t.classList.contains("ht_ctc_entry_animation")?1200:120;setTimeout(function(){t.classList.add("ht_ctc_animation",l.ani)},e),o(".ht-ctc-chat").hover(function(){o(".ht-ctc-chat .ht-ctc-cta-hover").show(120)},function(){o(".ht-ctc-chat .ht-ctc-cta-hover").hide(100)})}(t)}function b(){document.querySelector(".for_greetings_header_image_badge")&&(document.querySelectorAll(".for_greetings_header_image_badge").forEach(function(t){t.classList.add("g_header_badge_online")}),o(".for_greetings_header_image_badge").show())}function w(){var t=document.querySelector(".ht_ctc_notification");t&&(u("n_badge","stop"),t.remove())}function k(o){if(l.analytics&&"session"==l.analytics){if(sessionStorage.getItem("ht_ctc_analytics"))return;sessionStorage.setItem("ht_ctc_analytics","done")}function a(e){var c=l.chat_number&&""!==l.chat_number?l.chat_number:l.number;try{document.dispatchEvent(new CustomEvent("ht_ctc_event_apply_variables",{detail:{v:e}})),e=(e=(e=(e=void 0!==window.apply_variables_value?window.apply_variables_value:e).replace("{number}",c)).replace("{title}",n)).replace("{url}",t)}catch(t){}return e}var r;r="event_"+Math.floor(1e4+9e4*Math.random()),l.ctc_pixel_event_id=r,document.dispatchEvent(new CustomEvent("ht_ctc_event_analytics"));var i=l.chat_number&&""!==l.chat_number?l.chat_number:l.number,_={},s="Click to Chat for WhatsApp",u="chat: "+i,h=n+", "+t;if(l.ga){var v=l.g_an_event_name&&""!==l.g_an_event_name?l.g_an_event_name:"click to chat";v=a(v),d.g_an_params&&d.g_an_params.forEach(function(t){if(d[t]){var e=d[t],n=e.key,c=e.value;n=a(n),c=a(c),_[n]=c}});var m=0,p="no",f=[];if("undefined"!=typeof dataLayer)try{var g=function(t,e){t&&"string"==typeof t&&""!==t.trim()&&(f.includes(t)||f.push(t))};"undefined"==typeof gtag&&(window.gtag=function(){dataLayer.push(arguments)},p="yes");var y=[];try{var b,w=null===(b=window.google_tag_data)||void 0===b?void 0:b.tidr;null!=w&&w.destination&&"object"===c(w.destination)&&Object.keys(w.destination).forEach(function(t){g(t)})}catch(t){}try{var k,S=null===(k=window.google_tag_data)||void 0===k||null===(k=k.tidr)||void 0===k?void 0:k.container;S&&"object"===c(S)&&Object.values(S).forEach(function(t){Array.isArray(t.destinations)&&t.destinations.forEach(function(t){"string"==typeof t&&t.startsWith("G-")&&g(t)})})}catch(t){}try{Array.isArray(window.dataLayer)&&window.dataLayer.forEach(function(t){Array.isArray(t)&&"config"===t[0]&&"string"==typeof t[1]?g(t[1]):null!=t&&t.send_to&&"string"==typeof t.send_to&&g(t.send_to)})}catch(t){}f.forEach(function(t){var e;e=(e=t).toUpperCase(),y.includes(e)||(y.push(e),(e.startsWith("G-")||e.startsWith("GT-"))&&(_.send_to=e,gtag("event",v,_),m++))})}catch(t){}0==m&&"no"==p&&("undefined"!=typeof gtag?gtag("event",v,_):"undefined"!=typeof ga&&void 0!==ga.getAll?ga.getAll()[0].send("event",s,u,h):"undefined"!=typeof __gaTracker&&__gaTracker("send","event",s,u,h))}if("undefined"!=typeof dataLayer){dataLayer.push({event:"Click to Chat",type:"chat",number:i,title:n,url:t,event_category:s,event_label:h,event_action:u,ref:"dataLayer push"});var E=e(e({},null!=_?_:{}),{},{event:null!=v?v:"chat_click",ref:"dataLayer push ga admin values"});dataLayer.push(E)}if(l.ads&&"undefined"!=typeof gtag_report_conversion&&gtag_report_conversion(),l.fb&&"undefined"!=typeof fbq){var x=l.pixel_event_name&&""!==l.pixel_event_name?l.pixel_event_name:"Click to Chat by HoliThemes",q=d.pixel_event_type&&""!==d.pixel_event_type?d.pixel_event_type:"trackCustom",O={};d.pixel_params&&d.pixel_params.forEach(function(t){if(d[t]){var e=d[t],n=e.key,c=e.value;n=a(n),c=a(c),O[n]=c}}),l.ctc_pixel_event_id="",fbq(q,x,O,{eventID:r})}}function S(t){document.dispatchEvent(new CustomEvent("ht_ctc_event_number",{detail:{ctc:l}}));var e=l.number,n=l.pre_filled;if(t.hasAttribute("data-number")&&""!==t.getAttribute("data-number")&&(e=t.getAttribute("data-number")),t.hasAttribute("data-pre_filled")){var c=t.getAttribute("data-pre_filled")||"";n=(l.prefix_pre_filled?l.prefix_pre_filled:"")+c}try{n=n.replaceAll("%","%25");var r=window.location.href;n=n.replace(/\[url]/gi,r),n=encodeURIComponent(decodeURI(n))}catch(t){}if(""!=e||l.custom_url_m&&""!==l.custom_url_m||l.custom_url_d&&""!==l.custom_url_d){var i="https://wa.me/"+e+"?text="+n,_=l.url_target_d?l.url_target_d:"_blank";"yes"==a?(l.url_structure_m&&"wa_colon"==l.url_structure_m&&(i="whatsapp://send?phone="+e+"&text="+n,_="_self"),l.custom_url_m&&""!==l.custom_url_m&&(i=l.custom_url_m)):(l.url_structure_d&&"web"==l.url_structure_d&&(i="https://web.whatsapp.com/send?phone="+e+"&text="+n),l.custom_url_d&&""!==l.custom_url_d&&(i=l.custom_url_d));var s="popup"==_?"scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=788,height=514,left=100,top=100":"noopener";window.open(i,_,s),l.chat_number=e,k(),function(t){if(l.hook_url){var e={};if(l.hook_v){e=void 0!==E?E:l.hook_v;var n={},c=1;e.forEach(function(t){n["value"+c]=t,c++}),l.hook_v=n}document.dispatchEvent(new CustomEvent("ht_ctc_event_hook",{detail:{ctc:l,number:t}}));var a=l.hook_url;if(e=l.hook_v,l.webhook_format&&"json"==l.webhook_format)var r=e;else r=JSON.stringify(e);o.ajax({url:a,type:"POST",mode:"no-cors",data:r,success:function(t){}})}}(e),w()}else if(l.no_number){var u=document.querySelector(".ctc-no-number-message");u&&(u.style.display="block")}}"undefined"!=typeof ht_ctc_chat_var&&(l=ht_ctc_chat_var),"undefined"!=typeof ht_ctc_variables&&(d=ht_ctc_variables),0===Object.keys(l).length||0===Object.keys(d).length?function(){if(0===Object.keys(l).length&&document.querySelector(".ht_ctc_chat_data"))try{var t,e=(null===(t=document.querySelector(".ht_ctc_chat_data"))||void 0===t?void 0:t.getAttribute("data-settings"))||"";l=JSON.parse(e),window.ht_ctc_chat_var=l}catch(t){}0===Object.keys(d).length&&(d={g_an_event_name:"click to chat",pixel_event_name:"Click to Chat by HoliThemes",pixel_event_type:"trackCustom",g_an_params:["g_an_param_1","g_an_param_2","g_an_param_3"],g_an_param_1:{key:"number",value:"{number}"},g_an_param_2:{key:"title",value:"{title}"},g_an_param_3:{key:"url",value:"{url}"},pixel_params:["pixel_param_1","pixel_param_2","pixel_param_3","pixel_param_4"],pixel_param_1:{key:"Category",value:"Click to Chat for WhatsApp"},pixel_param_2:{key:"return_type",value:"chat"},pixel_param_3:{key:"ID",value:"{number}"},pixel_param_4:{key:"Title",value:"{title}"}},window.ht_ctc_variables=d),h()}():h();var E=l.hook_v?l.hook_v:""})})();
  • click-to-chat-for-whatsapp/trunk/new/inc/assets/js/dev/app.dev.js

    r3369409 r3386465  
    10071007            // If GA is enabled
    10081008            if ( ctc.ga ) {
    1009                 console.log( 'google analytics' );
     1009                console.log('google analytics');
    10101010
    10111011                // Use custom event name or default
     
    10461046                // Keep track of whether we added gtag manually
    10471047                var is_ctc_add_gtag = 'no';
     1048                var measurement_ids = [];
    10481049
    10491050                // If Google Tag Manager's dataLayer is present
     
    10811082                            if ( tag_id.startsWith( 'G-' ) || tag_id.startsWith( 'GT-' ) ) {
    10821083                                ga_parms.send_to = tag_id;
     1084
     1085                                console.log('gtag event - send_to: ' + tag_id);
     1086                                console.log('g_event_name: ' + g_event_name);
     1087                                console.log( 'ga_parms: ' );
    10831088                                console.log( ga_parms );
    1084 
    1085                                 console.log( 'gtag event - send_to: ' + tag_id );
    10861089
    10871090                                gtag( 'event', g_event_name, ga_parms );
     
    10911094                        }
    10921095
    1093                         // Try to get GA tag IDs from global tag data
    1094                         if (
    1095                             window.google_tag_data &&
    1096                             window.google_tag_data.tidr &&
    1097                             window.google_tag_data.tidr.destination
    1098                         ) {
    1099                             console.log( 'google_tag_data tidr destination' );
    1100                             console.log( window.google_tag_data.tidr.destination );
    1101 
    1102                             // Trigger gtag event for each tag ID
    1103                             for ( var tag_id in window.google_tag_data.tidr.destination ) {
    1104                                 console.log( 'google_tag_data destination - loop: ' + tag_id );
    1105                                 call_gtag( tag_id );
     1096                        /**
     1097                         * Helper: Add unique ID to measurement_ids array
     1098                         */
     1099                        function addMeasurementId(id, source) {
     1100                            if (id && typeof id === 'string' && id.trim() !== '') {
     1101                                if (!measurement_ids.includes(id)) {
     1102                                    console.log(`✔️ Added ${id} (from ${source})`);
     1103                                    measurement_ids.push(id);
     1104                                }
    11061105                            }
    11071106                        }
    11081107
    1109                         // Scan through dataLayer for tag IDs
    1110                         dataLayer.forEach( function ( i ) {
    1111                             console.log( 'datalayer - loop' );
    1112                             console.log( i );
    1113                             if ( i[ 0 ] == 'config' && i[ 1 ] ) {
    1114                                 tag_id = i[ 1 ];
    1115                                 console.log( 'datalayer - loop - tag_id: ' + tag_id );
    1116                                 call_gtag( tag_id );
     1108                        /**
     1109                         * From google_tag_data.tidr.destination
     1110                         */
     1111                        try {
     1112                            const tidr = window.google_tag_data?.tidr;
     1113                            if (tidr?.destination && typeof tidr.destination === 'object') {
     1114                                console.log('google_tag_data.tidr.destination:', tidr.destination);
     1115                                Object.keys(tidr.destination).forEach(tag_id => {
     1116                                    addMeasurementId(tag_id, 'google_tag_data.destination');
     1117                                });
    11171118                            }
     1119                        } catch (err) {
     1120                            console.warn('Error reading google_tag_data.tidr.destination', err);
     1121                        }
     1122
     1123                        /**
     1124                         * From google_tag_data.tidr.container → destinations[]
     1125                         */
     1126                        try {
     1127                            const containers = window.google_tag_data?.tidr?.container;
     1128                            if (containers && typeof containers === 'object') {
     1129                                Object.values(containers).forEach(container => {
     1130                                    if (Array.isArray(container.destinations)) {
     1131                                        container.destinations.forEach(dest => {
     1132                                            if (typeof dest === 'string' && dest.startsWith('G-')) {
     1133                                                addMeasurementId(dest, 'google_tag_data.container.destinations');
     1134                                            }
     1135                                        });
     1136                                    }
     1137                                });
     1138                            }
     1139                        } catch (err) {
     1140                            console.warn('Error reading google_tag_data.tidr.container', err);
     1141                        }
     1142
     1143                        /**
     1144                         * From dataLayer[] (fallback)
     1145                         */
     1146                        try {
     1147                            if (Array.isArray(window.dataLayer)) {
     1148                                window.dataLayer.forEach(item => {
     1149                                    if (Array.isArray(item) && item[0] === 'config' && typeof item[1] === 'string') {
     1150                                        addMeasurementId(item[1], 'dataLayer.config');
     1151                                    }
     1152                                    else if (item?.send_to && typeof item.send_to === 'string') {
     1153                                        addMeasurementId(item.send_to, 'dataLayer.send_to');
     1154                                    }
     1155                                });
     1156                            }
     1157                        } catch (err) {
     1158                            console.warn('Error scanning dataLayer', err);
     1159                        }
     1160                       
     1161
     1162                        console.log( 'Final unique measurement_ids:: ' );
     1163                        console.log( measurement_ids );
     1164
     1165                        // Call gtag for each unique measurement ID
     1166                        measurement_ids.forEach( function ( id ) {
     1167                            call_gtag( id );
    11181168                        } );
     1169                       
     1170
    11191171                    } catch ( e ) { }
    11201172                }
    11211173
    11221174                // Fallback: if no gtag events were sent and gtag exists, send the default event
    1123                 if ( 0 == gtag_count && 'no' == is_ctc_add_gtag ) {
     1175                if (0 == gtag_count && 'no' == is_ctc_add_gtag) {
     1176                    console.log('gtag_count is 0 and gtag is not created by plugin. - sending default event');
    11241177                    if ( typeof gtag !== 'undefined' ) {
    1125                         console.log( 'calling gtag - default' );
     1178                        console.log('calling gtag - default (no specifc send to parm. ' + 'g_event_name: ' + g_event_name);
     1179                        console.log( 'ga_parms: ' );
     1180                        console.log( ga_parms );
    11261181                        gtag( 'event', g_event_name, ga_parms );
    11271182                    } else if ( typeof ga !== 'undefined' && typeof ga.getAll !== 'undefined' ) {
     
    11381193            // Push analytics event to GTM dataLayer
    11391194            if ( typeof dataLayer !== 'undefined' ) {
    1140                 console.log( 'dataLayer' );
     1195                console.log('dataLayer');
     1196
     1197                // legacy
    11411198                dataLayer.push( {
    11421199                    event: 'Click to Chat',
     
    11491206                    event_action: ga_action,
    11501207                    ref: 'dataLayer push',
    1151                 } );
     1208                });
     1209               
     1210                // new since 3.40. using admin settings.
     1211                const pushParams = {
     1212                    ...(ga_parms ?? {}),
     1213                    event: g_event_name ?? 'chat_click',
     1214                    ref: 'dataLayer push ga admin values',
     1215                };
     1216                dataLayer.push(pushParams);
     1217                console.debug('dataLayer event pushed:', pushParams);
    11521218            }
    11531219
  • click-to-chat-for-whatsapp/trunk/readme.txt

    r3369409 r3386465  
    44Requires PHP: 5.6
    55Contributors: HoliThemes
    6 Stable tag: 4.29
     6Stable tag: 4.30
    77Tags: whatsapp, whatsapp business, click to chat, whatsapp chat, WooCommerce WhatsApp
    88License: GPLv2 or later
     
    542542== Changelog ==
    543543
     544= 4.30 =
     545* Enchancement: Google Analytics feature.
     546
    544547= 4.29 =
    545548* Settings to load JavaScript files as Normal, Async, or Defer for improved performance.
Note: See TracChangeset for help on using the changeset viewer.