Skip to content

Commit

Permalink
Support gtag (#8)
Browse files Browse the repository at this point in the history
* add the js code for the gtag compatible event

* add the settings needed to choose between old Analytics and new Gtag

* update .pot file

* Fix typo

* updated translation

* Update Readme, changelog

* ver 1.2
  • Loading branch information
garubi authored Oct 12, 2020
1 parent c20e44a commit b4566e5
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 39 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@
**Requires at least:** 4.5
**Tested up to:** 5.5.1
**Requires PHP:** 7.0
**Stable tag:** 1.1.4
**Stable tag:** 1.2
**License:** GPLv2 or later
**License URI:** https://www.gnu.org/licenses/gpl-2.0.html

Send an event to Google Analytics when a visitor interacts with the Taw.kto Chat widget.

## Description ##

This plugin sends an Event to Google Analytics if the visitors chat for at least 60 seconds, or if he submit the "Chat Offline Form"
This plugin sends an Event to Google Analytics if the visitors chat for a configurable amount of time (default 60 seconds), or if he submit the "Chat Offline Form".

Since ver. 1.2 the pluging let you choose if the generated event would be compatible with the newer gtag syntax or with the old Analytics syntax.

This plugins requires that on your site is active a Tawk.to chat widget. The easyest way to install a Tawk.to Chat on your site is by the [official Tawk.to WordPress plugin](https://it.wordpress.org/plugins/tawkto-live-chat/) but you can copy-paste the widget code from Tawk.to dashboard too.

This plugin supports automatic updates via [GitHub Updater plugin](https://github.com/afragen/github-updater)



## Changelog ##

### 1.2 ###
* Added support for the new gtag syntax

### 1.1.4 ###
* Other fix for issue #6

Expand Down
30 changes: 30 additions & 0 deletions admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ public function analytics_events_for_tawkto_chat_page_init() {
);


add_settings_section(
'analytics_events_for_tawkto_chat_setting_section_version', // id
__( 'Installed Analytics version', 'tawkto-analytics-event' ), // title
array( $this, 'analytics_events_for_tawkto_chat_section_info' ), // callback
'analytics-events-for-tawkto-chat-admin' // page
);

add_settings_field(
'analytics_version', // id
__( 'Select the Analytics version used on this site', 'tawkto-analytics-event' ), // title
array( $this, 'analytics_version_callback' ), // callback
'analytics-events-for-tawkto-chat-admin', // page
'analytics_events_for_tawkto_chat_setting_section_version' // section
);

add_settings_section(
'analytics_events_for_tawkto_chat_setting_section_ongoing', // id
__( 'Ongoing Chat event', 'tawkto-analytics-event' ), // title
Expand Down Expand Up @@ -124,6 +139,10 @@ public function analytics_events_for_tawkto_chat_sanitize($input) {
$sanitary_values['enable_ongoing'] = $input['enable_ongoing'];
}

if ( isset( $input['analytics_version'] ) ) {
$sanitary_values['analytics_version'] = sanitize_text_field( $input['analytics_version'] );
}

if ( isset( $input['chat_duration'] ) ) {
$sanitary_values['chat_duration'] = sanitize_text_field( $input['chat_duration'] );
}
Expand Down Expand Up @@ -162,6 +181,17 @@ public function enable_ongoing_callback() {
);
}

public function analytics_version_callback() {
printf(
'<input type="radio" name="TAE_options[analytics_version]" id="analytics_version" value="gtag" %s> <code>gtag</code> (newer)',
( isset( $this->analytics_events_for_tawkto_chat_options['analytics_version'] ) && $this->analytics_events_for_tawkto_chat_options['analytics_version'] == 'gtag' ) ? 'checked' : ''
);
printf(
'<br><input type="radio" name="TAE_options[analytics_version]" id="analytics_version" value="analytics" %s> <code>analytics</code> (older)',
( isset( $this->analytics_events_for_tawkto_chat_options['analytics_version'] ) && $this->analytics_events_for_tawkto_chat_options['analytics_version'] == 'analytics' ) ? 'checked' : ''
);
}

public function chat_duration_callback() {
printf(
'<input class="regular-text" type="text" name="TAE_options[chat_duration]" id="chat_duration" value="%s">',
Expand Down
Binary file modified languages/tawkto-analytics-event-it_IT.mo
Binary file not shown.
38 changes: 22 additions & 16 deletions languages/tawkto-analytics-event-it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# This file is distributed under the same license as the Analytics Events for Tawk.to Chat plugin.
msgid ""
msgstr ""
"Project-Id-Version: Analytics Events for Tawk.to Chat 1.1.1\n"
"Project-Id-Version: Analytics Events for Tawk.to Chat 1.2-beta\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/tawkto-analytics-"
"event\n"
"POT-Creation-Date: 2020-09-02 13:07+0100\n"
"PO-Revision-Date: 2020-09-02 13:20+0100\n"
"POT-Creation-Date: 2020-10-12 15:44+0100\n"
"PO-Revision-Date: 2020-10-12 15:45+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
Expand All @@ -18,7 +18,6 @@ msgstr ""
"X-Domain: tawkto-analytics-event\n"

#. Plugin Name of the plugin
#| msgid "Analytics Events for Tawkto Chat"
msgid "Analytics Events for Tawk.to Chat"
msgstr "Analytics Events for Tawk.to Chat"

Expand All @@ -27,7 +26,6 @@ msgid "https://github.com/garubi/tawkto-analytics-event"
msgstr "https://github.com/garubi/tawkto-analytics-event"

#. Description of the plugin
#| msgid "Send an event to Google Analytics when a visitor interacts with the Tawkto Chat widget."
msgid "Send an event to Google Analytics when a visitor interacts with the Tawk.to Chat widget."
msgstr "Invia un Evento a Google Analytics quando un visitatore interagisce con il widget della chat di Tawk.to."

Expand All @@ -48,50 +46,58 @@ msgid "Tawk.to Chat Analytics"
msgstr "Tawk.to Chat Analytics"

#: admin/settings.php:52
msgid "Installed Analytics version"
msgstr "Versione di Analytics installata"

#: admin/settings.php:59
msgid "Select the Analytics version used on this site"
msgstr "Scegli la versione di Analytics usata in questo sito"

#: admin/settings.php:67
msgid "Ongoing Chat event"
msgstr "Evento per Chat in corso"

#: admin/settings.php:59
#: admin/settings.php:74
msgid "Enable sending Event when Chat is OnGoing for XX seconds"
msgstr "Abilita l'invio dell'Evento quando la Chat è in corso per XX secondi"

#: admin/settings.php:67
#: admin/settings.php:82
msgid "Minimum Chat duration for trigger the event (seconds)"
msgstr "Durata minima della chat per inviare l'Evento (secondi)"

#: admin/settings.php:75
#: admin/settings.php:90
msgid "Analytics Event Category for Ongoing"
msgstr "Categoria dell'Evento Analytics per Chat in corso"

#: admin/settings.php:83
#: admin/settings.php:98
msgid "Analytics Event Action for Ongoing"
msgstr "Azione dell'Evento Analytics per Chat in corso"

#: admin/settings.php:91
#: admin/settings.php:106
msgid "Offline Chat event"
msgstr "Evento per Chat offline"

#: admin/settings.php:98
#: admin/settings.php:113
msgid "Enable sending Event when a form from an offline Chat is submitted"
msgstr "Abilita l'invio dell'Evento quando la Chat è offline"

#: admin/settings.php:106
#: admin/settings.php:121
msgid "Analytics Event Category for Offline"
msgstr "Categoria dell'Evento Analytics per Chat offline"

#: admin/settings.php:114
#: admin/settings.php:129
msgid "Analytics Event Action for Offline"
msgstr "Azione dell'Evento Analytics per Chat offline"

#: tawkto-analytics-event.php:35
#: tawkto-analytics-event.php:36
#: tawkto-analytics-event.php:39
msgid "Chat"
msgstr "Chat"

#: tawkto-analytics-event.php:38
#: tawkto-analytics-event.php:37
msgid "Ongoing chat"
msgstr "Chat In corso"

#: tawkto-analytics-event.php:39
#: tawkto-analytics-event.php:40
msgid "Form sent from offline chat"
msgstr "Invio form per chat offline"
34 changes: 21 additions & 13 deletions languages/tawkto-analytics-event.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the same license as the Analytics Events for Tawk.to Chat plugin.
msgid ""
msgstr ""
"Project-Id-Version: Analytics Events for Tawk.to Chat 1.1.1\n"
"Project-Id-Version: Analytics Events for Tawk.to Chat 1.2-beta\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/tawkto-analytics-event\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2020-09-02T11:02:14+00:00\n"
"POT-Creation-Date: 2020-10-12T13:38:05+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.2.0\n"
"X-Domain: tawkto-analytics-event\n"
Expand Down Expand Up @@ -43,50 +43,58 @@ msgid "Tawk.to Chat Analytics"
msgstr ""

#: admin/settings.php:52
msgid "Ongoing Chat event"
msgid "Installed Analytics version"
msgstr ""

#: admin/settings.php:59
msgid "Enable sending Event when Chat is OnGoing for XX seconds"
msgid "Select the Analytics version used on this site"
msgstr ""

#: admin/settings.php:67
msgid "Ongoing Chat event"
msgstr ""

#: admin/settings.php:74
msgid "Enable sending Event when Chat is OnGoing for XX seconds"
msgstr ""

#: admin/settings.php:82
msgid "Minimum Chat duration for trigger the event (seconds)"
msgstr ""

#: admin/settings.php:75
#: admin/settings.php:90
msgid "Analytics Event Category for Ongoing"
msgstr ""

#: admin/settings.php:83
#: admin/settings.php:98
msgid "Analytics Event Action for Ongoing"
msgstr ""

#: admin/settings.php:91
#: admin/settings.php:106
msgid "Offline Chat event"
msgstr ""

#: admin/settings.php:98
#: admin/settings.php:113
msgid "Enable sending Event when a form from an offline Chat is submitted"
msgstr ""

#: admin/settings.php:106
#: admin/settings.php:121
msgid "Analytics Event Category for Offline"
msgstr ""

#: admin/settings.php:114
#: admin/settings.php:129
msgid "Analytics Event Action for Offline"
msgstr ""

#: tawkto-analytics-event.php:35
#: tawkto-analytics-event.php:36
#: tawkto-analytics-event.php:39
msgid "Chat"
msgstr ""

#: tawkto-analytics-event.php:38
#: tawkto-analytics-event.php:37
msgid "Ongoing chat"
msgstr ""

#: tawkto-analytics-event.php:39
#: tawkto-analytics-event.php:40
msgid "Form sent from offline chat"
msgstr ""
21 changes: 18 additions & 3 deletions public/js/tawkto-api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ var ongoing_check_id= setInterval(function(){
if ( diff > 1000 * TAE_VAR.chat_min_lenght){
(TAE_VAR.debug) ? console.log('Send event Ongoing chat to Analytics') : '';
if( TAE_VAR.enable_ongoing == 'true' ){
ga('send', 'event', { eventCategory: TAE_VAR.eventCategoryChatOngoing, eventAction: TAE_VAR.eventActionChatOngoing, eventLabel: TAE_VAR.chat_min_lenght + ' seconds'});
}
if( TAE_VAR.analytics_version == 'analytics' ){
ga('send', 'event', { eventCategory: TAE_VAR.eventCategoryChatOngoing, eventAction: TAE_VAR.eventActionChatOngoing, eventLabel: TAE_VAR.chat_min_lenght + ' seconds'});
}
else{
gtag('event', TAE_VAR.eventActionChatOngoing, {
'event_category': TAE_VAR.eventCategoryChatOngoing,
'event_label': TAE_VAR.chat_min_lenght + ' seconds',
});
}
}
else{
console.log('Sending event Ongoing chat to Analytics is disabled')
}
Expand All @@ -37,7 +45,14 @@ var ongoing_check_id= setInterval(function(){
Tawk_API.onOfflineSubmit = function(data){
(TAE_VAR.debug) ? console.log('Send event Chat offline submit to Analytics') : '';
if( TAE_VAR.enable_offline == 'true' ){
ga('send', 'event', { eventCategory: TAE_VAR.eventCategoryonOfflineSubmit, eventAction: TAE_VAR.eventActiononOfflineSubmit});
if( TAE_VAR.analytics_version == 'analytics' ){
ga('send', 'event', { eventCategory: TAE_VAR.eventCategoryonOfflineSubmit, eventAction: TAE_VAR.eventActiononOfflineSubmit});
}
else{
gtag('event', TAE_VAR.eventActiononOfflineSubmit, {
'event_category': TAE_VAR.eventCategoryonOfflineSubmit,
});
}
}
else{
console.log('Send event Chat offline submit to Analytics is disabled')
Expand Down
11 changes: 9 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@ Tags: chat, tawkto, analytics
Requires at least: 4.5
Tested up to: 5.5.1
Requires PHP: 7.0
Stable tag: 1.1.4
Stable tag: 1.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Send an event to Google Analytics when a visitor interacts with the Taw.kto Chat widget.

== Description ==

This plugin sends an Event to Google Analytics if the visitors chat for at least 60 seconds, or if he submit the "Chat Offline Form"
This plugin sends an Event to Google Analytics if the visitors chat for a configurable amount of time (default 60 seconds), or if he submit the "Chat Offline Form".

Since ver. 1.2 the pluging let you choose if the generated event would be compatible with the newer gtag syntax or with the old Analytics syntax.

This plugins requires that on your site is active a Tawk.to chat widget. The easyest way to install a Tawk.to Chat on your site is by the [official Tawk.to WordPress plugin](https://it.wordpress.org/plugins/tawkto-live-chat/) but you can copy-paste the widget code from Tawk.to dashboard too.

This plugin supports automatic updates via [GitHub Updater plugin](https://github.com/afragen/github-updater)



== Changelog ==

= 1.2 =
* Added support for the new gtag syntax

= 1.1.4 =
* Other fix for issue #6

Expand Down
8 changes: 5 additions & 3 deletions tawkto-analytics-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
* Author URI: https://garuti.it
* Text Domain: tawkto-analytics-event
* Domain Path: /languages
* Version: 1.1.4
* Version: 1.2
* GitHub Plugin URI: https://github.com/garubi/tawkto-analytics-event
*
* @package Tawkto_Analytics_Event
*/


define( 'TAE_VER', '1.1.4' );
define( 'TAE_VER', '1.2' );
define( 'TAE_URL', plugin_dir_url( __FILE__ ) );
define( 'TAE_PATH', trailingslashit(plugin_dir_path(__FILE__) ) );

Expand All @@ -30,7 +30,8 @@ function TAE_load_plugin_textdomain() {

function TAE_activate(){
$settings = array (
'enable_ongoing' => 1,
'analytics_version' => 'gtag',
'enable_ongoing' => 1,
'chat_duration' => 60,
'analytics_event_category_for_ongoing' => __( 'Chat', 'tawkto-analytics-event' ),
'analytics_event_action_for_ongoing' => __( 'Ongoing chat', 'tawkto-analytics-event' ),
Expand All @@ -54,6 +55,7 @@ function TAE_enqueue_js(){


wp_localize_script( 'tawkto_js', 'TAE_VAR', array(
'analytics_version' => $tae_options['analytics_version'],
'enable_ongoing' => ($tae_options['enable_ongoing']) ? 'true' : 'false', // Enable sending Event when Chat is OnGoing for XX seconds
'enable_offline' => ($tae_options['enable_offline']) ? 'true' : 'false', // Enable sending Event when a form from an offline Chat is submitted
'chat_min_lenght' => $tae_options['chat_duration'], // Minimum Chat duration for trigger the event
Expand Down

0 comments on commit b4566e5

Please sign in to comment.