-
Notifications
You must be signed in to change notification settings - Fork 0
/
tawkto-analytics-event.php
68 lines (56 loc) · 2.9 KB
/
tawkto-analytics-event.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Plugin Name: Analytics Events for Tawk.to Chat
* Plugin URI: https://github.com/garubi/tawkto-analytics-event
* Description: Send an event to Google Analytics when a visitor interacts with the Tawk.to Chat widget.
* Author: Stefano Garuti
* Author URI: https://garuti.it
* Text Domain: tawkto-analytics-event
* Domain Path: /languages
* Version: 1.2
* GitHub Plugin URI: https://github.com/garubi/tawkto-analytics-event
*
* @package Tawkto_Analytics_Event
*/
define( 'TAE_VER', '1.2' );
define( 'TAE_URL', plugin_dir_url( __FILE__ ) );
define( 'TAE_PATH', trailingslashit(plugin_dir_path(__FILE__) ) );
require_once( TAE_PATH . 'admin/settings.php');
function TAE_load_plugin_textdomain() {
load_plugin_textdomain( 'tawkto-analytics-event', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'TAE_load_plugin_textdomain' );
register_activation_hook( __FILE__, 'TAE_activate' );
register_deactivation_hook( __FILE__, 'TAE_deactivate');
function TAE_activate(){
$settings = array (
'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' ),
'enable_offline' => 1,
'analytics_event_category_for_offline' => __( 'Chat', 'tawkto-analytics-event' ),
'analytics_event_action_for_offline' => __( 'Form sent from offline chat', 'tawkto-analytics-event' ),
);
add_option( 'TAE_options', $settings );
}
function TAE_deactivate(){
delete_option( 'TAE_options' );
}
add_action( 'wp_enqueue_scripts', 'TAE_enqueue_js' );
function TAE_enqueue_js(){
wp_enqueue_script( 'tawkto_js', TAE_URL . '/public/js/tawkto-api-client.js', '', TAE_VER, true );
$tae_options = get_option( 'TAE_options' ); // Array of All Options
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
'eventCategoryChatOngoing' => $tae_options['analytics_event_category_for_ongoing'], // Analytics Event Category for Ongoing,
'eventActionChatOngoing' => $tae_options['analytics_event_action_for_ongoing'], // Analytics Event Action for Ongoing,
'eventCategoryonOfflineSubmit' => $tae_options['analytics_event_category_for_offline'], // Analytics Event Category for Offline
'eventActiononOfflineSubmit' => $tae_options['analytics_event_action_for_offline'], // Analytics Event Action for Offline
'debug' => WP_DEBUG,
));
}