Event Tracking for Gravity Forms - Version 2.1.0

Version Description

  • Released 2018-01-10
  • Enhancement: Added Matomo (formerly Piwik) support
Download this release

Release Info

Developer ronalfy
Plugin Icon 128x128 Event Tracking for Gravity Forms
Version 2.1.0
Comparing to
See all releases

Code changes from version 2.0.9 to 2.1.0

README.txt CHANGED
@@ -1,26 +1,26 @@
1
  === Event Tracking for Gravity Forms ===
2
- Contributors: ronalfy, bigwing, nmarks
3
- Tags: gravity forms, google analytics, google tag manager, event tracking
4
  Requires at least:4.0
5
  Tested up to: 4.9
6
- Stable tag: 2.0.9
7
  Requires PHP: 5.6
 
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Easily add event tracking using Gravity Forms and your Google Analytics or Google Tag Manager account.
12
 
13
  == Description ==
14
 
15
- This plugin provides an easy way to add event tracking to your Gravity Forms using Google Analytics or Google Tag Manager.
16
-
17
- Properly track for submissions as events/conversions in Google Analytics.
18
 
19
  Also supports:
20
 
21
  * Pagination events
22
  * JS only events
23
  * Google Tag Manager
 
24
 
25
  = Setup Guide =
26
  Looking for help setting things up? [Read Our Setup Guide](https://bigwing.com/nest/gravity-forms-event-tracking-google-analytics)
@@ -29,9 +29,11 @@ Looking for help setting things up? [Read Our Setup Guide](https://bigwing.com/n
29
  - Gravity Forms 2.0+
30
  - Google Analytics Universal Analytics
31
  - Google Tag Manager (optional)
 
32
 
33
  = Features =
34
  - Submit events to Google Analytics using the Measurement Protocol, JavaScript, or using Google Tag Manager
 
35
  - Add multiple event feeds with conditionals
36
  - Custom event categories, actions, labels and even values
37
  - Track form pagination events
@@ -93,12 +95,16 @@ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gra
93
 
94
  == Screenshots ==
95
 
96
- 1. The Gravity Forms setting screen where you setup your UA ID.
97
  2. The form settings feed list.
98
  3. The feed settings page
99
 
100
  == Changelog ==
101
 
 
 
 
 
102
  = 2.0.9 =
103
  * Released 2017-11-29
104
  * Bug fix: added host name to measurement protocol due to filters blocking the conversion.
@@ -211,5 +217,5 @@ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gra
211
 
212
  == Upgrade Notice ==
213
 
214
- = 2.0.9 =
215
- Numerous fixes to the measurement protocol. Please verify your conversions.
1
  === Event Tracking for Gravity Forms ===
2
+ Contributors: ronalfy, bigwing, nmarks, kzeni
3
+ Tags: gravity forms, google analytics, google tag manager, matomo, piwik, event tracking
4
  Requires at least:4.0
5
  Tested up to: 4.9
6
+ Stable tag: 2.1.0
7
  Requires PHP: 5.6
8
+ Donate link: https://mediaron.com/contribute/
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
12
+ Easily add event tracking using Gravity Forms and your Google Analytics, Google Tag Manager, or Matomo (formerly Piwik) account.
13
 
14
  == Description ==
15
 
16
+ This plugin provides an easy way to add event tracking to your Gravity Forms using Google Analytics, Google Tag Manager, or Matomo (formerly Piwik).
 
 
17
 
18
  Also supports:
19
 
20
  * Pagination events
21
  * JS only events
22
  * Google Tag Manager
23
+ * Matomo (formerly Piwik)
24
 
25
  = Setup Guide =
26
  Looking for help setting things up? [Read Our Setup Guide](https://bigwing.com/nest/gravity-forms-event-tracking-google-analytics)
29
  - Gravity Forms 2.0+
30
  - Google Analytics Universal Analytics
31
  - Google Tag Manager (optional)
32
+ - Matomo (formerly Piwik) account (optional)
33
 
34
  = Features =
35
  - Submit events to Google Analytics using the Measurement Protocol, JavaScript, or using Google Tag Manager
36
+ - Submit events using Matomo (formerly Piwik)
37
  - Add multiple event feeds with conditionals
38
  - Custom event categories, actions, labels and even values
39
  - Track form pagination events
95
 
96
  == Screenshots ==
97
 
98
+ 1. The Gravity Forms setting screen where you setup your event tracking.
99
  2. The form settings feed list.
100
  3. The feed settings page
101
 
102
  == Changelog ==
103
 
104
+ = 2.1.0 =
105
+ * Released 2018-01-10
106
+ * Enhancement: Added Matomo (formerly Piwik) support
107
+
108
  = 2.0.9 =
109
  * Released 2017-11-29
110
  * Bug fix: added host name to measurement protocol due to filters blocking the conversion.
217
 
218
  == Upgrade Notice ==
219
 
220
+ = 2.1.0 =
221
+ Enhancement: Added Matomo (formerly Piwik) support
gravity-forms-event-tracking.php CHANGED
@@ -2,15 +2,15 @@
2
  /**
3
  * Plugin Name: Gravity Forms Event Tracking
4
  * Plugin URI: https://wordpress.org/plugins/gravity-forms-google-analytics-event-tracking/
5
- * Description: Add Google Analytics event tracking to your Gravity Forms with ease.
6
- * Version: 2.0.9
7
  * Author: Ronald Huereca
8
  * Author URI: https://mediaron.com
9
  * Text Domain: gravity-forms-google-analytics-event-tracking
10
  * License: GPL-2.0+
11
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
  * Domain Path: /languages
13
- * Developer Credit: Nathan Marks
14
  */
15
 
16
  // If this file is called directly, abort.
@@ -183,6 +183,39 @@ class GFGAET {
183
  return false;
184
  }
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  /**
187
  * Autoload class files.
188
  *
@@ -228,6 +261,7 @@ class GFGAET {
228
  public function pagination( $form, $source_page_number, $current_page_number ) {
229
  $pagination = GFGAET_Pagination::get_instance();
230
  $pagination->paginate( $form, $source_page_number, $current_page_number );
 
231
  }
232
  }
233
 
2
  /**
3
  * Plugin Name: Gravity Forms Event Tracking
4
  * Plugin URI: https://wordpress.org/plugins/gravity-forms-google-analytics-event-tracking/
5
+ * Description: Add event tracking to your Gravity Forms with ease using Google Analytics, Tag Manager, or Matomo (formerly Piwik).
6
+ * Version: 2.1.0
7
  * Author: Ronald Huereca
8
  * Author URI: https://mediaron.com
9
  * Text Domain: gravity-forms-google-analytics-event-tracking
10
  * License: GPL-2.0+
11
  * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
  * Domain Path: /languages
13
+ * Developer Credit: Nathan Marks, Kurt Zenisek
14
  */
15
 
16
  // If this file is called directly, abort.
183
  return false;
184
  }
185
 
186
+ /**
187
+ * Check to see if Matomo (formerly Piwik) has been configured
188
+ *
189
+ * @since 2.1.0
190
+ * @return string/bool Returns string UA code, false otherwise
191
+ */
192
+ public static function is_matomo_configured() {
193
+ $gravity_forms_add_on_settings = get_option( 'gravityformsaddon_GFGAET_UA_settings', array() );
194
+ if( isset( $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_matomo_url' ] ) && isset( $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_matomo_siteid' ] ) ){ // Both the Matomo URL and Site ID have been specified
195
+ return true;
196
+ }else{
197
+ return false;
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Checks whether Matomo (formerly Piwik) JavaScript only mode is activated for sending events.
203
+ *
204
+ * @since 2.1.0
205
+ *
206
+ * @return bool true if Matomo JavaScript only, false if not
207
+ */
208
+ public static function is_matomo_js_only() {
209
+ $gravity_forms_add_on_settings = get_option( 'gravityformsaddon_GFGAET_UA_settings', false );
210
+ if ( ! isset( $gravity_forms_add_on_settings[ 'matomo_mode' ] ) ) {
211
+ return false;
212
+ }
213
+ if ( 'matomo_js' == $gravity_forms_add_on_settings[ 'matomo_mode' ] ) {
214
+ return true;
215
+ }
216
+ return false;
217
+ }
218
+
219
  /**
220
  * Autoload class files.
221
  *
261
  public function pagination( $form, $source_page_number, $current_page_number ) {
262
  $pagination = GFGAET_Pagination::get_instance();
263
  $pagination->paginate( $form, $source_page_number, $current_page_number );
264
+ $pagination->matomo_paginate( $form, $source_page_number, $current_page_number );
265
  }
266
  }
267
 
includes/GFGAET_Matomo_HTTP_API.php ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class GFGAET_Matomo_HTTP_API {
3
+
4
+ private $endpoint = ''; // Tracking HTTP API Endpoint
5
+ private $_id = ''; // Unique Visitor ID
6
+ private $idsite = ''; // Site ID
7
+ private $rec = 1; // Required for tracking
8
+ private $apiv = 1; // API Version (currently v1)
9
+ private $rand = ''; // Random value to help avoid the tracking request being cached by the browser or a proxy
10
+ private $action_name = ''; // Event category
11
+ private $e_c = ''; // Event category
12
+ private $e_a = ''; // Event action
13
+ private $e_n = ''; // Event Label
14
+ private $e_v = ''; // Event Value
15
+ private $url = ''; // Full URL
16
+
17
+ public function init() {
18
+ $this->_id = $this->create_client_id();
19
+
20
+ if ( GFGAET::is_matomo_configured() ) {
21
+
22
+ $gravity_forms_add_on_settings = get_option( 'gravityformsaddon_GFGAET_UA_settings', false );
23
+
24
+ $this->endpoint = rtrim($gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_matomo_url' ],'/').'/piwik.php'; // Provided Tracking HTTP API Endpoint (auto-remove trailing slash in provided URL to then include our own [prevent worrying if the trailing slash was or wasn't provided.])
25
+
26
+ $this->idsite = $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_matomo_siteid' ]; // Site ID
27
+ }
28
+
29
+ $this->rand = uniqid('',false); // Random value to help avoid the tracking request being cached by the browser or a proxy
30
+
31
+ }
32
+
33
+ public function set_matomo_event_category( $event_category ) {
34
+ $this->action_name = urlencode($event_category);
35
+ $this->e_c = urlencode($event_category);
36
+ }
37
+
38
+ public function set_matomo_event_action( $event_action ) {
39
+ $this->e_a = urlencode($event_action);
40
+ }
41
+
42
+ public function set_matomo_event_label( $event_label ) {
43
+ $this->e_n = urlencode($event_label);
44
+ }
45
+
46
+ public function set_matomo_event_value( $event_value ) {
47
+ $this->e_v = urlencode($event_value);
48
+ }
49
+
50
+ public function set_matomo_document_location( $document_location ) {
51
+ $this->url = urlencode($document_location);
52
+ }
53
+
54
+ public function send_matomo() {
55
+
56
+ if ( GFGAET::is_matomo_configured() ) {
57
+
58
+ // Get variables in wp_remote_post body format
59
+ $matomo_mp_vars = array(
60
+ //'_id',
61
+ 'idsite',
62
+ 'rec',
63
+ 'apiv',
64
+ 'rand',
65
+ 'action_name',
66
+ 'e_c',
67
+ 'e_a',
68
+ 'e_n',
69
+ 'e_v',
70
+ 'url',
71
+ );
72
+ $matomo_mp_body = array();
73
+ foreach( $matomo_mp_vars as $index => $matomo_mp_var ) {
74
+ if ( empty( $this->{$matomo_mp_vars[$index]} ) ) continue; // Empty params cause the payload to fail in testing
75
+ $matomo_mp_body[$matomo_mp_var] = $this->{$matomo_mp_vars[$index]};
76
+ }
77
+
78
+ // Add Payload
79
+ $payload = add_query_arg( $matomo_mp_body, $this->endpoint );
80
+
81
+ // Perform the POST
82
+ $response = wp_remote_get( esc_url_raw( $payload ) );
83
+
84
+ }
85
+
86
+ }
87
+
88
+
89
+ /**
90
+ * Create a GUID on Client specific values
91
+ *
92
+ * @return string
93
+ */
94
+ private function create_client_id() {
95
+
96
+ // collect user specific data
97
+ if ( isset( $_COOKIE['_ga'] ) ) {
98
+
99
+ $ga_cookie = explode( '.', $_COOKIE['_ga'] );
100
+ if( isset( $ga_cookie[2] ) ) {
101
+
102
+ // check if uuid
103
+ if( $this->check_UUID( $ga_cookie[2] ) ) {
104
+
105
+ // uuid set in cookie
106
+ return $ga_cookie[2];
107
+ }
108
+ elseif( isset( $ga_cookie[2]) && isset( $ga_cookie[3] ) ) {
109
+
110
+ // google default client id
111
+ return $ga_cookie[2] . '.' . $ga_cookie[3];
112
+ }
113
+ }
114
+ }
115
+
116
+ // nothing found - return random uuid client id
117
+ return $this->generate_UUID();
118
+ }
119
+
120
+ /**
121
+ * Check if is a valid UUID v4
122
+ *
123
+ * @param $uuid
124
+ * @return int
125
+ */
126
+ private function check_UUID( $uuid ) {
127
+ return preg_match('#^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$#i', $uuid );
128
+ }
129
+
130
+ /**
131
+ * Generate UUID v4 function - needed to generate a CID when one isn't available
132
+ *
133
+ * @author Andrew Moore http://www.php.net/manual/en/function.uniqid.php#94959
134
+ * @return string
135
+ */
136
+ private function generate_UUID() {
137
+ return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
138
+ // 32 bits for "time_low"
139
+ mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
140
+
141
+ // 16 bits for "time_mid"
142
+ mt_rand( 0, 0xffff ),
143
+
144
+ // 16 bits for "time_hi_and_version",
145
+ // four most significant bits holds version number 4
146
+ mt_rand( 0, 0x0fff ) | 0x4000,
147
+
148
+ // 16 bits, 8 bits for "clk_seq_hi_res",
149
+ // 8 bits for "clk_seq_low",
150
+ // two most significant bits holds zero and one for variant DCE1.1
151
+ mt_rand( 0, 0x3fff ) | 0x8000,
152
+
153
+ // 48 bits for "node"
154
+ mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
155
+ );
156
+ }
157
+ }
158
+
159
+ ?>
includes/GFGAET_Pagination.php CHANGED
@@ -44,7 +44,7 @@ class GFGAET_Pagination {
44
  if ( false !== $ua_code ) {
45
  $event = new GFGAET_Measurement_Protocol();
46
  $event->init();
47
-
48
  /**
49
  * Filter: gform_pagination_event_category
50
  *
@@ -140,4 +140,85 @@ class GFGAET_Pagination {
140
  }
141
 
142
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  }
44
  if ( false !== $ua_code ) {
45
  $event = new GFGAET_Measurement_Protocol();
46
  $event->init();
47
+
48
  /**
49
  * Filter: gform_pagination_event_category
50
  *
140
  }
141
 
142
  }
143
+
144
+ /**
145
+ * Send pagination events.
146
+ *
147
+ * @since 2.0.0
148
+ *
149
+ * @param array $form The form arguments
150
+ * @param int @source_page_number The original page number
151
+ * @param int $current_page_number The new page number
152
+ */
153
+ public function matomo_paginate( $form, $source_page_number, $current_page_number ) {
154
+
155
+ if ( GFGAET::is_matomo_configured() ) {
156
+ $event = new GFGAET_Matomo_HTTP_API();
157
+ $event->init();
158
+
159
+ /**
160
+ * Filter: gform_pagination_event_category
161
+ *
162
+ * Filter the event category dynamically
163
+ *
164
+ * @since 2.0.0
165
+ *
166
+ * @param string $category Event Category
167
+ * @param array $form Gravity Form form array
168
+ * @param int $source_page_number Source page number
169
+ * @param int $current_page_number Current Page Number
170
+ */
171
+ $event_category = apply_filters( 'gform_pagination_event_category', 'form', $form, $source_page_number, $current_page_number );
172
+
173
+ /**
174
+ * Filter: gform_pagination_event_action
175
+ *
176
+ * Filter the event action dynamically
177
+ *
178
+ * @since 2.0.0
179
+ *
180
+ * @param string $action Event Action
181
+ * @param array $form Gravity Form form array
182
+ * @param int $source_page_number Source page number
183
+ * @param int $current_page_number Current Page Number
184
+ */
185
+ $event_action = apply_filters( 'gform_pagination_event_action', 'pagination', $form, $source_page_number, $current_page_number );
186
+
187
+ /**
188
+ * Filter: gform_pagination_event_label
189
+ *
190
+ * Filter the event label dynamically
191
+ *
192
+ * @since 2.0.0
193
+ *
194
+ * @param string $label Event Label
195
+ * @param array $form Gravity Form form array
196
+ * @param int $source_page_number Source page number
197
+ * @param int $current_page_number Current Page Number
198
+ */
199
+ $event_label = sprintf( '%s::%d::%d', esc_html( $form['title'] ), absint( $source_page_number ), absint( $current_page_number ) );
200
+ $event_label = apply_filters( 'gform_pagination_event_label', $event_label, $form, $source_page_number, $current_page_number );
201
+
202
+ $event->set_matomo_event_category( $event_category );
203
+ $event->set_matomo_event_action( $event_action );
204
+ $event->set_matomo_event_label( $event_label );
205
+
206
+ if ( GFGAET::is_matomo_js_only() ) {
207
+ ?>
208
+ <script>
209
+ if ( typeof window.parent._paq != 'undefined' ) {
210
+
211
+ window.parent._paq.push(['trackEvent', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>']);
212
+
213
+ }
214
+ </script>
215
+ <?php
216
+ return;
217
+ }
218
+
219
+ // Submit the Matomo (formerly Piwik) event
220
+ $event->send_matomo();
221
+ }
222
+
223
+ }
224
  }
includes/GFGAET_Submission_Feeds.php CHANGED
@@ -214,6 +214,8 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
214
 
215
  // Push the event to google
216
  $this->push_event( $entry, $form, $ga_event_data );
 
 
217
  }
218
 
219
  /**
@@ -238,6 +240,8 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
238
 
239
  // Push the event to google
240
  $this->push_event( $entry, $form, $ga_event_data );
 
 
241
  }
242
 
243
  /**
@@ -404,12 +408,111 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
404
 
405
  //Push out the event to each UA code
406
  foreach( $google_analytics_codes as $ua_code ) {
407
-
408
  // Submit the event
409
  $event->send( $ua_code );
410
  }
411
  }
412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  /**
414
  * Get the event value for payment entries
415
  *
@@ -465,11 +568,6 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
465
  //Check for a valid UA code
466
  $feed_ua_code = isset( $settings[ 'gaEventUA' ] ) ? $settings[ 'gaEventUA' ] : '';
467
  $ua_codes = $this->get_ua_codes( $feed_ua_code, $this->get_ga_id() );
468
- if ( empty( $ua_codes ) ) {
469
- GFCommon::add_error_message( __( 'You must set a UA code for event tracking to work.', 'gravity-forms-google-analytics-event-tracking' ) );
470
- return $feed_id;
471
- }
472
-
473
 
474
  if ( $is_valid ) {
475
  $settings = $this->filter_settings( $sections, $settings );
@@ -545,7 +643,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
545
  "type" => "text",
546
  "name" => "gaEventUA",
547
  "class" => "medium",
548
- "tooltip" => sprintf( '<h6>%s</h6>%s', __( 'Google Analytics UA Code', 'gravity-forms-google-analytics-event-tracking' ), __( 'Leave empty to use global GA Code. You can enter multiple UA codes as long as they are comma separated.', 'gravity-forms-google-analytics-event-tracking' ) ),
549
  "placeholder" => $ga_id_placeholder,
550
  ),
551
  array(
214
 
215
  // Push the event to google
216
  $this->push_event( $entry, $form, $ga_event_data );
217
+ // Push the event to matomo
218
+ $this->push_matomo_event( $entry, $form, $ga_event_data );
219
  }
220
 
221
  /**
240
 
241
  // Push the event to google
242
  $this->push_event( $entry, $form, $ga_event_data );
243
+ // Push the event to matomo
244
+ $this->push_matomo_event( $entry, $form, $ga_event_data );
245
  }
246
 
247
  /**
408
 
409
  //Push out the event to each UA code
410
  foreach( $google_analytics_codes as $ua_code ) {
 
411
  // Submit the event
412
  $event->send( $ua_code );
413
  }
414
  }
415
 
416
+ /**
417
+ * Push the Matomo (formerly Piwik) Event!
418
+ *
419
+ * @since 2.1.0
420
+ * @param array $event Gravity Forms event object
421
+ * @param array $form Gravity Forms form object
422
+ */
423
+ private function push_matomo_event( $entry, $form, $ga_event_data ) {
424
+
425
+ if ( false === GFGAET::is_matomo_configured() ) return;
426
+
427
+ $event = new GFGAET_Matomo_HTTP_API();
428
+ $event->init();
429
+
430
+ // Set some defaults
431
+ $event->set_matomo_document_location( 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . str_replace( '//', '/', $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'] ) );
432
+
433
+ // Set our event object variables
434
+ /**
435
+ * Filter: gform_event_category
436
+ *
437
+ * Filter the event category dynamically
438
+ *
439
+ * @since 1.6.5
440
+ *
441
+ * @param string $category Event Category
442
+ * @param object $form Gravity Form form object
443
+ * @param object $entry Gravity Form Entry Object
444
+ */
445
+ $event_category = apply_filters( 'gform_event_category', $ga_event_data['gaEventCategory'], $form, $entry );
446
+ $event->set_matomo_event_category( $event_category );
447
+
448
+ /**
449
+ * Filter: gform_event_action
450
+ *
451
+ * Filter the event action dynamically
452
+ *
453
+ * @since 1.6.5
454
+ *
455
+ * @param string $action Event Action
456
+ * @param object $form Gravity Form form object
457
+ * @param object $entry Gravity Form Entry Object
458
+ */
459
+ $event_action = apply_filters( 'gform_event_action', $ga_event_data['gaEventAction'], $form, $entry );
460
+ $event->set_matomo_event_action( $event_action );
461
+
462
+ /**
463
+ * Filter: gform_event_label
464
+ *
465
+ * Filter the event label dynamically
466
+ *
467
+ * @since 1.6.5
468
+ *
469
+ * @param string $label Event Label
470
+ * @param object $form Gravity Form form object
471
+ * @param object $entry Gravity Form Entry Object
472
+ */
473
+ $event_label = apply_filters( 'gform_event_label', $ga_event_data['gaEventLabel'], $form, $entry );
474
+ $event->set_matomo_event_label( $event_label );
475
+
476
+ /**
477
+ * Filter: gform_event_value
478
+ *
479
+ * Filter the event value dynamically
480
+ *
481
+ * @since 1.6.5
482
+ *
483
+ * @param object $form Gravity Form form object
484
+ * @param object $entry Gravity Form Entry Object
485
+ */
486
+ $event_value = apply_filters( 'gform_event_value', $ga_event_data['gaEventValue'], $form, $entry );
487
+ if ( $event_value ) {
488
+ // Event value must be a valid float!
489
+ $event_value = GFCommon::to_number( $event_value );
490
+ $event->set_matomo_event_value( $event_value );
491
+ }
492
+
493
+ $feed_id = absint( $ga_event_data[ 'feed_id' ] );
494
+ $entry_id = $entry['id'];
495
+
496
+ if ( GFGAET::is_matomo_js_only() ) {
497
+ ?>
498
+ <script>
499
+ var matomo_feed_submission = sessionStorage.getItem('matomo_feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>');
500
+ if ( null == matomo_feed_submission ) {
501
+ if ( typeof window.parent._paq != 'undefined' ) {
502
+
503
+ window.parent._paq.push(['trackEvent', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>']);
504
+
505
+ sessionStorage.setItem('matomo_feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>', true );
506
+ }
507
+ }
508
+ </script>
509
+ <?php
510
+ return;
511
+ }
512
+ // Submit the Matomo (formerly Piwik) event
513
+ $event->send_matomo();
514
+ }
515
+
516
  /**
517
  * Get the event value for payment entries
518
  *
568
  //Check for a valid UA code
569
  $feed_ua_code = isset( $settings[ 'gaEventUA' ] ) ? $settings[ 'gaEventUA' ] : '';
570
  $ua_codes = $this->get_ua_codes( $feed_ua_code, $this->get_ga_id() );
 
 
 
 
 
571
 
572
  if ( $is_valid ) {
573
  $settings = $this->filter_settings( $sections, $settings );
643
  "type" => "text",
644
  "name" => "gaEventUA",
645
  "class" => "medium",
646
+ "tooltip" => sprintf( '<h6>%s</h6>%s', __( 'Google Analytics UA Code (Optional)', 'gravity-forms-google-analytics-event-tracking' ), __( 'Leave empty to use global GA Code. You can enter multiple UA codes as long as they are comma separated.', 'gravity-forms-google-analytics-event-tracking' ) ),
647
  "placeholder" => $ga_id_placeholder,
648
  ),
649
  array(
includes/GFGAET_UA.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  GFForms::include_addon_framework();
3
  class GFGAET_UA extends GFAddOn {
4
- protected $_version = '2.0';
5
  protected $_min_gravityforms_version = '1.8.20';
6
  protected $_slug = 'GFGAET_UA';
7
  protected $_path = 'gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php';
@@ -14,7 +14,7 @@ class GFGAET_UA extends GFAddOn {
14
  protected $_capabilities_settings_page = 'gravityforms_event_tracking';
15
  protected $_capabilities_form_settings = 'gravityforms_event_tracking';
16
  protected $_capabilities_uninstall = 'gravityforms_event_tracking_uninstall';
17
-
18
  private static $_instance = null;
19
 
20
  /**
@@ -26,13 +26,13 @@ class GFGAET_UA extends GFAddOn {
26
  if ( self::$_instance == null ) {
27
  self::$_instance = new self();
28
  }
29
-
30
  return self::$_instance;
31
  }
32
-
33
  public function init() {
34
  parent::init();
35
-
36
  // Migrate old GA Code over to new add-on
37
  $ga_options = get_option( 'gravityformsaddon_GFGAET_UA_settings', false );
38
  if ( ! $ga_options ) {
@@ -41,19 +41,19 @@ class GFGAET_UA extends GFAddOn {
41
  update_option( 'gravityformsaddon_GFGAET_UA_settings', $old_ga_option );
42
  }
43
  }
44
-
45
  }
46
-
47
  /**
48
  * Plugin settings fields
49
- *
50
  * @return array Array of plugin settings
51
  */
52
  public function plugin_settings_fields() {
53
  return array(
54
  array(
55
- 'title' => __( 'Google Analytics', 'gravity-forms-google-analytics-event-tracking' ),
56
- 'description' => __( 'Need help? <a target="_blank" href="https://bigwing.com/nest/gravity-forms-event-tracking-google-analytics/">See our guide</a>.', 'gravity-forms-google-analytics-event-tracking' ),
57
  'fields' => array(
58
  array(
59
  'name' => 'gravity_forms_event_tracking_ua',
@@ -61,14 +61,8 @@ class GFGAET_UA extends GFAddOn {
61
  'label' => __( 'UA Tracking ID', 'gravity-forms-google-analytics-event-tracking' ),
62
  'type' => 'text',
63
  'class' => 'small',
64
-
65
  ),
66
- )
67
- ),
68
- array(
69
- 'title' => __( 'Advanced', 'gravity-forms-google-analytics-event-tracking' ),
70
- 'description' => __( 'By default, events are sent using the measurement protocol. You can change to using pure Google Analytics and Google Tag Manager if your forms are Ajax only.', 'gravity-forms-google-analytics-event-tracking' ),
71
- 'fields' => array(
72
  array(
73
  'type' => 'radio',
74
  'name' => 'mode',
@@ -78,7 +72,7 @@ class GFGAET_UA extends GFAddOn {
78
  'choices' => array(
79
  array(
80
  'name' => 'ga_on',
81
- 'tooltip' => esc_html__( 'Forms must be Ajax only', 'sometextdomain' ),
82
  'label' => esc_html__( 'Google Analytics (Ajax only)', 'gravity-forms-google-analytics-event-tracking' ),
83
  'value' => 'ga'
84
  ),
@@ -90,12 +84,60 @@ class GFGAET_UA extends GFAddOn {
90
  ),
91
  array(
92
  'name' => 'gmp_on',
93
- 'tooltip' => esc_html__( 'Events will be sent using the measurement protocol.', 'sometextdomain' ),
94
  'label' => esc_html__( 'Measurement Protocol (Default)', 'gravity-forms-google-analytics-event-tracking' ),
95
  'value' => 'gmp'
96
  ),
97
  ),
98
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  array(
100
  'type' => 'radio',
101
  'name' => 'ajax_only',
@@ -115,8 +157,9 @@ class GFGAET_UA extends GFAddOn {
115
  ),
116
  ),
117
  ),
118
- ),
119
  )
 
120
  );
121
  }
122
- }
1
  <?php
2
  GFForms::include_addon_framework();
3
  class GFGAET_UA extends GFAddOn {
4
+ protected $_version = '2.0';
5
  protected $_min_gravityforms_version = '1.8.20';
6
  protected $_slug = 'GFGAET_UA';
7
  protected $_path = 'gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php';
14
  protected $_capabilities_settings_page = 'gravityforms_event_tracking';
15
  protected $_capabilities_form_settings = 'gravityforms_event_tracking';
16
  protected $_capabilities_uninstall = 'gravityforms_event_tracking_uninstall';
17
+
18
  private static $_instance = null;
19
 
20
  /**
26
  if ( self::$_instance == null ) {
27
  self::$_instance = new self();
28
  }
29
+
30
  return self::$_instance;
31
  }
32
+
33
  public function init() {
34
  parent::init();
35
+
36
  // Migrate old GA Code over to new add-on
37
  $ga_options = get_option( 'gravityformsaddon_GFGAET_UA_settings', false );
38
  if ( ! $ga_options ) {
41
  update_option( 'gravityformsaddon_GFGAET_UA_settings', $old_ga_option );
42
  }
43
  }
44
+
45
  }
46
+
47
  /**
48
  * Plugin settings fields
49
+ *
50
  * @return array Array of plugin settings
51
  */
52
  public function plugin_settings_fields() {
53
  return array(
54
  array(
55
+ 'title' => __( 'Google Analytics and Google Tag Manager', 'gravity-forms-google-analytics-event-tracking' ),
56
+ 'description' => '<p>' . __( 'By default, events are sent using the measurement protocol. You can change to using pure Google Analytics and Google Tag Manager if your forms are Ajax only.', 'gravity-forms-google-analytics-event-tracking' ) . '</p><p>' . __( 'Need help? <a target="_blank" href="https://bigwing.com/nest/gravity-forms-event-tracking-google-analytics/">See our guide</a>.</p>', 'gravity-forms-google-analytics-event-tracking' ),
57
  'fields' => array(
58
  array(
59
  'name' => 'gravity_forms_event_tracking_ua',
61
  'label' => __( 'UA Tracking ID', 'gravity-forms-google-analytics-event-tracking' ),
62
  'type' => 'text',
63
  'class' => 'small',
64
+
65
  ),
 
 
 
 
 
 
66
  array(
67
  'type' => 'radio',
68
  'name' => 'mode',
72
  'choices' => array(
73
  array(
74
  'name' => 'ga_on',
75
+ 'tooltip' => esc_html__( 'Forms must be Ajax only', 'gravity-forms-google-analytics-event-tracking' ),
76
  'label' => esc_html__( 'Google Analytics (Ajax only)', 'gravity-forms-google-analytics-event-tracking' ),
77
  'value' => 'ga'
78
  ),
84
  ),
85
  array(
86
  'name' => 'gmp_on',
87
+ 'tooltip' => esc_html__( 'Events will be sent using the measurement protocol.', 'gravity-forms-google-analytics-event-tracking' ),
88
  'label' => esc_html__( 'Measurement Protocol (Default)', 'gravity-forms-google-analytics-event-tracking' ),
89
  'value' => 'gmp'
90
  ),
91
  ),
92
  ),
93
+ ),
94
+ ),
95
+ array(
96
+ 'title' => __( '<a target="_blank" href="https://matomo.org">Matomo</a> (formerly Piwik) Open Analytics Platform', 'gravity-forms-google-analytics-event-tracking' ),
97
+ 'fields' => array(
98
+ array(
99
+ 'name' => 'gravity_forms_event_tracking_matomo_url',
100
+ 'tooltip' => __( 'Enter your Matomo (formerly Piwik) URL. This is the same URL you use to access your Matomo instance (ex. http://www.example.com/matomo/.)', 'gravity-forms-google-analytics-event-tracking' ),
101
+ 'label' => __( 'Matomo URL', 'gravity-forms-google-analytics-event-tracking' ),
102
+ 'type' => 'text',
103
+ 'class' => 'small',
104
+
105
+ ),
106
+ array(
107
+ 'name' => 'gravity_forms_event_tracking_matomo_siteid',
108
+ 'tooltip' => __( 'Enter your Site ID (ex. 2 or J2O1NDvxzmMB if using the Protect Track ID plugin.)', 'gravity-forms-google-analytics-event-tracking' ),
109
+ 'label' => __( 'Site ID', 'gravity-forms-google-analytics-event-tracking' ),
110
+ 'type' => 'text',
111
+ 'class' => 'small',
112
+
113
+ ),
114
+ array(
115
+ 'type' => 'radio',
116
+ 'name' => 'matomo_mode',
117
+ 'horizontal' => false,
118
+ 'default_value' => 'matomo_http',
119
+ 'label' => 'How would you like to send <strong>Matomo</strong> events?',
120
+ 'choices' => array(
121
+ array(
122
+ 'name' => 'matomo_js_on',
123
+ 'tooltip' => esc_html__( 'Forms must be Ajax only. Events will be sent using the <a target="_blank" href="https://matomo.org/docs/event-tracking/#javascript-trackevent">`trackEvent` JavaScript function</a>.', 'gravity-forms-google-analytics-event-tracking' ),
124
+ 'label' => esc_html__( 'JavaScript `trackEvent` Function (Ajax only)', 'gravity-forms-google-analytics-event-tracking' ),
125
+ 'value' => 'matomo_js'
126
+ ),
127
+ array(
128
+ 'name' => 'matomo_http_on',
129
+ 'tooltip' => esc_html__( 'Events will be sent using the <a target="_blank" href="https://developer.matomo.org/api-reference/tracking-api">Tracking HTTP API</a>.', 'gravity-forms-google-analytics-event-tracking' ),
130
+ 'label' => esc_html__( 'Tracking HTTP API (Default)', 'gravity-forms-google-analytics-event-tracking' ),
131
+ 'value' => 'matomo_http'
132
+ ),
133
+ ),
134
+ ),
135
+ )
136
+ ),
137
+ array(
138
+ 'title' => __( 'Advanced', 'gravity-forms-google-analytics-event-tracking' ),
139
+ 'description' => __( 'This will make all your forms Ajax only for options that require it.', 'gravity-forms-google-analytics-event-tracking' ),
140
+ 'fields' => array(
141
  array(
142
  'type' => 'radio',
143
  'name' => 'ajax_only',
157
  ),
158
  ),
159
  ),
160
+ )
161
  )
162
+
163
  );
164
  }
165
+ }