WhatsApp me - Version 4.1.9

Version Description

  • SECURE escape input values on wp-admin (thanks to Camilo @camilo517)
  • NEW can pass custom data layer name for gtag.js and GTM with filter joinchat_get_settings
  • FIX also send Google Analytics 4 event when Universal Analytics and GA4 are present
Download this release

Release Info

Developer pacotole
Plugin Icon 128x128 WhatsApp me
Version 4.1.9
Comparing to
See all releases

Code changes from version 4.1.8 to 4.1.9

README.txt CHANGED
@@ -5,7 +5,7 @@ Tags: whatsapp business, whatsapp, click to chat, button, whatsapp support chat,
5
  Requires at least: 3.5.0
6
  Tested up to: 5.6
7
  Requires PHP: 5.3
8
- Stable tag: 4.1.8
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -169,10 +169,11 @@ If Universal Analtics (analytics.js) detected:
169
 
170
  `ga('send', 'event', 'JoinChat', 'click', out_url })`
171
 
172
- If your tracker doesn't have the standard name 'ga' you can set your custom name with 'ga_tracker' setting:
173
 
174
  `add_filter( 'joinchat_get_settings', function( $settings ){
175
- $settings['ga_tracker'] = 'my_custom_GA_name';
 
176
  return $settings;
177
  } );`
178
 
@@ -214,6 +215,11 @@ There is a Javascript event that Join.chat triggers automatically before launch
214
 
215
  == Changelog ==
216
 
 
 
 
 
 
217
  = 4.1.8 =
218
  * Front script better settings validation
219
  * FIX error with some prices on variable replacement
5
  Requires at least: 3.5.0
6
  Tested up to: 5.6
7
  Requires PHP: 5.3
8
+ Stable tag: 4.1.9
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
169
 
170
  `ga('send', 'event', 'JoinChat', 'click', out_url })`
171
 
172
+ If your site don't have standard names for UA tracker ('ga') or data layer ('dataLayer') you can set your custom names with this filter:
173
 
174
  `add_filter( 'joinchat_get_settings', function( $settings ){
175
+ $settings['ga_tracker'] = 'gaCustom';
176
+ $settings['data_layer'] = 'dataLayerCustom';
177
  return $settings;
178
  } );`
179
 
215
 
216
  == Changelog ==
217
 
218
+ = 4.1.9 =
219
+ * **SECURE** escape input values on wp-admin (thanks to Camilo @camilo517)
220
+ * NEW can pass custom data layer name for gtag.js and GTM with filter `joinchat_get_settings`
221
+ * FIX also send Google Analytics 4 event when Universal Analytics and GA4 are present
222
+
223
  = 4.1.8 =
224
  * Front script better settings validation
225
  * FIX error with some prices on variable replacement
admin/class-joinchat-admin.php CHANGED
@@ -522,7 +522,7 @@ class JoinChatAdmin {
522
 
523
  switch ( $field_id ) {
524
  case 'telephone':
525
- $output = '<input id="joinchat_phone" ' . ( $this->enhanced_phone ? 'data-' : '' ) . 'name="joinchat[telephone]" value="' . $value . '" type="text" style="width:15em">' .
526
  '<p class="description">' . __( "Contact phone number <strong>(the button will not be shown if it's empty)</strong>", 'creame-whatsapp-me' ) . '</p>' .
527
  '<p class="joinchat-addon">' . sprintf(
528
  __( 'Add unlimited numbers with %1$s or multiple contacts with %2$s', 'creame-whatsapp-me' ),
@@ -551,7 +551,7 @@ class JoinChatAdmin {
551
 
552
  $output = '<div id="joinchat_button_image_wrapper">' .
553
  '<div id="joinchat_button_image_holder" ' . ( $image ? "style=\"background-size:cover; background-image:url('$image');\"" : '' ) . '></div>' .
554
- '<input id="joinchat_button_image" name="joinchat[button_image]" type="hidden" value="' . $value . '">' .
555
  '<input id="joinchat_button_image_add" type="button" value="' . esc_attr__( 'Select an image', 'creame-whatsapp-me' ) . '" class="button-primary" ' .
556
  'data-title="' . esc_attr__( 'Select button image', 'creame-whatsapp-me' ) . '" data-button="' . esc_attr__( 'Use image', 'creame-whatsapp-me' ) . '"> ' .
557
  '<input id="joinchat_button_image_remove" type="button" value="' . esc_attr__( 'Remove', 'creame-whatsapp-me' ) . '" class="button-secondary' . ( $image ? '' : ' joinchat-hidden' ) . '">' .
@@ -563,12 +563,12 @@ class JoinChatAdmin {
563
  break;
564
 
565
  case 'button_tip':
566
- $output = '<input id="joinchat_button_tip" name="joinchat[button_tip]" value="' . $value . '" type="text" maxlength="40" class="regular-text" placeholder="' . esc_attr__( '💬 Need help?', 'creame-whatsapp-me' ) . '"> ' .
567
  '<p class="description">' . __( 'Short text shown next to button', 'creame-whatsapp-me' ) . '</p>';
568
  break;
569
 
570
  case 'button_delay':
571
- $output = '<input id="joinchat_button_delay" name="joinchat[button_delay]" value="' . $value . '" type="number" min="0" max="120" style="width:5em"> ' . __( 'seconds', 'creame-whatsapp-me' ) .
572
  '<p class="description">' . __( 'Time since the page is opened until the button is displayed', 'creame-whatsapp-me' ) . '</p>';
573
  break;
574
 
@@ -579,7 +579,7 @@ class JoinChatAdmin {
579
  break;
580
 
581
  case 'message_text':
582
- $output = '<textarea id="joinchat_message_text" name="joinchat[message_text]" rows="4" class="regular-text" placeholder="' . esc_attr__( "Hello 👋\nCan we help you?", 'creame-whatsapp-me' ) . '">' . $value . '</textarea>' .
583
  '<p class="description">' . __( 'Define a text to encourage users to contact by WhatsApp', 'creame-whatsapp-me' ) . '</p>' .
584
  '<p class="joinchat-addon">' . sprintf(
585
  __( 'Add links, images, videos and more with %s', 'creame-whatsapp-me' ),
@@ -588,22 +588,22 @@ class JoinChatAdmin {
588
  break;
589
 
590
  case 'message_send':
591
- $output = '<textarea id="joinchat_message_send" name="joinchat[message_send]" rows="3" class="regular-text" placeholder="' . esc_attr__( 'Hi *{SITE}*! I need more info about {TITLE} {URL}', 'creame-whatsapp-me' ) . '">' . $value . '</textarea>' .
592
  '<p class="description">' . __( 'Predefined text for the first message the user will send you', 'creame-whatsapp-me' ) . '</p>';
593
  break;
594
 
595
  case 'message_start':
596
- $output = '<input id="joinchat_message_start" name="joinchat[message_start]" value="' . $value . '" type="text" maxlength="20" class="regular-text" placeholder="' . esc_attr__( 'Open chat', 'creame-whatsapp-me' ) . '"> ' .
597
  '<p class="description">' . __( 'Text to open chat on Chat Window button', 'creame-whatsapp-me' ) . '</p>';
598
  break;
599
 
600
  case 'message_delay':
601
- $output = '<input id="joinchat_message_delay" name="joinchat[message_delay]" value="' . $value . '" type="number" min="0" max="120" style="width:5em"> ' . __( 'seconds (0 disabled)', 'creame-whatsapp-me' ) .
602
  '<p class="description">' . __( 'Chat Window auto displays after delay', 'creame-whatsapp-me' ) . '</p>';
603
  break;
604
 
605
  case 'message_views':
606
- $output = '<input id="joinchat_message_views" name="joinchat[message_views]" value="' . $value . '" type="number" min="1" max="120" style="width:5em"> ' .
607
  '<p class="description">' . __( 'Chat Window auto displays from this number of page views', 'creame-whatsapp-me' ) . '</p>';
608
  break;
609
 
@@ -614,7 +614,7 @@ class JoinChatAdmin {
614
  break;
615
 
616
  case 'color':
617
- $output = '<input id="joinchat_color" name="joinchat[color]" value="' . $value . '" type="text" data-default-color="#25d366"> ';
618
  break;
619
 
620
  case 'dark_mode':
@@ -638,7 +638,7 @@ class JoinChatAdmin {
638
  __( 'WhatsApp Logo', 'creame-whatsapp-me' ) . '</label><br>' .
639
  '<label><input name="joinchat[header]" value="__custom__" type="radio"' . checked( '__custom__', $check, false ) . '> ' .
640
  __( 'Custom:', 'creame-whatsapp-me' ) . '</label> ' .
641
- '<input id="joinchat_header_custom" name="joinchat[header_custom]" value="' . $value . '" type="text" maxlength="40" class="regular-text" placeholder="">' .
642
  '</fieldset>';
643
  break;
644
 
@@ -940,15 +940,15 @@ class JoinChatAdmin {
940
  <?php wp_nonce_field( 'joinchat_data', 'joinchat_nonce' ); ?>
941
  <p>
942
  <label for="joinchat_phone"><?php _e( 'Telephone', 'creame-whatsapp-me' ); ?></label><br>
943
- <input id="joinchat_phone" <?php echo $this->enhanced_phone ? 'data-' : ''; ?>name="joinchat_telephone" value="<?php echo $metadata['telephone']; ?>" type="text" placeholder="<?php echo $placeholders['telephone']; ?>">
944
  </p>
945
  <p>
946
  <label for="joinchat_message"><?php _e( 'Call to Action', 'creame-whatsapp-me' ); ?></label><br>
947
- <textarea id="joinchat_message" name="joinchat_message" rows="2" placeholder="<?php echo $placeholders['message_text']; ?>" class="large-text"><?php echo $metadata['message_text']; ?></textarea>
948
  </p>
949
  <p>
950
  <label for="joinchat_message_send"><?php _e( 'Message', 'creame-whatsapp-me' ); ?></label><br>
951
- <textarea id="joinchat_message_send" name="joinchat_message_send" rows="2" placeholder="<?php echo $placeholders['message_send']; ?>" class="large-text"><?php echo $metadata['message_send']; ?></textarea>
952
  <?php if ( count( $metabox_vars ) ) : ?>
953
  <small><?php _e( 'Can use vars', 'creame-whatsapp-me' ); ?> <code>{<?php echo join( '}</code> <code>{', $metabox_vars ); ?>}</code></small>
954
  <?php endif; ?>
522
 
523
  switch ( $field_id ) {
524
  case 'telephone':
525
+ $output = '<input id="joinchat_phone" ' . ( $this->enhanced_phone ? 'data-' : '' ) . 'name="joinchat[telephone]" value="' . esc_attr( $value ) . '" type="text" style="width:15em">' .
526
  '<p class="description">' . __( "Contact phone number <strong>(the button will not be shown if it's empty)</strong>", 'creame-whatsapp-me' ) . '</p>' .
527
  '<p class="joinchat-addon">' . sprintf(
528
  __( 'Add unlimited numbers with %1$s or multiple contacts with %2$s', 'creame-whatsapp-me' ),
551
 
552
  $output = '<div id="joinchat_button_image_wrapper">' .
553
  '<div id="joinchat_button_image_holder" ' . ( $image ? "style=\"background-size:cover; background-image:url('$image');\"" : '' ) . '></div>' .
554
+ '<input id="joinchat_button_image" name="joinchat[button_image]" type="hidden" value="' . intval( $value ) . '">' .
555
  '<input id="joinchat_button_image_add" type="button" value="' . esc_attr__( 'Select an image', 'creame-whatsapp-me' ) . '" class="button-primary" ' .
556
  'data-title="' . esc_attr__( 'Select button image', 'creame-whatsapp-me' ) . '" data-button="' . esc_attr__( 'Use image', 'creame-whatsapp-me' ) . '"> ' .
557
  '<input id="joinchat_button_image_remove" type="button" value="' . esc_attr__( 'Remove', 'creame-whatsapp-me' ) . '" class="button-secondary' . ( $image ? '' : ' joinchat-hidden' ) . '">' .
563
  break;
564
 
565
  case 'button_tip':
566
+ $output = '<input id="joinchat_button_tip" name="joinchat[button_tip]" value="' . esc_attr( $value ) . '" type="text" maxlength="40" class="regular-text" placeholder="' . esc_attr__( '💬 Need help?', 'creame-whatsapp-me' ) . '"> ' .
567
  '<p class="description">' . __( 'Short text shown next to button', 'creame-whatsapp-me' ) . '</p>';
568
  break;
569
 
570
  case 'button_delay':
571
+ $output = '<input id="joinchat_button_delay" name="joinchat[button_delay]" value="' . intval( $value ) . '" type="number" min="0" max="120" style="width:5em"> ' . __( 'seconds', 'creame-whatsapp-me' ) .
572
  '<p class="description">' . __( 'Time since the page is opened until the button is displayed', 'creame-whatsapp-me' ) . '</p>';
573
  break;
574
 
579
  break;
580
 
581
  case 'message_text':
582
+ $output = '<textarea id="joinchat_message_text" name="joinchat[message_text]" rows="4" class="regular-text" placeholder="' . esc_attr__( "Hello 👋\nCan we help you?", 'creame-whatsapp-me' ) . '">' . esc_textarea( $value ) . '</textarea>' .
583
  '<p class="description">' . __( 'Define a text to encourage users to contact by WhatsApp', 'creame-whatsapp-me' ) . '</p>' .
584
  '<p class="joinchat-addon">' . sprintf(
585
  __( 'Add links, images, videos and more with %s', 'creame-whatsapp-me' ),
588
  break;
589
 
590
  case 'message_send':
591
+ $output = '<textarea id="joinchat_message_send" name="joinchat[message_send]" rows="3" class="regular-text" placeholder="' . esc_attr__( 'Hi *{SITE}*! I need more info about {TITLE} {URL}', 'creame-whatsapp-me' ) . '">' . esc_textarea( $value ) . '</textarea>' .
592
  '<p class="description">' . __( 'Predefined text for the first message the user will send you', 'creame-whatsapp-me' ) . '</p>';
593
  break;
594
 
595
  case 'message_start':
596
+ $output = '<input id="joinchat_message_start" name="joinchat[message_start]" value="' . esc_attr( $value ) . '" type="text" maxlength="20" class="regular-text" placeholder="' . esc_attr__( 'Open chat', 'creame-whatsapp-me' ) . '"> ' .
597
  '<p class="description">' . __( 'Text to open chat on Chat Window button', 'creame-whatsapp-me' ) . '</p>';
598
  break;
599
 
600
  case 'message_delay':
601
+ $output = '<input id="joinchat_message_delay" name="joinchat[message_delay]" value="' . intval( $value ) . '" type="number" min="0" max="120" style="width:5em"> ' . __( 'seconds (0 disabled)', 'creame-whatsapp-me' ) .
602
  '<p class="description">' . __( 'Chat Window auto displays after delay', 'creame-whatsapp-me' ) . '</p>';
603
  break;
604
 
605
  case 'message_views':
606
+ $output = '<input id="joinchat_message_views" name="joinchat[message_views]" value="' . intval( $value ) . '" type="number" min="1" max="120" style="width:5em"> ' .
607
  '<p class="description">' . __( 'Chat Window auto displays from this number of page views', 'creame-whatsapp-me' ) . '</p>';
608
  break;
609
 
614
  break;
615
 
616
  case 'color':
617
+ $output = '<input id="joinchat_color" name="joinchat[color]" value="' . esc_attr( $value ) . '" type="text" data-default-color="#25d366"> ';
618
  break;
619
 
620
  case 'dark_mode':
638
  __( 'WhatsApp Logo', 'creame-whatsapp-me' ) . '</label><br>' .
639
  '<label><input name="joinchat[header]" value="__custom__" type="radio"' . checked( '__custom__', $check, false ) . '> ' .
640
  __( 'Custom:', 'creame-whatsapp-me' ) . '</label> ' .
641
+ '<input id="joinchat_header_custom" name="joinchat[header_custom]" value="' . esc_attr( $value ) . '" type="text" maxlength="40" class="regular-text" placeholder="">' .
642
  '</fieldset>';
643
  break;
644
 
940
  <?php wp_nonce_field( 'joinchat_data', 'joinchat_nonce' ); ?>
941
  <p>
942
  <label for="joinchat_phone"><?php _e( 'Telephone', 'creame-whatsapp-me' ); ?></label><br>
943
+ <input id="joinchat_phone" <?php echo $this->enhanced_phone ? 'data-' : ''; ?>name="joinchat_telephone" value="<?php echo esc_attr( $metadata['telephone'] ); ?>" type="text" placeholder="<?php echo $placeholders['telephone']; ?>">
944
  </p>
945
  <p>
946
  <label for="joinchat_message"><?php _e( 'Call to Action', 'creame-whatsapp-me' ); ?></label><br>
947
+ <textarea id="joinchat_message" name="joinchat_message" rows="2" placeholder="<?php echo $placeholders['message_text']; ?>" class="large-text"><?php echo esc_textarea( $metadata['message_text'] ); ?></textarea>
948
  </p>
949
  <p>
950
  <label for="joinchat_message_send"><?php _e( 'Message', 'creame-whatsapp-me' ); ?></label><br>
951
+ <textarea id="joinchat_message_send" name="joinchat_message_send" rows="2" placeholder="<?php echo $placeholders['message_send']; ?>" class="large-text"><?php echo esc_textarea( $metadata['message_send'] ); ?></textarea>
952
  <?php if ( count( $metabox_vars ) ) : ?>
953
  <small><?php _e( 'Can use vars', 'creame-whatsapp-me' ); ?> <code>{<?php echo join( '}</code> <code>{', $metabox_vars ); ?>}</code></small>
954
  <?php endif; ?>
admin/class-joinchat-wooadmin.php CHANGED
@@ -220,20 +220,21 @@ class JoinChatWooAdmin {
220
  case 'message_text_product':
221
  $output = '<textarea id="joinchat_message_text_product" name="joinchat[message_text_product]" rows="4" class="regular-text" ' .
222
  'placeholder="' . esc_attr__( "This *{PRODUCT}* can be yours for only *{PRICE}*!\nIf you have any questions, ask us.", 'creame-whatsapp-me' ) . '">' .
223
- $value . '</textarea>' .
224
  '<p class="description">' . __( 'Define a text for your products to encourage customers to contact', 'creame-whatsapp-me' ) . '</p>';
225
  break;
226
 
227
  case 'message_text_on_sale':
228
  $output = '<textarea id="joinchat_message_text_on_sale" name="joinchat[message_text_on_sale]" rows="4" class="regular-text" ' .
229
  'placeholder="' . esc_attr__( "Save {DISCOUNT}! This *{PRODUCT}* can be yours for only ~{REGULAR}~ *{PRICE}*.\nIf you have any questions, ask us.", 'creame-whatsapp-me' ) . '">' .
230
- $value . '</textarea>' .
231
  '<p class="description">' . __( 'Define a text for your products on sale to encourage customers to contact', 'creame-whatsapp-me' ) . '</p>';
232
  break;
233
 
234
  case 'message_send_product':
235
  $output = '<textarea id="joinchat_message_send_product" name="joinchat[message_send_product]" rows="3" class="regular-text" ' .
236
- 'placeholder="' . esc_attr__( "*Hi {SITE}!*\nI have a question about *{PRODUCT} ({SKU})*", 'creame-whatsapp-me' ) . '">' . $value . '</textarea>' .
 
237
  '<p class="description">' . __( 'Predefined text for the first message the client will send you', 'creame-whatsapp-me' ) . '</p>';
238
  break;
239
  }
220
  case 'message_text_product':
221
  $output = '<textarea id="joinchat_message_text_product" name="joinchat[message_text_product]" rows="4" class="regular-text" ' .
222
  'placeholder="' . esc_attr__( "This *{PRODUCT}* can be yours for only *{PRICE}*!\nIf you have any questions, ask us.", 'creame-whatsapp-me' ) . '">' .
223
+ esc_textarea( $value ) . '</textarea>' .
224
  '<p class="description">' . __( 'Define a text for your products to encourage customers to contact', 'creame-whatsapp-me' ) . '</p>';
225
  break;
226
 
227
  case 'message_text_on_sale':
228
  $output = '<textarea id="joinchat_message_text_on_sale" name="joinchat[message_text_on_sale]" rows="4" class="regular-text" ' .
229
  'placeholder="' . esc_attr__( "Save {DISCOUNT}! This *{PRODUCT}* can be yours for only ~{REGULAR}~ *{PRICE}*.\nIf you have any questions, ask us.", 'creame-whatsapp-me' ) . '">' .
230
+ esc_textarea( $value ) . '</textarea>' .
231
  '<p class="description">' . __( 'Define a text for your products on sale to encourage customers to contact', 'creame-whatsapp-me' ) . '</p>';
232
  break;
233
 
234
  case 'message_send_product':
235
  $output = '<textarea id="joinchat_message_send_product" name="joinchat[message_send_product]" rows="3" class="regular-text" ' .
236
+ 'placeholder="' . esc_attr__( "*Hi {SITE}!*\nI have a question about *{PRODUCT} ({SKU})*", 'creame-whatsapp-me' ) . '">' .
237
+ esc_textarea( $value ) . '</textarea>' .
238
  '<p class="description">' . __( 'Predefined text for the first message the client will send you', 'creame-whatsapp-me' ) . '</p>';
239
  break;
240
  }
joinchat.php CHANGED
@@ -9,7 +9,7 @@
9
  * Plugin Name: Join.chat
10
  * Plugin URI: https://join.chat
11
  * Description: Connects a WordPress chat with WhatsApp. The best solution for marketing and support. Stop losing customers and increase your sales.
12
- * Version: 4.1.8
13
  * Author: Creame
14
  * Author URI: https://crea.me
15
  * License: GPL-2.0+
@@ -26,7 +26,7 @@ if ( ! defined( 'WPINC' ) ) {
26
  /**
27
  * Currently plugin version.
28
  */
29
- define( 'JOINCHAT_VERSION', '4.1.8' );
30
 
31
  /**
32
  * The core plugin class that is used to define internationalization,
9
  * Plugin Name: Join.chat
10
  * Plugin URI: https://join.chat
11
  * Description: Connects a WordPress chat with WhatsApp. The best solution for marketing and support. Stop losing customers and increase your sales.
12
+ * Version: 4.1.9
13
  * Author: Creame
14
  * Author URI: https://crea.me
15
  * License: GPL-2.0+
26
  /**
27
  * Currently plugin version.
28
  */
29
+ define( 'JOINCHAT_VERSION', '4.1.9' );
30
 
31
  /**
32
  * The core plugin class that is used to define internationalization,
public/js/joinchat.js CHANGED
@@ -15,36 +15,47 @@
15
  return $(sel || this.$div, this.$div);
16
  };
17
 
18
- // Trigger Google Analytics event
19
  joinchat_obj.send_event = function (label, action) {
20
  label = label || '';
21
  action = action || 'click';
22
 
23
- // Can pass setting 'ga_tracker' for custom GA tracker name
24
  // Compatible with GADP for WordPress by MonsterInsights tracker name
25
  var ga_tracker = win[this.settings.ga_tracker] || win['ga'] || win['__gaTracker'];
 
 
26
 
27
- // Send Google Analtics custom event (Universal Analtics - analytics.js) or (Global Site Tag - gtag.js)
28
  if (typeof ga_tracker == 'function' && typeof ga_tracker.getAll == 'function') {
29
  ga_tracker('set', 'transport', 'beacon');
30
  var trackers = ga_tracker.getAll();
31
  trackers.forEach(function (tracker) {
32
- tracker.send("event", 'JoinChat', action, label);
33
- });
34
- } else if (typeof gtag == 'function') {
35
- gtag('event', action, {
36
- 'event_category': 'JoinChat',
37
- 'event_label': label,
38
- 'transport_type': 'beacon'
39
  });
40
  }
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  // Send Google Tag Manager custom event
43
- if (typeof dataLayer == 'object') {
44
- dataLayer.push({
45
  'event': 'JoinChat',
46
  'eventAction': action,
47
- 'eventLabel': label
48
  });
49
  }
50
 
@@ -254,8 +265,15 @@
254
  $(doc).trigger('joinchat:start');
255
  }
256
 
257
- // Ready!!
258
- $(function () {
 
 
 
 
 
 
 
259
  joinchat_obj.$div = $('.joinchat');
260
 
261
  // Exit if no joinchat div
@@ -302,6 +320,12 @@
302
  }
303
 
304
  joinchat_obj.store.setItem('joinchat_views', parseInt(joinchat_obj.store.getItem('joinchat_views') || 0) + 1);
305
- });
 
 
 
 
 
 
306
 
307
  }(jQuery, window, document));
15
  return $(sel || this.$div, this.$div);
16
  };
17
 
18
+ // Trigger Analytics events
19
  joinchat_obj.send_event = function (label, action) {
20
  label = label || '';
21
  action = action || 'click';
22
 
23
+ // Can pass setting 'ga_tracker' for custom UA tracker name
24
  // Compatible with GADP for WordPress by MonsterInsights tracker name
25
  var ga_tracker = win[this.settings.ga_tracker] || win['ga'] || win['__gaTracker'];
26
+ // Can pass setting 'data_layer' for custom data layer name
27
+ var data_layer = win[this.settings.data_layer] || win['dataLayer'];
28
 
29
+ // Send Google Analytics custom event (Universal Analytics - analytics.js)
30
  if (typeof ga_tracker == 'function' && typeof ga_tracker.getAll == 'function') {
31
  ga_tracker('set', 'transport', 'beacon');
32
  var trackers = ga_tracker.getAll();
33
  trackers.forEach(function (tracker) {
34
+ tracker.send('event', 'JoinChat', action, label);
 
 
 
 
 
 
35
  });
36
  }
37
 
38
+ // Send Google Analytics custom event (Google Analytics 4 - gtag.js)
39
+ if (typeof gtag == 'function' && typeof data_layer == 'object') {
40
+ var ga4 = false;
41
+ data_layer.forEach(function (item) { if (item[0] == 'config' && item[1].substring(0, 2) == 'G-') ga4 = item[1]; });
42
+
43
+ if (ga4) {
44
+ gtag('event', action, {
45
+ 'event_category': 'JoinChat',
46
+ 'event_label': label,
47
+ 'send_to': ga4,
48
+ 'transport_type': 'beacon',
49
+ });
50
+ }
51
+ }
52
+
53
  // Send Google Tag Manager custom event
54
+ if (typeof data_layer == 'object') {
55
+ data_layer.push({
56
  'event': 'JoinChat',
57
  'eventAction': action,
58
+ 'eventLabel': label,
59
  });
60
  }
61
 
265
  $(doc).trigger('joinchat:start');
266
  }
267
 
268
+ // Simple run only once wrapper
269
+ function once(fn) {
270
+ return function () {
271
+ fn && fn.apply(this, arguments);
272
+ fn = null;
273
+ };
274
+ }
275
+
276
+ function on_page_ready() {
277
  joinchat_obj.$div = $('.joinchat');
278
 
279
  // Exit if no joinchat div
320
  }
321
 
322
  joinchat_obj.store.setItem('joinchat_views', parseInt(joinchat_obj.store.getItem('joinchat_views') || 0) + 1);
323
+ }
324
+
325
+ // Ready!! (in some scenarios jQuery.ready doesn't fire, this try to ensure Join.chat initialization)
326
+ var once_page_ready = once(on_page_ready);
327
+ $(once_page_ready);
328
+ $(win).on('load', once_page_ready);
329
+ doc.addEventListener('DOMContentLoaded', once_page_ready);
330
 
331
  }(jQuery, window, document));
public/js/joinchat.min.js CHANGED
@@ -1 +1 @@
1
- !function(p,u,d){"use strict";function t(){p(d).trigger("joinchat:starting");var t,o,e=1e3*joinchat_obj.settings.button_delay,n=1e3*joinchat_obj.settings.message_delay,i=!!joinchat_obj.settings.message_hash,a=!!joinchat_obj.$(".joinchat__box").length,s=parseInt(joinchat_obj.store.getItem("joinchat_views")||1)>=joinchat_obj.settings.message_views,h=-1!==(joinchat_obj.store.getItem("joinchat_hashes")||"").split(",").filter(Boolean).indexOf(joinchat_obj.settings.message_hash||"none");function c(){clearTimeout(o),joinchat_obj.chatbox_show()}function j(){joinchat_obj.save_hash(),joinchat_obj.chatbox_hide()}var _,r,b,l="joinchat--show";function g(){var t=(d.activeElement.type||"").toLowerCase();0<=["date","datetime","email","month","number","password","search","tel","text","textarea","time","url","week"].indexOf(t)?joinchat_obj.chatbox?(joinchat_obj.chatbox_hide(),setTimeout(function(){joinchat_obj.$div.removeClass("joinchat--show")},400)):joinchat_obj.$div.removeClass("joinchat--show"):joinchat_obj.$div.addClass("joinchat--show")}h||i&&n&&!joinchat_obj.settings.message_badge&&s||(l+=" joinchat--tooltip"),setTimeout(function(){joinchat_obj.$div.addClass(l)},e),i&&!h&&n&&(joinchat_obj.settings.message_badge?o=setTimeout(function(){joinchat_obj.$(".joinchat__badge").addClass("joinchat__badge--in")},e+n):s&&(o=setTimeout(c,e+n))),a&&!joinchat_obj.is_mobile&&joinchat_obj.$(".joinchat__button").on("mouseenter",function(){t=setTimeout(c,1500)}).on("mouseleave",function(){clearTimeout(t)}),joinchat_obj.$(".joinchat__button").on("click",function(){a&&!joinchat_obj.chatbox?c():(j(),joinchat_obj.open_whatsapp())}),joinchat_obj.$(".joinchat__close").on("click",j),joinchat_obj.$(".joinchat__box__scroll").on("mousewheel DOMMouseScroll",function(t){t.preventDefault();t=t.originalEvent.wheelDelta||-t.originalEvent.detail;this.scrollTop+=30*(t<0?1:-1)}),joinchat_obj.is_mobile&&(p(d).on("focus blur","input, textarea",function(t){p(t.target).closest(joinchat_obj.$div).length||(clearTimeout(_),_=setTimeout(g,200))}),p(u).on("resize",function(){clearTimeout(r),r=setTimeout(function(){joinchat_obj.$div[0].style.setProperty("--vh",window.innerHeight+"px")},200)}).trigger("resize")),p(d).on("click",'.joinchat_open, .joinchat_app, a[href="#joinchat"], a[href="#whatsapp"]',function(t){t.preventDefault(),!a||p(this).is('.joinchat_app, a[href="#whatsapp"]')?joinchat_obj.open_whatsapp():c()}),p(d).on("click",".joinchat_close",function(t){t.preventDefault(),joinchat_obj.chatbox_hide()}),a&&"IntersectionObserver"in u&&(0<(n=p(".joinchat_show, .joinchat_force_show")).length&&(b=new IntersectionObserver(function(t){p.each(t,function(){if(0<this.intersectionRatio&&(!h||p(this.target).hasClass("joinchat_force_show")))return c(),b.disconnect(),!1})}),n.each(function(){b.observe(this)}))),p(d).trigger("joinchat:start")}u.joinchat_obj=u.joinchat_obj||{},joinchat_obj=p.extend({$div:null,settings:null,store:null,chatbox:!1,is_mobile:!1},joinchat_obj),joinchat_obj.$=function(t){return p(t||this.$div,this.$div)},joinchat_obj.send_event=function(o,e){o=o||"",e=e||"click";var t=u[this.settings.ga_tracker]||u.ga||u.__gaTracker;"function"==typeof t&&"function"==typeof t.getAll?(t("set","transport","beacon"),t.getAll().forEach(function(t){t.send("event","JoinChat",e,o)})):"function"==typeof gtag&&gtag("event",e,{event_category:"JoinChat",event_label:o,transport_type:"beacon"}),"object"==typeof dataLayer&&dataLayer.push({event:"JoinChat",eventAction:e,eventLabel:o}),"function"==typeof fbq&&fbq("trackCustom","JoinChat",{eventAction:e,eventLabel:o})},joinchat_obj.whatsapp_link=function(t,o,e){return((e=void 0!==e?e:this.settings.whatsapp_web&&!this.is_mobile)?"https://web.whatsapp.com/send":"https://api.whatsapp.com/send")+"?phone="+encodeURIComponent(t)+"&text="+encodeURIComponent(o||"")},joinchat_obj.chatbox_show=function(){this.chatbox||(this.chatbox=!0,this.$div.addClass("joinchat--chatbox"),this.settings.message_badge&&this.$(".joinchat__badge").hasClass("joinchat__badge--in")&&this.$(".joinchat__badge").toggleClass("joinchat__badge--in joinchat__badge--out"),p(d).trigger("joinchat:show"))},joinchat_obj.chatbox_hide=function(){this.chatbox&&(this.chatbox=!1,this.$div.removeClass("joinchat--chatbox joinchat--tooltip"),this.settings.message_badge&&this.$(".joinchat__badge").removeClass("joinchat__badge--out"),p(d).trigger("joinchat:hide"))},joinchat_obj.save_hash=function(){var t=this.settings.message_hash||"none",o=(this.store.getItem("joinchat_hashes")||"").split(",").filter(Boolean);-1===o.indexOf(t)&&(o.push(t),this.store.setItem("joinchat_hashes",o.join(",")))},joinchat_obj.open_whatsapp=function(t,o){t={link:this.whatsapp_link(t||this.settings.telephone,o||this.settings.message_send)},o=new RegExp("^https?://(wa.me|(api|web|chat).whatsapp.com|"+location.hostname.replace(".",".")+")/.*","i");p(d).trigger("joinchat:open",[t,this.settings]),o.test(t.link)?(this.send_event(t.link),u.open(t.link,"joinchat","noopener")):console.error("Join.chat: the link doesn't seem safe, it must point to the current domain or whatsapp.com")},p(function(){if(joinchat_obj.$div=p(".joinchat"),joinchat_obj.$div.length){joinchat_obj.settings=joinchat_obj.$div.data("settings"),joinchat_obj.is_mobile=!!navigator.userAgent.match(/Android|iPhone|BlackBerry|IEMobile|Opera Mini/i);try{localStorage.setItem("test",1),localStorage.removeItem("test"),joinchat_obj.store=localStorage}catch(t){joinchat_obj.store={_data:{},setItem:function(t,o){this._data[t]=String(o)},getItem:function(t){return this._data.hasOwnProperty(t)?this._data[t]:null}}}if("object"!=typeof joinchat_obj.settings)try{joinchat_obj.settings=JSON.parse(joinchat_obj.$div.attr("data-settings"))}catch(t){joinchat_obj.settings=void 0,console.error("Join.chat: can't get settings")}joinchat_obj.settings&&joinchat_obj.settings.telephone&&(joinchat_obj.is_mobile||!joinchat_obj.settings.mobile_only?t():p(d).on("click",'.joinchat_open, .joinchat_app, a[href="#joinchat"], a[href="#whatsapp"]',function(t){t.preventDefault(),joinchat_obj.open_whatsapp()})),joinchat_obj.store.setItem("joinchat_views",parseInt(joinchat_obj.store.getItem("joinchat_views")||0)+1)}})}(jQuery,window,document);
1
+ !function(p,u,d){"use strict";function t(){p(d).trigger("joinchat:starting");var t,o,e=1e3*joinchat_obj.settings.button_delay,n=1e3*joinchat_obj.settings.message_delay,i=!!joinchat_obj.settings.message_hash,a=!!joinchat_obj.$(".joinchat__box").length,s=parseInt(joinchat_obj.store.getItem("joinchat_views")||1)>=joinchat_obj.settings.message_views,h=-1!==(joinchat_obj.store.getItem("joinchat_hashes")||"").split(",").filter(Boolean).indexOf(joinchat_obj.settings.message_hash||"none");function c(){clearTimeout(o),joinchat_obj.chatbox_show()}function j(){joinchat_obj.save_hash(),joinchat_obj.chatbox_hide()}var _,r,b,l="joinchat--show";function g(){var t=(d.activeElement.type||"").toLowerCase();0<=["date","datetime","email","month","number","password","search","tel","text","textarea","time","url","week"].indexOf(t)?joinchat_obj.chatbox?(joinchat_obj.chatbox_hide(),setTimeout(function(){joinchat_obj.$div.removeClass("joinchat--show")},400)):joinchat_obj.$div.removeClass("joinchat--show"):joinchat_obj.$div.addClass("joinchat--show")}h||i&&n&&!joinchat_obj.settings.message_badge&&s||(l+=" joinchat--tooltip"),setTimeout(function(){joinchat_obj.$div.addClass(l)},e),i&&!h&&n&&(joinchat_obj.settings.message_badge?o=setTimeout(function(){joinchat_obj.$(".joinchat__badge").addClass("joinchat__badge--in")},e+n):s&&(o=setTimeout(c,e+n))),a&&!joinchat_obj.is_mobile&&joinchat_obj.$(".joinchat__button").on("mouseenter",function(){t=setTimeout(c,1500)}).on("mouseleave",function(){clearTimeout(t)}),joinchat_obj.$(".joinchat__button").on("click",function(){a&&!joinchat_obj.chatbox?c():(j(),joinchat_obj.open_whatsapp())}),joinchat_obj.$(".joinchat__close").on("click",j),joinchat_obj.$(".joinchat__box__scroll").on("mousewheel DOMMouseScroll",function(t){t.preventDefault();t=t.originalEvent.wheelDelta||-t.originalEvent.detail;this.scrollTop+=30*(t<0?1:-1)}),joinchat_obj.is_mobile&&(p(d).on("focus blur","input, textarea",function(t){p(t.target).closest(joinchat_obj.$div).length||(clearTimeout(_),_=setTimeout(g,200))}),p(u).on("resize",function(){clearTimeout(r),r=setTimeout(function(){joinchat_obj.$div[0].style.setProperty("--vh",window.innerHeight+"px")},200)}).trigger("resize")),p(d).on("click",'.joinchat_open, .joinchat_app, a[href="#joinchat"], a[href="#whatsapp"]',function(t){t.preventDefault(),!a||p(this).is('.joinchat_app, a[href="#whatsapp"]')?joinchat_obj.open_whatsapp():c()}),p(d).on("click",".joinchat_close",function(t){t.preventDefault(),joinchat_obj.chatbox_hide()}),a&&"IntersectionObserver"in u&&(0<(n=p(".joinchat_show, .joinchat_force_show")).length&&(b=new IntersectionObserver(function(t){p.each(t,function(){if(0<this.intersectionRatio&&(!h||p(this.target).hasClass("joinchat_force_show")))return c(),b.disconnect(),!1})}),n.each(function(){b.observe(this)}))),p(d).trigger("joinchat:start")}u.joinchat_obj=u.joinchat_obj||{},joinchat_obj=p.extend({$div:null,settings:null,store:null,chatbox:!1,is_mobile:!1},joinchat_obj),joinchat_obj.$=function(t){return p(t||this.$div,this.$div)},joinchat_obj.send_event=function(o,e){o=o||"",e=e||"click";var n,t=u[this.settings.ga_tracker]||u.ga||u.__gaTracker,i=u[this.settings.data_layer]||u.dataLayer;"function"==typeof t&&"function"==typeof t.getAll&&(t("set","transport","beacon"),t.getAll().forEach(function(t){t.send("event","JoinChat",e,o)})),"function"==typeof gtag&&"object"==typeof i&&(n=!1,i.forEach(function(t){"config"==t[0]&&"G-"==t[1].substring(0,2)&&(n=t[1])}),n&&gtag("event",e,{event_category:"JoinChat",event_label:o,send_to:n,transport_type:"beacon"})),"object"==typeof i&&i.push({event:"JoinChat",eventAction:e,eventLabel:o}),"function"==typeof fbq&&fbq("trackCustom","JoinChat",{eventAction:e,eventLabel:o})},joinchat_obj.whatsapp_link=function(t,o,e){return((e=void 0!==e?e:this.settings.whatsapp_web&&!this.is_mobile)?"https://web.whatsapp.com/send":"https://api.whatsapp.com/send")+"?phone="+encodeURIComponent(t)+"&text="+encodeURIComponent(o||"")},joinchat_obj.chatbox_show=function(){this.chatbox||(this.chatbox=!0,this.$div.addClass("joinchat--chatbox"),this.settings.message_badge&&this.$(".joinchat__badge").hasClass("joinchat__badge--in")&&this.$(".joinchat__badge").toggleClass("joinchat__badge--in joinchat__badge--out"),p(d).trigger("joinchat:show"))},joinchat_obj.chatbox_hide=function(){this.chatbox&&(this.chatbox=!1,this.$div.removeClass("joinchat--chatbox joinchat--tooltip"),this.settings.message_badge&&this.$(".joinchat__badge").removeClass("joinchat__badge--out"),p(d).trigger("joinchat:hide"))},joinchat_obj.save_hash=function(){var t=this.settings.message_hash||"none",o=(this.store.getItem("joinchat_hashes")||"").split(",").filter(Boolean);-1===o.indexOf(t)&&(o.push(t),this.store.setItem("joinchat_hashes",o.join(",")))},joinchat_obj.open_whatsapp=function(t,o){t={link:this.whatsapp_link(t||this.settings.telephone,o||this.settings.message_send)},o=new RegExp("^https?://(wa.me|(api|web|chat).whatsapp.com|"+location.hostname.replace(".",".")+")/.*","i");p(d).trigger("joinchat:open",[t,this.settings]),o.test(t.link)?(this.send_event(t.link),u.open(t.link,"joinchat","noopener")):console.error("Join.chat: the link doesn't seem safe, it must point to the current domain or whatsapp.com")};var o,e=(o=function(){if(joinchat_obj.$div=p(".joinchat"),joinchat_obj.$div.length){joinchat_obj.settings=joinchat_obj.$div.data("settings"),joinchat_obj.is_mobile=!!navigator.userAgent.match(/Android|iPhone|BlackBerry|IEMobile|Opera Mini/i);try{localStorage.setItem("test",1),localStorage.removeItem("test"),joinchat_obj.store=localStorage}catch(t){joinchat_obj.store={_data:{},setItem:function(t,o){this._data[t]=String(o)},getItem:function(t){return this._data.hasOwnProperty(t)?this._data[t]:null}}}if("object"!=typeof joinchat_obj.settings)try{joinchat_obj.settings=JSON.parse(joinchat_obj.$div.attr("data-settings"))}catch(t){joinchat_obj.settings=void 0,console.error("Join.chat: can't get settings")}joinchat_obj.settings&&joinchat_obj.settings.telephone&&(joinchat_obj.is_mobile||!joinchat_obj.settings.mobile_only?t():p(d).on("click",'.joinchat_open, .joinchat_app, a[href="#joinchat"], a[href="#whatsapp"]',function(t){t.preventDefault(),joinchat_obj.open_whatsapp()})),joinchat_obj.store.setItem("joinchat_views",parseInt(joinchat_obj.store.getItem("joinchat_views")||0)+1)}},function(){o&&o.apply(this,arguments),o=null});p(e),p(u).on("load",e),d.addEventListener("DOMContentLoaded",e)}(jQuery,window,document);