Event Tracking for Gravity Forms - Version 2.4.0

Version Description

  • Released 2021-05-01
  • Requires: Gravity Forms 2.5 and above.
  • Feature: Options to install gtag and Tag Manager are available.
  • Bug Fix: Google Tag Manager no longer requires a UA code.
  • Feature: Improved interface inline with Gravity Forms 2.5.
  • Feature: Track UTM variables using Google Tag Manager.
  • Miscelleanous bug fixes and code cleanup.
Download this release

Release Info

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

Code changes from version 2.3.12 to 2.4.0

README.txt CHANGED
@@ -1,19 +1,19 @@
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.9
5
  Tested up to: 5.7
6
- Stable tag: 2.3.12
7
  Requires PHP: 5.6
8
  Donate link: https://github.com/mediaron
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 account. Supports Google Analytics v3 only at this time.
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
  This plugin only supports Google Analytics v3 only at this time.
19
 
@@ -24,20 +24,17 @@ Also supports:
24
  * Pagination events
25
  * JS only events
26
  * Google Tag Manager
27
- * Matomo (formerly Piwik)
28
 
29
  = Setup Guide =
30
- Looking for help setting things up? [Read Our Setup Guide](https://mediaron.com/event-tracking-for-gravity-forms/)
31
 
32
  = Minimum Requirements =
33
- - Gravity Forms 2.4
34
- - Google Analytics Universal Analytics
35
  - Google Tag Manager (optional)
36
- - Matomo account (optional)
37
 
38
  = Features =
39
  - Submit events to Google Analytics using the Measurement Protocol, JavaScript, or using Google Tag Manager
40
- - Submit events using Matomo (formerly Piwik)
41
  - Add multiple event feeds with conditionals
42
  - Custom event categories, actions, labels and even values
43
  - Track form pagination events
@@ -52,7 +49,7 @@ Development happens on <a href="https://github.com/ronalfy/wordpress-gravity-for
52
  == Installation ==
53
 
54
  = Minimum Requirements =
55
- - Gravity Forms 2.4+
56
 
57
  = Using The WordPress Dashboard =
58
 
@@ -113,7 +110,7 @@ Yes, check out <a href="https://github.com/ronalfy/wordpress-gravity-forms-event
113
 
114
  = Can I track when a user has filled out a form field, but not submitted? =
115
 
116
- Yes, with the <a href="https://www.gravityforms.com/add-ons/partial-entries/">Partial Entries Add-on</a>. Edit your form and go to the 'Advanced' section and fill out your event parameters. If a partial entry is saved, the event will be sent to Google Analytics using the Measurement Protocol.
117
 
118
  Check out the video below for an explanation:
119
 
@@ -132,6 +129,15 @@ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gra
132
 
133
  == Changelog ==
134
 
 
 
 
 
 
 
 
 
 
135
  = 2.3.12 =
136
  * Released 2021-03-11
137
  * Testing Matomo to ensure it is tracked correctly.
@@ -305,11 +311,5 @@ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gra
305
 
306
  == Upgrade Notice ==
307
 
308
- = 2.3.12 =
309
- Testing Matomo to ensure it is tracked correctly. Testing compatibility with WordPress 5.7. Testing with Gravity Forms 2.5 RC-1.
310
-
311
- = 2.3.10 =
312
- Prevent empty values to be sent to analytics when using partial entries.
313
-
314
- = 2.3.9 =
315
- Fixing pagination settings for the form with correct default values. Fixed PHP 7.3 error with partial entries add-on showing incorrect offset.
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:5.5
5
  Tested up to: 5.7
6
+ Stable tag: 2.4.0
7
  Requires PHP: 5.6
8
  Donate link: https://github.com/mediaron
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 or Google Tag Manager account. Supports Google Analytics v3 and Gravity Forms 2.5+ only at this time.
13
 
14
  == Description ==
15
 
16
+ This plugin provides an easy way to add event tracking to your Gravity Forms using Google Analytics and Google Tag Manager.
17
 
18
  This plugin only supports Google Analytics v3 only at this time.
19
 
24
  * Pagination events
25
  * JS only events
26
  * Google Tag Manager
 
27
 
28
  = Setup Guide =
29
+ Looking for help setting things up? [Read Our Setup Guide](https://mediaron.com/event-tracking-for-gravity-forms/?utm_source=wordpress_org&utm_medium=documentation&utm_campaign=event_tracking)
30
 
31
  = Minimum Requirements =
32
+ - Gravity Forms 2.5
33
+ - Google Analytics Universal Analytics v3
34
  - Google Tag Manager (optional)
 
35
 
36
  = Features =
37
  - Submit events to Google Analytics using the Measurement Protocol, JavaScript, or using Google Tag Manager
 
38
  - Add multiple event feeds with conditionals
39
  - Custom event categories, actions, labels and even values
40
  - Track form pagination events
49
  == Installation ==
50
 
51
  = Minimum Requirements =
52
+ - Gravity Forms 2.5+
53
 
54
  = Using The WordPress Dashboard =
55
 
110
 
111
  = Can I track when a user has filled out a form field, but not submitted? =
112
 
113
+ You may use the Partial Entries add-on, but it is not recommended. Use pagination events instead.
114
 
115
  Check out the video below for an explanation:
116
 
129
 
130
  == Changelog ==
131
 
132
+ = 2.4.0 =
133
+ * Released 2021-05-01
134
+ * Requires: Gravity Forms 2.5 and above.
135
+ * Feature: Options to install gtag and Tag Manager are available.
136
+ * Bug Fix: Google Tag Manager no longer requires a UA code.
137
+ * Feature: Improved interface inline with Gravity Forms 2.5.
138
+ * Feature: Track UTM variables using Google Tag Manager.
139
+ * Miscelleanous bug fixes and code cleanup.
140
+
141
  = 2.3.12 =
142
  * Released 2021-03-11
143
  * Testing Matomo to ensure it is tracked correctly.
311
 
312
  == Upgrade Notice ==
313
 
314
+ = 2.4.0 =
315
+ Requires Gravity Forms 2.5+. Numerous cosmetic changes. Track UTM variables. Install GA or GTM using the add-on as needed.
 
 
 
 
 
 
gravity-forms-event-tracking.php CHANGED
@@ -2,8 +2,8 @@
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.3.12
7
  * Author: Ronald Huereca
8
  * Author URI: https://mediaron.com
9
  * Text Domain: gravity-forms-google-analytics-event-tracking
@@ -18,6 +18,9 @@ if ( ! defined( 'WPINC' ) ) {
18
  die;
19
  }
20
 
 
 
 
21
  class GFGAET {
22
 
23
  /**
@@ -61,7 +64,7 @@ class GFGAET {
61
  * @return bool true if meets minimum version, false if not
62
  */
63
  public static function check_php_version() {
64
- if( ! version_compare( '5.3', PHP_VERSION, '<=' ) ) {
65
  return false;
66
  }
67
  return true;
@@ -75,7 +78,7 @@ class GFGAET {
75
  public static function check_plugin() {
76
  if( ! GFGAET::check_php_version() ) {
77
  deactivate_plugins( GFGAET::get_plugin_basename() );
78
- exit( sprintf( esc_html__( 'Gravity Forms Event Tracking requires PHP version 5.3 and up. You are currently running PHP version %s.', 'gravity-forms-google-analytics-event-tracking' ), esc_html( PHP_VERSION ) ) );
79
  }
80
  }
81
 
@@ -106,6 +109,18 @@ class GFGAET {
106
  return $dir;
107
  }
108
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  /**
110
  * Initialize Gravity Forms related add-ons.
111
  *
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
6
+ * Version: 2.4.0
7
  * Author: Ronald Huereca
8
  * Author URI: https://mediaron.com
9
  * Text Domain: gravity-forms-google-analytics-event-tracking
18
  die;
19
  }
20
 
21
+ define( 'GFGAET_MIN_GFORMS_VERSION', '2.2.0' );
22
+ define( 'GFGAET_VERSION', '2.4.0' );
23
+
24
  class GFGAET {
25
 
26
  /**
64
  * @return bool true if meets minimum version, false if not
65
  */
66
  public static function check_php_version() {
67
+ if( ! version_compare( '5.6', PHP_VERSION, '<=' ) ) {
68
  return false;
69
  }
70
  return true;
78
  public static function check_plugin() {
79
  if( ! GFGAET::check_php_version() ) {
80
  deactivate_plugins( GFGAET::get_plugin_basename() );
81
+ exit( sprintf( esc_html__( 'Gravity Forms Event Tracking requires PHP version 5.6 and up. You are currently running PHP version %s.', 'gravity-forms-google-analytics-event-tracking' ), esc_html( PHP_VERSION ) ) );
82
  }
83
  }
84
 
109
  return $dir;
110
  }
111
 
112
+ /**
113
+ * Return the URL path to an asset.
114
+ *
115
+ * @param string $path Path to the asset.
116
+ */
117
+ public static function get_plugin_url( $path = '' ) {
118
+ $dir = rtrim( plugin_dir_url(__FILE__), '/' );
119
+ if ( !empty( $path ) && is_string( $path) )
120
+ $dir .= '/' . ltrim( $path, '/' );
121
+ return $dir;
122
+ }
123
+
124
  /**
125
  * Initialize Gravity Forms related add-ons.
126
  *
img/analytics.png ADDED
Binary file
img/analytics.svg ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
3
+ width="192px" height="192px" viewBox="0 0 192 192" enable-background="new 0 0 192 192" xml:space="preserve">
4
+ <rect x="0" y="0" fill="none" width="192" height="192"/>
5
+ <g>
6
+ <g>
7
+ <path fill="#F9AB00" d="M130,29v132c0,14.77,10.19,23,21,23c10,0,21-7,21-23V30c0-13.54-10-22-21-22S130,17.33,130,29z"/>
8
+ </g>
9
+ <g>
10
+ <path fill="#E37400" d="M75,96v65c0,14.77,10.19,23,21,23c10,0,21-7,21-23V97c0-13.54-10-22-21-22S75,84.33,75,96z"/>
11
+ </g>
12
+ <g>
13
+ <circle fill="#E37400" cx="41" cy="163" r="21"/>
14
+ </g>
15
+ </g>
16
+ </svg>
img/google-brands.png ADDED
Binary file
img/google-brands.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="google" class="svg-inline--fa fa-google fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 488 512"><path fill="currentColor" d="M488 261.8C488 403.3 391.1 504 248 504 110.8 504 0 393.2 0 256S110.8 8 248 8c66.8 0 123 24.5 166.3 64.9l-67.5 64.9C258.5 52.6 94.3 116.6 94.3 256c0 86.5 69.1 156.6 153.7 156.6 98.2 0 135-70.4 140.8-106.9H248v-85.3h236.1c2.3 12.7 3.9 24.9 3.9 41.4z"></path></svg>
img/gtm.png ADDED
Binary file
includes/GFGAET_Pagination.php CHANGED
@@ -15,7 +15,7 @@ class GFGAET_Pagination {
15
  */
16
  public static function get_instance() {
17
  if ( null == self::$instance ) {
18
- self::$instance = new self;
19
  }
20
  return self::$instance;
21
  } //end get_instance
@@ -34,9 +34,9 @@ class GFGAET_Pagination {
34
  *
35
  * @since 2.0.0
36
  *
37
- * @param array $form The form arguments
38
  * @param int @source_page_number The original page number
39
- * @param int $current_page_number The new page number
40
  */
41
  public function paginate( $form, $source_page_number, $current_page_number ) {
42
 
@@ -60,7 +60,7 @@ class GFGAET_Pagination {
60
  $event_category = 'form';
61
  if ( isset( $form['pagination_category'] ) ) {
62
  $pagination_category = trim( $form['pagination_category'] );
63
- if( ! empty( $pagination_category ) ) {
64
  $event_category = $pagination_category;
65
  }
66
  }
@@ -81,7 +81,7 @@ class GFGAET_Pagination {
81
  $event_action = 'pagination';
82
  if ( isset( $form['pagination_action'] ) ) {
83
  $pagination_action = trim( $form['pagination_action'] );
84
- if( ! empty( $pagination_action ) ) {
85
  $event_action = $pagination_action;
86
  }
87
  }
@@ -102,11 +102,11 @@ class GFGAET_Pagination {
102
  $event_label = sprintf( '%s::%d::%d', esc_html( $form['title'] ), absint( $source_page_number ), absint( $current_page_number ) );
103
  if ( isset( $form['pagination_label'] ) ) {
104
  $pagination_label = trim( $form['pagination_label'] );
105
- if( ! empty( $pagination_label ) ) {
106
  $pagination_label = str_replace( '{form_title}', esc_html( $form['title'] ), $pagination_label );
107
  $pagination_label = str_replace( '{source_page_number}', absint( $source_page_number ), $pagination_label );
108
  $pagination_label = str_replace( '{current_page_number}', absint( $current_page_number ), $pagination_label );
109
- $event_label = $pagination_label;
110
  }
111
  }
112
  $event_label = apply_filters( 'gform_pagination_event_label', $event_label, $form, $source_page_number, $current_page_number );
@@ -126,12 +126,12 @@ class GFGAET_Pagination {
126
  $event_value = 0;
127
  if ( isset( $form['pagination_value'] ) ) {
128
  $pagination_value = trim( $form['pagination_value'] );
129
- if( ! empty( $pagination_value ) ) {
130
  $event_value = $pagination_value;
131
  }
132
  }
133
  // Value is rounded up (Google likes integers only) before given an absolute value
134
- $event_value = absint( round( GFCommon::to_number( apply_filters( 'gform_pagination_event_value', $event_value, $form, $source_page_number, $current_page_number ) ) ) );
135
 
136
  // Set environmental variables for the measurement protocol
137
  $event->set_event_category( $event_category );
@@ -163,17 +163,22 @@ class GFGAET_Pagination {
163
  } else {
164
  // UA code doesn't match, use another tracker
165
  window.parent.ga( 'create', '<?php echo esc_js( $ua_code ); ?>', 'auto', 'GTGAET_Tracker' );
166
- window.parent.ga( 'GTGAET_Tracker.send', 'event', '<?php echo esc_js( $event_category );?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>'<?php if ( 0 !== $event_value ) { echo ',' . "'" . esc_js( $event_value ) . "'"; } ?>);
 
 
 
 
 
167
  }
168
  }
169
  </script>
170
  <?php
171
  return;
172
- } else if ( GFGAET::is_gtm_only() ) {
173
  ?>
174
  <script>
175
  if ( typeof( window.parent.dataLayer ) != 'undefined' ) {
176
- window.parent.dataLayer.push({'event': 'GFTrackEvent',
177
  'GFTrackCategory':'<?php echo esc_js( $event_category ); ?>',
178
  'GFTrackAction':'<?php echo esc_js( $event_action ); ?>',
179
  'GFTrackLabel':'<?php echo esc_js( $event_label ); ?>',
@@ -196,9 +201,9 @@ class GFGAET_Pagination {
196
  *
197
  * @since 2.0.0
198
  *
199
- * @param array $form The form arguments
200
  * @param int @source_page_number The original page number
201
- * @param int $current_page_number The new page number
202
  */
203
  public function matomo_paginate( $form, $source_page_number, $current_page_number ) {
204
 
@@ -221,7 +226,7 @@ class GFGAET_Pagination {
221
  $event_category = 'form';
222
  if ( isset( $form['pagination_category'] ) ) {
223
  $pagination_category = trim( $form['pagination_category'] );
224
- if( ! empty( $pagination_category ) ) {
225
  $event_category = $pagination_category;
226
  }
227
  }
@@ -242,7 +247,7 @@ class GFGAET_Pagination {
242
  $event_action = 'pagination';
243
  if ( isset( $form['pagination_action'] ) ) {
244
  $pagination_action = trim( $form['pagination_action'] );
245
- if( ! empty( $pagination_action ) ) {
246
  $event_action = $pagination_action;
247
  }
248
  }
@@ -263,11 +268,11 @@ class GFGAET_Pagination {
263
  $event_label = sprintf( '%s::%d::%d', esc_html( $form['title'] ), absint( $source_page_number ), absint( $current_page_number ) );
264
  if ( isset( $form['pagination_label'] ) ) {
265
  $pagination_label = trim( $form['pagination_label'] );
266
- if( ! empty( $pagination_label ) ) {
267
  $pagination_label = str_replace( '{form_title}', esc_html( $form['title'] ), $pagination_label );
268
  $pagination_label = str_replace( '{source_page_number}', absint( $source_page_number ), $pagination_label );
269
  $pagination_label = str_replace( '{current_page_number}', absint( $current_page_number ), $pagination_label );
270
- $event_label = $pagination_label;
271
  }
272
  }
273
  $event_label = apply_filters( 'gform_pagination_event_label', $event_label, $form, $source_page_number, $current_page_number );
@@ -287,7 +292,7 @@ class GFGAET_Pagination {
287
  $event_value = 0;
288
  if ( isset( $form['pagination_value'] ) ) {
289
  $pagination_value = trim( $form['pagination_value'] );
290
- if( ! empty( $pagination_value ) ) {
291
  $event_value = $pagination_value;
292
  }
293
  }
@@ -303,7 +308,12 @@ class GFGAET_Pagination {
303
  ?>
304
  <script>
305
  if ( typeof window.parent._paq != 'undefined' ) {
306
- window.parent._paq.push(['trackEvent', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>'<?php if ( 0 !== $event_value ) { echo ',' . "'" . esc_js( $event_value ) . "'"; } ?>]);
 
 
 
 
 
307
 
308
  }
309
  </script>
15
  */
16
  public static function get_instance() {
17
  if ( null == self::$instance ) {
18
+ self::$instance = new self();
19
  }
20
  return self::$instance;
21
  } //end get_instance
34
  *
35
  * @since 2.0.0
36
  *
37
+ * @param array $form The form arguments
38
  * @param int @source_page_number The original page number
39
+ * @param int $current_page_number The new page number
40
  */
41
  public function paginate( $form, $source_page_number, $current_page_number ) {
42
 
60
  $event_category = 'form';
61
  if ( isset( $form['pagination_category'] ) ) {
62
  $pagination_category = trim( $form['pagination_category'] );
63
+ if ( ! empty( $pagination_category ) ) {
64
  $event_category = $pagination_category;
65
  }
66
  }
81
  $event_action = 'pagination';
82
  if ( isset( $form['pagination_action'] ) ) {
83
  $pagination_action = trim( $form['pagination_action'] );
84
+ if ( ! empty( $pagination_action ) ) {
85
  $event_action = $pagination_action;
86
  }
87
  }
102
  $event_label = sprintf( '%s::%d::%d', esc_html( $form['title'] ), absint( $source_page_number ), absint( $current_page_number ) );
103
  if ( isset( $form['pagination_label'] ) ) {
104
  $pagination_label = trim( $form['pagination_label'] );
105
+ if ( ! empty( $pagination_label ) ) {
106
  $pagination_label = str_replace( '{form_title}', esc_html( $form['title'] ), $pagination_label );
107
  $pagination_label = str_replace( '{source_page_number}', absint( $source_page_number ), $pagination_label );
108
  $pagination_label = str_replace( '{current_page_number}', absint( $current_page_number ), $pagination_label );
109
+ $event_label = $pagination_label;
110
  }
111
  }
112
  $event_label = apply_filters( 'gform_pagination_event_label', $event_label, $form, $source_page_number, $current_page_number );
126
  $event_value = 0;
127
  if ( isset( $form['pagination_value'] ) ) {
128
  $pagination_value = trim( $form['pagination_value'] );
129
+ if ( ! empty( $pagination_value ) ) {
130
  $event_value = $pagination_value;
131
  }
132
  }
133
  // Value is rounded up (Google likes integers only) before given an absolute value
134
+ $event_value = absint( round( GFCommon::to_number( apply_filters( 'gform_pagination_event_value', $event_value, $form, $source_page_number, $current_page_number ) ) ) );
135
 
136
  // Set environmental variables for the measurement protocol
137
  $event->set_event_category( $event_category );
163
  } else {
164
  // UA code doesn't match, use another tracker
165
  window.parent.ga( 'create', '<?php echo esc_js( $ua_code ); ?>', 'auto', 'GTGAET_Tracker' );
166
+ window.parent.ga( 'GTGAET_Tracker.send', 'event', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>'
167
+ <?php
168
+ if ( 0 !== $event_value ) {
169
+ echo ',' . "'" . esc_js( $event_value ) . "'"; }
170
+ ?>
171
+ );
172
  }
173
  }
174
  </script>
175
  <?php
176
  return;
177
+ } elseif ( GFGAET::is_gtm_only() ) {
178
  ?>
179
  <script>
180
  if ( typeof( window.parent.dataLayer ) != 'undefined' ) {
181
+ window.parent.dataLayer.push({'event': 'GFTrackEvent',
182
  'GFTrackCategory':'<?php echo esc_js( $event_category ); ?>',
183
  'GFTrackAction':'<?php echo esc_js( $event_action ); ?>',
184
  'GFTrackLabel':'<?php echo esc_js( $event_label ); ?>',
201
  *
202
  * @since 2.0.0
203
  *
204
+ * @param array $form The form arguments
205
  * @param int @source_page_number The original page number
206
+ * @param int $current_page_number The new page number
207
  */
208
  public function matomo_paginate( $form, $source_page_number, $current_page_number ) {
209
 
226
  $event_category = 'form';
227
  if ( isset( $form['pagination_category'] ) ) {
228
  $pagination_category = trim( $form['pagination_category'] );
229
+ if ( ! empty( $pagination_category ) ) {
230
  $event_category = $pagination_category;
231
  }
232
  }
247
  $event_action = 'pagination';
248
  if ( isset( $form['pagination_action'] ) ) {
249
  $pagination_action = trim( $form['pagination_action'] );
250
+ if ( ! empty( $pagination_action ) ) {
251
  $event_action = $pagination_action;
252
  }
253
  }
268
  $event_label = sprintf( '%s::%d::%d', esc_html( $form['title'] ), absint( $source_page_number ), absint( $current_page_number ) );
269
  if ( isset( $form['pagination_label'] ) ) {
270
  $pagination_label = trim( $form['pagination_label'] );
271
+ if ( ! empty( $pagination_label ) ) {
272
  $pagination_label = str_replace( '{form_title}', esc_html( $form['title'] ), $pagination_label );
273
  $pagination_label = str_replace( '{source_page_number}', absint( $source_page_number ), $pagination_label );
274
  $pagination_label = str_replace( '{current_page_number}', absint( $current_page_number ), $pagination_label );
275
+ $event_label = $pagination_label;
276
  }
277
  }
278
  $event_label = apply_filters( 'gform_pagination_event_label', $event_label, $form, $source_page_number, $current_page_number );
292
  $event_value = 0;
293
  if ( isset( $form['pagination_value'] ) ) {
294
  $pagination_value = trim( $form['pagination_value'] );
295
+ if ( ! empty( $pagination_value ) ) {
296
  $event_value = $pagination_value;
297
  }
298
  }
308
  ?>
309
  <script>
310
  if ( typeof window.parent._paq != 'undefined' ) {
311
+ window.parent._paq.push(['trackEvent', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>'
312
+ <?php
313
+ if ( 0 !== $event_value ) {
314
+ echo ',' . "'" . esc_js( $event_value ) . "'"; }
315
+ ?>
316
+ ]);
317
 
318
  }
319
  </script>
includes/GFGAET_Pagination_Settings.php CHANGED
@@ -1,19 +1,19 @@
1
  <?php
2
  GFForms::include_addon_framework();
3
  class GFGAET_Pagination_Settings extends GFAddOn {
4
- protected $_version = '2.0';
5
- protected $_min_gravityforms_version = '1.8.20';
6
- protected $_slug = 'GFGAET_Pagination_Settings';
7
- protected $_path = 'gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php';
8
- protected $_full_path = __FILE__;
9
- protected $_title = 'Gravity Forms Google Analytics Event Tracking';
10
- protected $_short_title = 'Event Tracking';
11
  // Members plugin integration
12
  protected $_capabilities = array( 'gravityforms_event_tracking', 'gravityforms_event_tracking_uninstall' );
13
  // Permissions
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
 
@@ -23,11 +23,11 @@ class GFGAET_Pagination_Settings extends GFAddOn {
23
  * @return object $_instance An instance of this class.
24
  */
25
  public static function get_instance() {
26
- if ( self::$_instance == null ) {
27
- self::$_instance = new self();
28
- }
29
 
30
- return self::$_instance;
31
  }
32
 
33
  public function init() {
@@ -48,9 +48,9 @@ class GFGAET_Pagination_Settings extends GFAddOn {
48
  */
49
  public function save_pagination_settings( $form ) {
50
  $form['pagination_category'] = rgpost( 'pagination_category' );
51
- $form['pagination_action'] = rgpost( 'pagination_action' );
52
- $form['pagination_label'] = rgpost( 'pagination_label' );
53
- $form['pagination_value'] = rgpost( 'pagination_value' );
54
  return $form;
55
  }
56
 
@@ -65,7 +65,8 @@ class GFGAET_Pagination_Settings extends GFAddOn {
65
  * @return array Updated form settings
66
  */
67
  public function add_pagination_form_settings( $settings, $form ) {
68
- $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_description'] = sprintf( '
 
69
  <tr>
70
  <th colspan="2">
71
  %s<br /><br />
@@ -74,27 +75,50 @@ class GFGAET_Pagination_Settings extends GFAddOn {
74
  <strong>%s:</strong> %s<br />
75
  <strong>%s:</strong> 0
76
  </th>
77
- </tr>', __( 'If left blank, the following values are used:', 'gravity-forms-google-analytics-event-tracking' ), __( 'Category', 'gravity-forms-google-analytics-event-tracking' ), __( 'Action', 'gravity-forms-google-analytics-event-tracking' ), __( 'Label', 'gravity-forms-google-analytics-event-tracking' ), __( '{form_title}::{source_page_number}::{current_page_number}', 'gravity-forms-google-analytics-event-tracking' ), __( 'Value', 'gravity-forms-google-analytics-event-tracking' ) );
78
- $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_category'] = sprintf( '
 
 
 
 
 
 
 
 
79
  <tr>
80
  <th><label for="pagination_category">%s</label></th>
81
  <td><input value="%s" name="pagination_category" id="pagination_category" class="fieldwidth-3" /></td>
82
- </tr>', __( 'Pagination Category', 'gravity-forms-google-analytics-event-tracking' ), esc_attr( rgar( $form, 'pagination_category' ) ) );
83
- $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_action'] = sprintf( '
 
 
 
 
84
  <tr>
85
  <th><label for="pagination_action">%s</label></th>
86
  <td><input value="%s" name="pagination_action" id="pagination_action" class="fieldwidth-3" /></td>
87
- </tr>', __( 'Pagination Action', 'gravity-forms-google-analytics-event-tracking' ), esc_attr( rgar( $form, 'pagination_action' ) ) );
88
- $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_label'] = sprintf( '
 
 
 
 
89
  <tr>
90
  <th><label for="pagination_label">%s</label></th>
91
  <td><input value="%s" name="pagination_label" id="pagination_label" class="fieldwidth-3" /></td>
92
- </tr>', __( 'Pagination Label', 'gravity-forms-google-analytics-event-tracking' ), esc_attr( rgar( $form, 'pagination_label' ) ) );
93
- $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_value'] = sprintf( '
 
 
 
 
94
  <tr>
95
  <th><label for="pagination_value">%s</label></th>
96
  <td><input value="%s" type="number" name="pagination_value" id="pagination_value" class="fieldwidth-3" /></td>
97
- </tr>', __( 'Pagination Value', 'gravity-forms-google-analytics-event-tracking' ), esc_attr( rgar( $form, 'pagination_value' ) ) );
 
 
 
98
  return $settings;
99
  }
100
  }
1
  <?php
2
  GFForms::include_addon_framework();
3
  class GFGAET_Pagination_Settings extends GFAddOn {
4
+ protected $_version = GFGAET_VERSION;
5
+ protected $_min_gravityforms_version = GFGAET_MIN_GFORMS_VERSION;
6
+ protected $_slug = 'GFGAET_Pagination_Settings';
7
+ protected $_path = 'gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php';
8
+ protected $_full_path = __FILE__;
9
+ protected $_title = 'Gravity Forms Google Analytics Event Tracking';
10
+ protected $_short_title = 'Event Tracking';
11
  // Members plugin integration
12
  protected $_capabilities = array( 'gravityforms_event_tracking', 'gravityforms_event_tracking_uninstall' );
13
  // Permissions
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
 
23
  * @return object $_instance An instance of this class.
24
  */
25
  public static function get_instance() {
26
+ if ( self::$_instance == null ) {
27
+ self::$_instance = new self();
28
+ }
29
 
30
+ return self::$_instance;
31
  }
32
 
33
  public function init() {
48
  */
49
  public function save_pagination_settings( $form ) {
50
  $form['pagination_category'] = rgpost( 'pagination_category' );
51
+ $form['pagination_action'] = rgpost( 'pagination_action' );
52
+ $form['pagination_label'] = rgpost( 'pagination_label' );
53
+ $form['pagination_value'] = rgpost( 'pagination_value' );
54
  return $form;
55
  }
56
 
65
  * @return array Updated form settings
66
  */
67
  public function add_pagination_form_settings( $settings, $form ) {
68
+ $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_description'] = sprintf(
69
+ '
70
  <tr>
71
  <th colspan="2">
72
  %s<br /><br />
75
  <strong>%s:</strong> %s<br />
76
  <strong>%s:</strong> 0
77
  </th>
78
+ </tr>',
79
+ __( 'If left blank, the following values are used:', 'gravity-forms-google-analytics-event-tracking' ),
80
+ __( 'Category', 'gravity-forms-google-analytics-event-tracking' ),
81
+ __( 'Action', 'gravity-forms-google-analytics-event-tracking' ),
82
+ __( 'Label', 'gravity-forms-google-analytics-event-tracking' ),
83
+ __( '{form_title}::{source_page_number}::{current_page_number}', 'gravity-forms-google-analytics-event-tracking' ),
84
+ __( 'Value', 'gravity-forms-google-analytics-event-tracking' )
85
+ );
86
+ $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_category'] = sprintf(
87
+ '
88
  <tr>
89
  <th><label for="pagination_category">%s</label></th>
90
  <td><input value="%s" name="pagination_category" id="pagination_category" class="fieldwidth-3" /></td>
91
+ </tr>',
92
+ __( 'Pagination Category', 'gravity-forms-google-analytics-event-tracking' ),
93
+ esc_attr( rgar( $form, 'pagination_category' ) )
94
+ );
95
+ $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_action'] = sprintf(
96
+ '
97
  <tr>
98
  <th><label for="pagination_action">%s</label></th>
99
  <td><input value="%s" name="pagination_action" id="pagination_action" class="fieldwidth-3" /></td>
100
+ </tr>',
101
+ __( 'Pagination Action', 'gravity-forms-google-analytics-event-tracking' ),
102
+ esc_attr( rgar( $form, 'pagination_action' ) )
103
+ );
104
+ $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_label'] = sprintf(
105
+ '
106
  <tr>
107
  <th><label for="pagination_label">%s</label></th>
108
  <td><input value="%s" name="pagination_label" id="pagination_label" class="fieldwidth-3" /></td>
109
+ </tr>',
110
+ __( 'Pagination Label', 'gravity-forms-google-analytics-event-tracking' ),
111
+ esc_attr( rgar( $form, 'pagination_label' ) )
112
+ );
113
+ $settings[ __( 'Pagination Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) ]['pagination_value'] = sprintf(
114
+ '
115
  <tr>
116
  <th><label for="pagination_value">%s</label></th>
117
  <td><input value="%s" type="number" name="pagination_value" id="pagination_value" class="fieldwidth-3" /></td>
118
+ </tr>',
119
+ __( 'Pagination Value', 'gravity-forms-google-analytics-event-tracking' ),
120
+ esc_attr( rgar( $form, 'pagination_value' ) )
121
+ );
122
  return $settings;
123
  }
124
  }
includes/GFGAET_Partial_Entries.php CHANGED
@@ -2,19 +2,19 @@
2
  // Credit: https://stevegrunwell.com/blog/custom-field-ids-gravity-forms/
3
  GFForms::include_addon_framework();
4
  class GFGAET_Partial_Entries extends GFAddOn {
5
- protected $_version = '2.0';
6
- protected $_min_gravityforms_version = '1.8.20';
7
- protected $_slug = 'GFGAET_Partial_Entries';
8
- protected $_path = 'gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php';
9
- protected $_full_path = __FILE__;
10
- protected $_title = 'Gravity Forms Google Analytics Partial Entries';
11
- protected $_short_title = 'Event Tracking';
12
  // Members plugin integration
13
  protected $_capabilities = array( 'gravityforms_event_tracking', 'gravityforms_event_tracking_uninstall' );
14
  // Permissions
15
  protected $_capabilities_settings_page = 'gravityforms_event_tracking';
16
  protected $_capabilities_form_settings = 'gravityforms_event_tracking';
17
- protected $_capabilities_uninstall = 'gravityforms_event_tracking_uninstall';
18
 
19
 
20
  private static $_instance = null;
@@ -58,8 +58,8 @@ class GFGAET_Partial_Entries extends GFAddOn {
58
  */
59
  public function partial_entry_saved( $partial_entry, $form ) {
60
  $form_fields = $this->get_mapped_fields( $partial_entry, $form );
61
- foreach( $form_fields as $gform_index => $gform_values ) {
62
- if( isset( $gform_values['event_category']) && !empty( $gform_values['event_category'] ) ) {
63
 
64
  // Get defaults
65
  $value = $gform_values['value'];
@@ -70,17 +70,16 @@ class GFGAET_Partial_Entries extends GFAddOn {
70
 
71
  // Get category/action/label
72
  $event_category = trim( $gform_values['event_category'] );
73
- $event_action = ( empty( $gform_values['event_action'] ) ? 'partial' : trim( $gform_values['event_action'] ) );
74
- $event_label = ( empty( $gform_values['event_label'] ) ? trim( $label ) : trim( $gform_values['event_label'] ) );
75
 
76
  // Get event value
77
  $event_value = ( empty( $gform_values['event_value'] ) ? trim( $value ) : trim( $gform_values['event_value'] ) );
78
- if( !is_numeric( $event_value ) ) {
79
  $event_value = 0;
80
  }
81
  $event_value = absint( round( GFCommon::to_number( $event_value ) ) );
82
 
83
-
84
  /**
85
  * Filter: gform_partial_event_category
86
  *
@@ -143,7 +142,7 @@ class GFGAET_Partial_Entries extends GFAddOn {
143
 
144
  // Let's set up the measurement protocol
145
  $ua_code = GFGAET::get_ua_code();
146
- $event = new GFGAET_Measurement_Protocol();
147
  $event->init();
148
  $event->set_event_category( $event_category );
149
  $event->set_event_action( $event_action );
@@ -169,33 +168,33 @@ class GFGAET_Partial_Entries extends GFAddOn {
169
 
170
  foreach ( $form['fields'] as $field ) {
171
  if ( ! isset( $field['id'] ) || ! $field['id'] ) {
172
- continue;
173
  }
174
 
175
  // Explode field IDs.
176
- $field_ids = explode( ',', $field['id'] );
177
- $field_ids = array_map( 'trim', $field_ids );
178
- $event_category = isset( $field['field_partial_entries_category'] ) ? $field['field_partial_entries_category'] : '' ;
179
- $event_action = isset( $field['field_partial_entries_action'] ) ? $field['field_partial_entries_action'] : '';
180
- $event_label = isset( $field['field_partial_entries_label'] ) ? $field['field_partial_entries_label'] : '';
181
- $event_value = isset( $field['field_partial_entries_value'] ) ? $field['field_partial_entries_value'] : '0';
182
  $event_category = GFCommon::replace_variables( $event_category, $form, $entry );
183
- $event_action = GFCommon::replace_variables( $event_action, $form, $entry );
184
- $event_label = GFCommon::replace_variables( $event_label, $form, $entry );
185
- $event_value = GFCommon::replace_variables( $event_value, $form, $entry );
186
 
187
  // We have a complex field, with multiple inputs.
188
  if ( ! empty( $field['inputs'] ) ) {
189
  foreach ( $field['inputs'] as $input ) {
190
  if ( isset( $input['isHidden'] ) && $input['isHidden'] ) {
191
- continue;
192
  }
193
 
194
  $field_id = array_shift( $field_ids );
195
 
196
  // If $field_id is empty, don't map this input.
197
  if ( ! $field_id ) {
198
- continue;
199
  }
200
 
201
  /*
@@ -208,7 +207,7 @@ class GFGAET_Partial_Entries extends GFAddOn {
208
  'event_category' => $event_category,
209
  'event_action' => $event_action,
210
  'event_label' => $event_label,
211
- 'event_value' => $event_value
212
  );
213
  }
214
  } else {
@@ -218,7 +217,7 @@ class GFGAET_Partial_Entries extends GFAddOn {
218
  'event_category' => $event_category,
219
  'event_action' => $event_action,
220
  'event_label' => $event_label,
221
- 'event_value' => $event_value
222
  );
223
  }
224
  }
@@ -251,9 +250,9 @@ class GFGAET_Partial_Entries extends GFAddOn {
251
  */
252
  public function add_tooltips( $tooltips ) {
253
  $tooltips['gfgaet_category'] = __( 'Event category which you would like to send to Google Analytics using Partial Entries. Merge tags are not allowed.', 'gravity-forms-google-analytics-event-tracking' );
254
- $tooltips['gfgaet_action'] = __( 'Event action which you would like to send to Google Analytics using Partial Entries. Merge tags are not allowed.', 'gravity-forms-google-analytics-event-tracking' );
255
- $tooltips['gfgaet_label'] = __( 'Event label which you would like to send to Google Analytics using Partial Entries. Merge tags are not allowed. If left blank, the form value will be used.', 'gravity-forms-google-analytics-event-tracking' );
256
- $tooltips['gfgaet_value'] = __( 'Event value (Integers only) which you would like to send to Google Analytics using Partial Entries. Merge tags are not allowed. If left blank, the form value will be used assuming it is an integer.', 'gravity-forms-google-analytics-event-tracking' );
257
  return $tooltips;
258
  }
259
 
@@ -312,7 +311,9 @@ class GFGAET_Partial_Entries extends GFAddOn {
312
  * @return string HTML for advanced settings
313
  */
314
  public function advanced_settings( $position, $form_id ) {
315
- if( 100 !== $position ) return;
 
 
316
  ?>
317
  <li class="admin_partial_entry_category field_setting">
318
  <label for="field_partial_entries_category" class="section_label">
2
  // Credit: https://stevegrunwell.com/blog/custom-field-ids-gravity-forms/
3
  GFForms::include_addon_framework();
4
  class GFGAET_Partial_Entries extends GFAddOn {
5
+ protected $_version = GFGAET_VERSION;
6
+ protected $_min_gravityforms_version = GFGAET_MIN_GFORMS_VERSION;
7
+ protected $_slug = 'GFGAET_Partial_Entries';
8
+ protected $_path = 'gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php';
9
+ protected $_full_path = __FILE__;
10
+ protected $_title = 'Gravity Forms Google Analytics Partial Entries';
11
+ protected $_short_title = 'Event Tracking';
12
  // Members plugin integration
13
  protected $_capabilities = array( 'gravityforms_event_tracking', 'gravityforms_event_tracking_uninstall' );
14
  // Permissions
15
  protected $_capabilities_settings_page = 'gravityforms_event_tracking';
16
  protected $_capabilities_form_settings = 'gravityforms_event_tracking';
17
+ protected $_capabilities_uninstall = 'gravityforms_event_tracking_uninstall';
18
 
19
 
20
  private static $_instance = null;
58
  */
59
  public function partial_entry_saved( $partial_entry, $form ) {
60
  $form_fields = $this->get_mapped_fields( $partial_entry, $form );
61
+ foreach ( $form_fields as $gform_index => $gform_values ) {
62
+ if ( isset( $gform_values['event_category'] ) && ! empty( $gform_values['event_category'] ) ) {
63
 
64
  // Get defaults
65
  $value = $gform_values['value'];
70
 
71
  // Get category/action/label
72
  $event_category = trim( $gform_values['event_category'] );
73
+ $event_action = ( empty( $gform_values['event_action'] ) ? 'partial' : trim( $gform_values['event_action'] ) );
74
+ $event_label = ( empty( $gform_values['event_label'] ) ? trim( $label ) : trim( $gform_values['event_label'] ) );
75
 
76
  // Get event value
77
  $event_value = ( empty( $gform_values['event_value'] ) ? trim( $value ) : trim( $gform_values['event_value'] ) );
78
+ if ( ! is_numeric( $event_value ) ) {
79
  $event_value = 0;
80
  }
81
  $event_value = absint( round( GFCommon::to_number( $event_value ) ) );
82
 
 
83
  /**
84
  * Filter: gform_partial_event_category
85
  *
142
 
143
  // Let's set up the measurement protocol
144
  $ua_code = GFGAET::get_ua_code();
145
+ $event = new GFGAET_Measurement_Protocol();
146
  $event->init();
147
  $event->set_event_category( $event_category );
148
  $event->set_event_action( $event_action );
168
 
169
  foreach ( $form['fields'] as $field ) {
170
  if ( ! isset( $field['id'] ) || ! $field['id'] ) {
171
+ continue;
172
  }
173
 
174
  // Explode field IDs.
175
+ $field_ids = explode( ',', $field['id'] );
176
+ $field_ids = array_map( 'trim', $field_ids );
177
+ $event_category = isset( $field['field_partial_entries_category'] ) ? $field['field_partial_entries_category'] : '';
178
+ $event_action = isset( $field['field_partial_entries_action'] ) ? $field['field_partial_entries_action'] : '';
179
+ $event_label = isset( $field['field_partial_entries_label'] ) ? $field['field_partial_entries_label'] : '';
180
+ $event_value = isset( $field['field_partial_entries_value'] ) ? $field['field_partial_entries_value'] : '0';
181
  $event_category = GFCommon::replace_variables( $event_category, $form, $entry );
182
+ $event_action = GFCommon::replace_variables( $event_action, $form, $entry );
183
+ $event_label = GFCommon::replace_variables( $event_label, $form, $entry );
184
+ $event_value = GFCommon::replace_variables( $event_value, $form, $entry );
185
 
186
  // We have a complex field, with multiple inputs.
187
  if ( ! empty( $field['inputs'] ) ) {
188
  foreach ( $field['inputs'] as $input ) {
189
  if ( isset( $input['isHidden'] ) && $input['isHidden'] ) {
190
+ continue;
191
  }
192
 
193
  $field_id = array_shift( $field_ids );
194
 
195
  // If $field_id is empty, don't map this input.
196
  if ( ! $field_id ) {
197
+ continue;
198
  }
199
 
200
  /*
207
  'event_category' => $event_category,
208
  'event_action' => $event_action,
209
  'event_label' => $event_label,
210
+ 'event_value' => $event_value,
211
  );
212
  }
213
  } else {
217
  'event_category' => $event_category,
218
  'event_action' => $event_action,
219
  'event_label' => $event_label,
220
+ 'event_value' => $event_value,
221
  );
222
  }
223
  }
250
  */
251
  public function add_tooltips( $tooltips ) {
252
  $tooltips['gfgaet_category'] = __( 'Event category which you would like to send to Google Analytics using Partial Entries. Merge tags are not allowed.', 'gravity-forms-google-analytics-event-tracking' );
253
+ $tooltips['gfgaet_action'] = __( 'Event action which you would like to send to Google Analytics using Partial Entries. Merge tags are not allowed.', 'gravity-forms-google-analytics-event-tracking' );
254
+ $tooltips['gfgaet_label'] = __( 'Event label which you would like to send to Google Analytics using Partial Entries. Merge tags are not allowed. If left blank, the form value will be used.', 'gravity-forms-google-analytics-event-tracking' );
255
+ $tooltips['gfgaet_value'] = __( 'Event value (Integers only) which you would like to send to Google Analytics using Partial Entries. Merge tags are not allowed. If left blank, the form value will be used assuming it is an integer.', 'gravity-forms-google-analytics-event-tracking' );
256
  return $tooltips;
257
  }
258
 
311
  * @return string HTML for advanced settings
312
  */
313
  public function advanced_settings( $position, $form_id ) {
314
+ if ( 100 !== $position ) {
315
+ return;
316
+ }
317
  ?>
318
  <li class="admin_partial_entry_category field_setting">
319
  <label for="field_partial_entries_category" class="section_label">
includes/GFGAET_Submission_Feeds.php CHANGED
@@ -13,13 +13,13 @@ GFForms::include_feed_addon_framework();
13
 
14
  class GFGAET_Submission_Feeds extends GFFeedAddOn {
15
 
16
- protected $_version = "2.3.12";
17
- protected $_min_gravityforms_version = "1.8.20";
18
- protected $_slug = "gravity-forms-event-tracking";
19
- protected $_path = "gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php";
20
- protected $_full_path = __FILE__;
21
- protected $_title = "Gravity Forms Google Analytics Event Tracking";
22
- protected $_short_title = "Submission Tracking";
23
 
24
  // Members plugin integration
25
  protected $_capabilities = array( 'gravityforms_event_tracking', 'gravityforms_event_tracking_uninstall' );
@@ -27,7 +27,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
27
  // Permissions
28
  protected $_capabilities_settings_page = 'gravityforms_event_tracking';
29
  protected $_capabilities_form_settings = 'gravityforms_event_tracking';
30
- protected $_capabilities_uninstall = 'gravityforms_event_tracking_uninstall';
31
 
32
  public $ua_id = false;
33
 
@@ -47,6 +47,357 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
47
  */
48
  public function init() {
49
  parent::init();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  }
51
 
52
  /**
@@ -67,17 +418,18 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
67
 
68
  /**
69
  * Process the feed!
 
70
  * @param array $feed feed data and settings
71
  * @param array $entry gf entry object
72
  * @param array $form gf form data
73
  */
74
  public function process_feed( $feed, $entry, $form ) {
75
 
76
- $paypal_feeds = $this->get_feeds_by_slug( 'gravityformspaypal', $form['id'] );
77
  $has_paypal_feed = false;
78
 
79
- foreach ( $paypal_feeds as $paypal_feed ){
80
- if ( $paypal_feed['is_active'] && $this->is_feed_condition_met( $paypal_feed, $form, $entry ) ){
81
  $has_paypal_feed = true;
82
  break;
83
  }
@@ -87,8 +439,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
87
 
88
  if ( $has_paypal_feed ) {
89
  gform_update_meta( $entry['id'], 'ga_event_data', maybe_serialize( $ga_event_data ) );
90
- }
91
- else {
92
  $this->track_form_after_submission( $entry, $form, $ga_event_data );
93
  }
94
  }
@@ -115,17 +466,18 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
115
  * @since 1.4.0
116
  * @return bool Returns true if UA ID is loaded, false otherwise
117
  */
118
- private function get_ga_id() {
119
- $this->load_ua_settings();
120
- if ( $this->ua_id == false ) {
121
- return '';
122
- } else {
123
- return $this->ua_id;
124
- }
125
- }
126
 
127
  /**
128
  * Get data required for processing
 
129
  * @param array $feed feed
130
  * @param array $entry GF Entry object
131
  * @param array $form GF Form object
@@ -137,23 +489,23 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
137
  $ga_cookie = isset( $_COOKIE['_ga'] ) ? $_COOKIE['_ga'] : '';
138
 
139
  // Location
140
- $document_location = str_replace( home_url(), '', $entry[ 'source_url' ] );
141
 
142
  // Title
143
  $document_title = isset( $post ) && get_the_title( $post ) ? get_the_title( $post ) : 'no title';
144
 
145
  // Store everything we need for later
146
  $ga_event_data = array(
147
- 'feed_id' => $feed['id'],
148
- 'entry_id' => $entry['id'],
149
- 'ga_cookie' => $ga_cookie,
150
  'document_location' => $document_location,
151
- 'document_title' => $document_title,
152
- 'gaEventUA' => $this->get_event_var( 'gaEventUA', $feed, $entry, $form ),
153
- 'gaEventCategory' => $this->get_event_var( 'gaEventCategory', $feed, $entry, $form ),
154
- 'gaEventAction' => $this->get_event_var( 'gaEventAction', $feed, $entry, $form ),
155
- 'gaEventLabel' => $this->get_event_var( 'gaEventLabel', $feed, $entry, $form ),
156
- 'gaEventValue' => $this->get_event_var( 'gaEventValue', $feed, $entry, $form ),
157
  );
158
 
159
  return $ga_event_data;
@@ -166,8 +518,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
166
 
167
  if ( isset( $feed['meta'][ $var ] ) && ! empty( $feed['meta'][ $var ] ) ) {
168
  return $feed['meta'][ $var ];
169
- }
170
- else {
171
  switch ( $var ) {
172
  case 'gaEventCategory':
173
  return 'Forms';
@@ -211,7 +562,6 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
211
  }
212
  }
213
 
214
-
215
  // Push the event to google
216
  $this->push_event( $entry, $form, $ga_event_data );
217
  // Push the event to matomo
@@ -253,8 +603,8 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
253
  */
254
  private function push_event( $entry, $form, $ga_event_data ) {
255
 
256
- //Get all analytics codes to send
257
- $google_analytics_codes = $this->get_ua_codes( $ga_event_data[ 'gaEventUA' ], $this->get_ga_id() );
258
 
259
  /**
260
  * Filter: gform_ua_ids
@@ -269,16 +619,21 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
269
  */
270
  $google_analytics_codes = apply_filters( 'gform_ua_ids', $google_analytics_codes, $form, $entry );
271
 
272
- if ( !is_array( $google_analytics_codes ) || empty( $google_analytics_codes ) ) return;
273
- $google_analytics_codes = array_unique($google_analytics_codes);
 
 
 
 
 
274
 
275
  $event = new GFGAET_Measurement_Protocol();
276
  $event->init();
277
 
278
  // Set some defaults
279
- $event->set_document_path( str_replace( home_url(), '', $entry[ 'source_url' ] ) );
280
  $event_url_parsed = parse_url( home_url() );
281
- $event->set_document_host( $event_url_parsed[ 'host' ] );
282
  $event->set_document_location( str_replace( '//', '/', 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'] ) );
283
  $event->set_document_title( $ga_event_data['document_title'] );
284
 
@@ -342,14 +697,14 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
342
  $event->set_event_value( $event_value );
343
  }
344
 
345
- $feed_id = absint( $ga_event_data[ 'feed_id' ] );
346
  $entry_id = $entry['id'];
347
 
348
  if ( GFGAET::is_ga_only() ) {
349
- $count = 1;
350
  $is_interactive_hit = 'false';
351
- $interactive_hit = GFGAET::get_interactive_hit_tracker();
352
- if( 'interactive_off' == $interactive_hit ) {
353
  $is_interactive_hit = 'false';
354
  } else {
355
  $is_interactive_hit = 'true';
@@ -357,7 +712,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
357
  ?>
358
  <script>
359
  <?php
360
- foreach( $google_analytics_codes as $ua_code ) {
361
  ?>
362
 
363
  // Check for gtab implementation
@@ -366,7 +721,10 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
366
  nonInteraction: <?php echo esc_js( $is_interactive_hit ); ?>,
367
  'event_category': '<?php echo esc_js( $event_category ); ?>',
368
  'event_label': '<?php echo esc_js( $event_label ); ?>'
369
- <?php if ( 0 !== $event_value && !empty( $event_value ) ) { echo sprintf( ",'value': '%s'", esc_js( $event_value ) ); } ?>
 
 
 
370
  }
371
  );
372
  if ( typeof( console ) == 'object' ) {
@@ -407,7 +765,12 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
407
  }
408
 
409
  // Use that tracker
410
- window.parent.ga( ga_send, 'event', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>'<?php if ( 0 !== $event_value && !empty( $event_value ) ) { echo ',' . "'" . esc_js( $event_value ) . "'"; } ?>, {
 
 
 
 
 
411
  nonInteraction: <?php echo esc_js( $is_interactive_hit ); ?>
412
  });
413
 
@@ -424,27 +787,45 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
424
  } elseif ( GFGAET::is_gtm_only() ) {
425
  ?>
426
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
  if ( typeof( window.parent.dataLayer ) != 'undefined' ) {
428
  window.parent.dataLayer.push({'event': 'GFTrackEvent',
429
  'GFTrackCategory':'<?php echo esc_js( $event_category ); ?>',
430
  'GFTrackAction':'<?php echo esc_js( $event_action ); ?>',
431
  'GFTrackLabel':'<?php echo esc_js( $event_label ); ?>',
432
  'GFTrackValue': <?php echo absint( $event_value ); ?>,
433
- 'GFEntryData':<?php echo json_encode( $entry ); ?>
 
 
 
 
 
434
  });
435
  }
436
  </script>
437
  <?php
438
  return;
439
  } else {
440
- //Push out the event to each UA code
441
- foreach( $google_analytics_codes as $ua_code ) {
442
  // Submit the event
443
  $event->send( $ua_code );
444
  }
445
  }
446
 
447
-
448
  }
449
 
450
  /**
@@ -456,7 +837,9 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
456
  */
457
  private function push_matomo_event( $entry, $form, $ga_event_data ) {
458
 
459
- if ( false === GFGAET::is_matomo_configured() ) return;
 
 
460
 
461
  $event = new GFGAET_Matomo_HTTP_API();
462
  $event->init();
@@ -524,7 +907,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
524
  $event->set_matomo_event_value( $event_value );
525
  }
526
 
527
- $feed_id = absint( $ga_event_data[ 'feed_id' ] );
528
  $entry_id = $entry['id'];
529
 
530
  if ( GFGAET::is_matomo_js_only() ) {
@@ -532,7 +915,12 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
532
  <script>
533
  if ( typeof window.parent._paq != 'undefined' ) {
534
 
535
- window.parent._paq.push(['trackEvent', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>'<?php if ( 0 !== $event_value && !empty( $event_value ) ) { echo ',' . "'" . esc_js( $event_value ) . "'"; } ?>]);
 
 
 
 
 
536
 
537
  }
538
  </script>
@@ -560,7 +948,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
560
  return false;
561
  }
562
 
563
- //---------- Form Settings Pages --------------------------
564
 
565
  /**
566
  * Form settings page title
@@ -569,7 +957,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
569
  * @return string Form Settings Title
570
  */
571
  public function feed_settings_title() {
572
- return __( 'Submission Tracking Settings', 'gravity-forms-google-analytics-event-tracking' );
573
  }
574
 
575
  public function maybe_save_feed_settings( $feed_id, $form_id ) {
@@ -595,13 +983,13 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
595
  $is_valid = $this->validate_settings( $sections, $settings );
596
  $result = false;
597
 
598
- //Check for a valid UA code
599
- $feed_ua_code = isset( $settings[ 'gaEventUA' ] ) ? $settings[ 'gaEventUA' ] : '';
600
- $ua_codes = $this->get_ua_codes( $feed_ua_code, $this->get_ga_id() );
601
 
602
  if ( $is_valid ) {
603
  $settings = $this->filter_settings( $sections, $settings );
604
- $feed_id = $this->save_feed_settings( $feed_id, $form_id, $settings );
605
  if ( $feed_id ) {
606
  GFCommon::add_message( $this->get_save_success_message( $sections ) );
607
  } else {
@@ -622,20 +1010,20 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
622
  */
623
  private function get_ua_codes( $feed_ua, $settings_ua ) {
624
  $google_analytics_codes = array();
625
- if ( !empty( $feed_ua ) ) {
626
- $ga_ua = explode( ',', $feed_ua );
627
- if ( is_array( $ga_ua ) ) {
628
- foreach( $ga_ua as &$value ) {
629
- $value = trim( $value );
630
- }
631
- }
632
- $google_analytics_codes = $ga_ua;
633
- }
634
- if( $settings_ua ) {
635
- $google_analytics_codes[] = $settings_ua;
636
- }
637
- $google_analytics_codes = array_unique( $google_analytics_codes );
638
- return $google_analytics_codes;
639
  }
640
 
641
  /**
@@ -645,77 +1033,77 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
645
  * @return array Array of form settings
646
  */
647
  public function feed_settings_fields() {
648
- $ga_id_placeholder = $this->get_ga_id();
649
  return array(
650
  array(
651
- "title" => __( 'Feed Settings', 'gravity-forms-google-analytics-event-tracking' ),
652
- "fields" => array(
653
  array(
654
  'label' => __( 'Feed Name', 'gravity-forms-google-analytics-event-tracking' ),
655
  'type' => 'text',
656
  'name' => 'feedName',
657
  'class' => 'medium',
658
  'required' => true,
659
- 'tooltip' => '<h6>' . __( 'Feed Name', 'gravity-forms-google-analytics-event-tracking' ) . '</h6>' . __( 'Enter a feed name to uniquely identify this setup.', 'gravity-forms-google-analytics-event-tracking' )
660
- )
661
  ),
662
  ),
663
  array(
664
- "title" => __( 'Submission Tracking Settings', 'gravity-forms-google-analytics-event-tracking' ),
665
- "fields" => array(
666
  array(
667
- "label" => "",
668
- "type" => "instruction_field",
669
- "name" => "instructions"
670
  ),
671
  array(
672
- "label" => __( 'Event UA Code', 'gravity-forms-google-analytics-event-tracking' ),
673
- "type" => "text",
674
- "name" => "gaEventUA",
675
- "class" => "medium",
676
- "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' ) ),
677
- "placeholder" => $ga_id_placeholder,
678
  ),
679
  array(
680
- "label" => __( 'Event Category', 'gravity-forms-google-analytics-event-tracking' ),
681
- "type" => "text",
682
- "name" => "gaEventCategory",
683
- "class" => "medium merge-tag-support mt-position-right",
684
- "tooltip" => sprintf( '<h6>%s</h6>%s', __( 'Event Category', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics event category', 'gravity-forms-google-analytics-event-tracking' ) ),
685
  ),
686
  array(
687
- "label" => __( 'Event Action', 'gravity-forms-google-analytics-event-tracking' ),
688
- "type" => "text",
689
- "name" => "gaEventAction",
690
- "class" => "medium merge-tag-support mt-position-right",
691
- "tooltip" => sprintf( '<h6>%s</h6>%s', __( 'Event Action', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics event action', 'gravity-forms-google-analytics-event-tracking' ) ),
692
  ),
693
  array(
694
- "label" => __( 'Event Label', 'gravity-forms-google-analytics-event-tracking' ),
695
- "type" => "text",
696
- "name" => "gaEventLabel",
697
- "class" => "medium merge-tag-support mt-position-right",
698
- "tooltip" => sprintf( '<h6>%s</h6>%s', __( 'Event Label', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics event label', 'gravity-forms-google-analytics-event-tracking' ) ),
699
  ),
700
  array(
701
- "label" => __( 'Event Value', 'gravity-forms-google-analytics-event-tracking' ),
702
- "type" => "text",
703
- "name" => "gaEventValue",
704
- "class" => "medium merge-tag-support mt-position-right",
705
- "tooltip" => sprintf( '<h6>%s</h6>%s', __( 'Event Value', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics event value. Leave blank to omit pushing a value to Google Analytics. Or to use the purchase value of a payment based form. <strong>Note:</strong> This must be a number (int). Floating numbers (e.g., 20.95) will be rounded up (e.g., 30)', 'gravity-forms-google-analytics-event-tracking' ) ),
706
  ),
707
- )
708
  ),
709
  array(
710
- "title" => __( 'Other Settings', 'gravity-forms-google-analytics-event-tracking' ),
711
- "fields" => array(
712
  array(
713
  'name' => 'conditionalLogic',
714
  'label' => __( 'Conditional Logic', 'gravity-forms-google-analytics-event-tracking' ),
715
  'type' => 'feed_condition',
716
- 'tooltip' => '<h6>' . __( 'Conditional Logic', 'gravity-forms-google-analytics-event-tracking' ) . '</h6>' . __( 'When conditions are enabled, events will only be sent to google when the conditions are met. When disabled, all form submissions will trigger an event.', 'gravity-forms-google-analytics-event-tracking' )
717
- )
718
- )
719
  ),
720
  );
721
  }
@@ -725,16 +1113,16 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
725
  *
726
  * @since 1.5.0
727
  */
728
- public function single_setting_row_instruction_field(){
729
  echo '
730
  <tr>
731
  <th colspan="2">
732
- <p>' . __( "If you leave these blank, the following defaults will be used when the event is tracked", 'gravity-forms-google-analytics-event-tracking' ) . ':</p>
733
  <p>
734
- <strong>' . __( "Event Category", 'gravity-forms-google-analytics-event-tracking' ) . ':</strong> Forms<br>
735
- <strong>' . __( "Event Action", 'gravity-forms-google-analytics-event-tracking' ) . ':</strong> Submission<br>
736
- <strong>' . __( "Event Label", 'gravity-forms-google-analytics-event-tracking' ) . ':</strong> Form: {form_title} ID: {form_id}<br>
737
- <strong>' . __( "Event Value", 'gravity-forms-google-analytics-event-tracking' ) . ':</strong> Payment Amount (on payment forms only, otherwise nothing is sent by default)
738
  </p>
739
  </td>
740
  </tr>';
@@ -742,6 +1130,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
742
 
743
  /**
744
  * Return the feed list columns
 
745
  * @return array columns
746
  */
747
  public function feed_list_columns() {
13
 
14
  class GFGAET_Submission_Feeds extends GFFeedAddOn {
15
 
16
+ protected $_version = GFGAET_VERSION;
17
+ protected $_min_gravityforms_version = GFGAET_MIN_GFORMS_VERSION;
18
+ protected $_slug = 'gravity-forms-event-tracking';
19
+ protected $_path = 'gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php';
20
+ protected $_full_path = __FILE__;
21
+ protected $_title = 'Gravity Forms Google Analytics Event Tracking';
22
+ protected $_short_title = 'Event Tracking';
23
 
24
  // Members plugin integration
25
  protected $_capabilities = array( 'gravityforms_event_tracking', 'gravityforms_event_tracking_uninstall' );
27
  // Permissions
28
  protected $_capabilities_settings_page = 'gravityforms_event_tracking';
29
  protected $_capabilities_form_settings = 'gravityforms_event_tracking';
30
+ protected $_capabilities_uninstall = 'gravityforms_event_tracking_uninstall';
31
 
32
  public $ua_id = false;
33
 
47
  */
48
  public function init() {
49
  parent::init();
50
+
51
+ // GTM UTM Variable Tracking Script.
52
+ add_action( 'wp_enqueue_scripts', array( $this, 'load_utm_gtm_script' ) );
53
+
54
+ // Load analytics?
55
+ add_action( 'wp_head', array( $this, 'maybe_install_analytics' ) );
56
+
57
+ // Load tag manager?
58
+ add_action( 'wp_head', array( $this, 'maybe_install_tag_manager_header' ) );
59
+ add_action( 'wp_body_open', array( $this, 'tag_manager_after_body' ) );
60
+
61
+ if ( $this->is_preview() ) {
62
+ add_action( 'gform_preview_header', array( $this, 'preview_header' ) );
63
+ add_action( 'gform_preview_body_open', array( $this, 'tag_manager_after_body' ) );
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Callback for the preview header action.
69
+ *
70
+ * Load analytics or tag manager in the form preview.
71
+ *
72
+ * @since 2.4.0
73
+ *
74
+ * @param int $form_id The Form ID being previewed.
75
+ */
76
+ public function preview_header( $form_id ) {
77
+
78
+ /**
79
+ * Filter: gform_ua_load_preview
80
+ *
81
+ * Allow Google Analytics and Tag Manager to load on the preview screen.
82
+ *
83
+ * @since 2.4.0
84
+ *
85
+ * @param bool $load_on_preview Whether to load analytics/tag manager on the preview screen.
86
+ */
87
+ $load_on_preview = true;
88
+ $google_analytics_codes = (bool) apply_filters( 'gform_ua_load_preview', $load_on_preview );
89
+
90
+ if ( $load_on_preview ) {
91
+ $this->maybe_install_analytics();
92
+ $this->maybe_install_tag_manager_header();
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Run after the body tag in preview mode and front-end.
98
+ *
99
+ * @since 2.4.0
100
+ *
101
+ * @param int $form_id The form ID.
102
+ */
103
+ public function tag_manager_after_body( $form_id ) {
104
+ $this->maybe_install_tag_manager_after_body();
105
+ }
106
+
107
+ /**
108
+ * Installs Tag Manager after the body tag if enabled.
109
+ *
110
+ * @since 2.4.0
111
+ *
112
+ * @param bool $force Whether to force install tag manager.
113
+ */
114
+ public function maybe_install_tag_manager_after_body( $force = false ) {
115
+ $ua_options = get_option( 'gravityformsaddon_GFGAET_UA_settings', array() );
116
+
117
+ // Check mode. Return if mode is not set.
118
+ if ( ! isset( $ua_options['mode'] ) ) {
119
+ return;
120
+ }
121
+
122
+ // Only load if GA is set in the mode.
123
+ if ( 'gtm_install_on' !== $ua_options['gravity_forms_event_tracking_gtm_install'] ) {
124
+ return;
125
+ }
126
+
127
+ // Get GTM container information. Return if not set.
128
+ $gtm_code = isset( $ua_options['gravity_forms_event_tracking_gtm_account_id'] ) ? sanitize_text_field( $ua_options['gravity_forms_event_tracking_gtm_account_id'] ) : '';
129
+ if ( empty( $gtm_code ) ) {
130
+ return;
131
+ }
132
+
133
+ if ( isset( $ua_options['gravity_forms_event_tracking_gtm_install'] ) ) {
134
+ if ( 'gtm_install_on' === $ua_options['gravity_forms_event_tracking_gtm_install'] ) {
135
+ /**
136
+ * Allow third-parties to enable/disable GTM loading.
137
+ *
138
+ * @since 2.4.0
139
+ *
140
+ * @param bool Output GTM script (default: true).
141
+ * @param bool Whether the output is in preview mode.
142
+ * @param array Saved settings.
143
+ */
144
+ $enable_gtm_output = apply_filters( 'gform_gtm_script_enable', true, $this->is_preview(), $ua_options );
145
+
146
+ if ( ! $enable_gtm_output ) {
147
+ return;
148
+ }
149
+
150
+ // User has requested GTM installation. Proceed.
151
+ ob_start();
152
+ echo "\r\n";
153
+ ?>
154
+ <!-- Google Tag Manager (noscript) -->
155
+ <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=<?php echo esc_js( $gtm_code ); ?>"
156
+ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
157
+ <!-- End Google Tag Manager (noscript) -->
158
+ <?php
159
+ /**
160
+ * Allow custom scripting for Google Tag Manager
161
+ *
162
+ * @since 2.4.0
163
+ *
164
+ * @param string $gtm_code Tag Manager code.
165
+ */
166
+ do_action( 'gform_install_tag_manager_after_body', $gtm_code );
167
+
168
+ /**
169
+ * Allow third-parties to modify the JavaScript that is returned.
170
+ *
171
+ * @since 2.4.0
172
+ *
173
+ * @param string JavaScript to output.
174
+ *
175
+ * @return string JavaScript to output.
176
+ */
177
+ echo wp_kses( apply_filters( 'gform_output_tag_manager_body', ob_get_clean() ), $this->get_javascript_kses() );
178
+ }
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Installs Tag Manager if the user has selected that option in settings.
184
+ *
185
+ * @since 2.4.0
186
+ *
187
+ * @param bool $force Whether to force install tag manager.
188
+ */
189
+ public function maybe_install_tag_manager_header( $force = false ) {
190
+ $ua_options = get_option( 'gravityformsaddon_GFGAET_UA_settings', array() );
191
+
192
+ // Check mode. Return if mode is not set.
193
+ if ( ! isset( $ua_options['mode'] ) ) {
194
+ return;
195
+ }
196
+
197
+ // Only load if GA is set in the mode.
198
+ if ( 'gtm_install_on' !== $ua_options['gravity_forms_event_tracking_gtm_install'] ) {
199
+ return;
200
+ }
201
+
202
+ // Get GTM container information. Return if not set.
203
+ $gtm_code = isset( $ua_options['gravity_forms_event_tracking_gtm_account_id'] ) ? sanitize_text_field( $ua_options['gravity_forms_event_tracking_gtm_account_id'] ) : '';
204
+ if ( empty( $gtm_code ) ) {
205
+ return;
206
+ }
207
+
208
+ if ( isset( $ua_options['gravity_forms_event_tracking_gtm_install'] ) ) {
209
+ if ( 'gtm_install_on' === $ua_options['gravity_forms_event_tracking_gtm_install'] ) {
210
+ /**
211
+ * Allow third-parties to enable/disable GTM loading.
212
+ *
213
+ * @since 2.4.0
214
+ *
215
+ * @param bool Output GTM script (default: true).
216
+ * @param bool Whether the output is in preview mode.
217
+ * @param array Saved settings.
218
+ */
219
+ $enable_gtm_output = apply_filters( 'gform_gtm_script_enable', true, $this->is_preview(), $ua_options );
220
+
221
+ if ( ! $enable_gtm_output ) {
222
+ return;
223
+ }
224
+
225
+ // User has requested GTM installation. Proceed.
226
+ ob_start();
227
+ echo "\r\n";
228
+ ?>
229
+ <!-- Google Tag Manager -->
230
+ <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
231
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
232
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
233
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
234
+ })(window,document,'script','dataLayer','<?php echo esc_js( $gtm_code ); ?>');</script>
235
+ <!-- End Google Tag Manager -->
236
+ <?php
237
+ /**
238
+ * Allow custom scripting for Google Tag Manager
239
+ *
240
+ * @since 2.4.0
241
+ *
242
+ * @param string $gtm_code Tag Manager code.
243
+ */
244
+ do_action( 'gform_install_tag_manager_header', $gtm_code );
245
+
246
+ /**
247
+ * Allow third-parties to modify the JavaScript that is returned.
248
+ *
249
+ * @since 2.4.0
250
+ *
251
+ * @param string JavaScript to output.
252
+ *
253
+ * @return string JavaScript to output.
254
+ */
255
+ echo wp_kses( apply_filters( 'gform_output_tag_manager_header', ob_get_clean() ), $this->get_javascript_kses() );
256
+ }
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Installs GTAG Google Analytics if user has selected that option in settings.
262
+ *
263
+ * @since 2.4.0
264
+ *
265
+ * @param bool $force Whether to force install analytics.
266
+ */
267
+ public function maybe_install_analytics( $force = false ) {
268
+ $ua_options = get_option( 'gravityformsaddon_GFGAET_UA_settings', array() );
269
+
270
+ // Check mode. Return if mode is not set.
271
+ if ( ! isset( $ua_options['mode'] ) ) {
272
+ return;
273
+ }
274
+
275
+ // Only load if GA is set in the mode.
276
+ if ( 'ga_on' !== $ua_options['mode'] ) {
277
+ return;
278
+ }
279
+
280
+ if ( isset( $ua_options['gravity_forms_event_tracking_ua_gtag_install'] ) ) {
281
+ if ( 'gtag_on' === $ua_options['gravity_forms_event_tracking_ua_gtag_install'] ) {
282
+ /**
283
+ * Allow third-parties to enable/disable gtag loading.
284
+ *
285
+ * @since 2.4.0
286
+ *
287
+ * @param bool Output gtag analytics (default: true).
288
+ * @param bool Whether the output is in preview mode.
289
+ * @param array Saved settings.
290
+ *
291
+ * @return bool true to force load analytics, false if not.
292
+ */
293
+ $enable_gtag = apply_filters( 'gform_ua_gtag_enable', true, $this->is_preview(), $ua_options );
294
+
295
+ // Return early if gtag output is disabled via filter.
296
+ if ( ! $enable_gtag ) {
297
+ return;
298
+ }
299
+
300
+ // Return if no Analytics tracking code is active.
301
+ if ( ! isset( $ua_options['gravity_forms_event_tracking_ua'] ) ) {
302
+ return;
303
+ }
304
+
305
+ // Return if GA code is empty.
306
+ $ga_code = $ua_options['gravity_forms_event_tracking_ua'];
307
+ if ( empty( $ga_code ) ) {
308
+ return;
309
+ }
310
+
311
+ // Sanitize ga code.
312
+ $ga_code = sanitize_text_field( $ga_code );
313
+
314
+ // User has requested GA installation. Proceed.
315
+ ob_start();
316
+ echo "\r\n";
317
+ ?>
318
+ <!-- Global site tag (gtag.js) - Google Analytics -->
319
+ <script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo esc_html( $ga_code ); ?>"></script> <?php //phpcs:ignore ?>
320
+ <script>
321
+ window.dataLayer = window.dataLayer || [];
322
+ function gtag(){dataLayer.push(arguments);}
323
+ gtag('js', new Date());
324
+
325
+ gtag('config', '<?php echo esc_js( $ga_code ); ?>');
326
+ <?php
327
+ /**
328
+ * Allow custom scripting for Google Analytics GTAG
329
+ *
330
+ * @since 2.4.0
331
+ *
332
+ * @param string $ga_code Google Analytics Property ID
333
+ */
334
+ do_action( 'gform_ga_install_analytics', $ga_code );
335
+ ?>
336
+ </script>
337
+ <?php
338
+ /**
339
+ * Allow third-parties to modify the JavaScript that is returned.
340
+ *
341
+ * @since 2.4.0
342
+ *
343
+ * @param string JavaScript to output.
344
+ *
345
+ * @return string JavaScript to output.
346
+ */
347
+ echo wp_kses( apply_filters( 'gform_ga_output_analytics', ob_get_clean() ), $this->get_javascript_kses() );
348
+ }
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Load a UTM tracking script for Google Tag Manager.
354
+ */
355
+ public function load_utm_gtm_script() {
356
+ $ua_options = get_option( 'gravityformsaddon_GFGAET_UA_settings', array() );
357
+ if ( isset( $ua_options['gravity_forms_event_tracking_gtm_utm_vars'] ) ) {
358
+ if ( 'utm_on' === $ua_options['gravity_forms_event_tracking_gtm_utm_vars'] ) {
359
+ wp_enqueue_script(
360
+ 'gforms_event_tracking_utm_gtm',
361
+ GFGAET::get_plugin_url( '/js/utm-tag-manager.js' ),
362
+ array( 'jquery', 'wp-ajax-response' ),
363
+ $this->_version,
364
+ true
365
+ );
366
+ }
367
+ }
368
+ }
369
+
370
+ /**
371
+ * Retrieve KSES allowed tags for Google Analytics and/or Tag Manager.
372
+ *
373
+ * @since 2.4.0
374
+ */
375
+ public function get_javascript_kses() {
376
+ $allowed_tags = array(
377
+ 'iframe' => array(
378
+ 'src' => true,
379
+ 'style' => true,
380
+ 'width' => true,
381
+ 'height' => true,
382
+ ),
383
+ 'noscript' => array(),
384
+ 'script' => array(
385
+ 'data-cfasync' => true,
386
+ 'async' => true,
387
+ 'src' => true,
388
+ ),
389
+ );
390
+ /**
391
+ * Allow third-parties to add or substract allowed tags.
392
+ *
393
+ * @since 2.4.0
394
+ *
395
+ * @param array $allowed_tags KSES allowed tags.
396
+ *
397
+ * @return array updated KSES allowed tags.
398
+ */
399
+ $allowed_tags = apply_filters( 'gform_ga_javascript_kses', $allowed_tags );
400
+ return $allowed_tags;
401
  }
402
 
403
  /**
418
 
419
  /**
420
  * Process the feed!
421
+ *
422
  * @param array $feed feed data and settings
423
  * @param array $entry gf entry object
424
  * @param array $form gf form data
425
  */
426
  public function process_feed( $feed, $entry, $form ) {
427
 
428
+ $paypal_feeds = $this->get_feeds_by_slug( 'gravityformspaypal', $form['id'] );
429
  $has_paypal_feed = false;
430
 
431
+ foreach ( $paypal_feeds as $paypal_feed ) {
432
+ if ( $paypal_feed['is_active'] && $this->is_feed_condition_met( $paypal_feed, $form, $entry ) ) {
433
  $has_paypal_feed = true;
434
  break;
435
  }
439
 
440
  if ( $has_paypal_feed ) {
441
  gform_update_meta( $entry['id'], 'ga_event_data', maybe_serialize( $ga_event_data ) );
442
+ } else {
 
443
  $this->track_form_after_submission( $entry, $form, $ga_event_data );
444
  }
445
  }
466
  * @since 1.4.0
467
  * @return bool Returns true if UA ID is loaded, false otherwise
468
  */
469
+ private function get_ga_id() {
470
+ $this->load_ua_settings();
471
+ if ( $this->ua_id == false ) {
472
+ return '';
473
+ } else {
474
+ return $this->ua_id;
475
+ }
476
+ }
477
 
478
  /**
479
  * Get data required for processing
480
+ *
481
  * @param array $feed feed
482
  * @param array $entry GF Entry object
483
  * @param array $form GF Form object
489
  $ga_cookie = isset( $_COOKIE['_ga'] ) ? $_COOKIE['_ga'] : '';
490
 
491
  // Location
492
+ $document_location = str_replace( home_url(), '', $entry['source_url'] );
493
 
494
  // Title
495
  $document_title = isset( $post ) && get_the_title( $post ) ? get_the_title( $post ) : 'no title';
496
 
497
  // Store everything we need for later
498
  $ga_event_data = array(
499
+ 'feed_id' => $feed['id'],
500
+ 'entry_id' => $entry['id'],
501
+ 'ga_cookie' => $ga_cookie,
502
  'document_location' => $document_location,
503
+ 'document_title' => $document_title,
504
+ 'gaEventUA' => $this->get_event_var( 'gaEventUA', $feed, $entry, $form ),
505
+ 'gaEventCategory' => $this->get_event_var( 'gaEventCategory', $feed, $entry, $form ),
506
+ 'gaEventAction' => $this->get_event_var( 'gaEventAction', $feed, $entry, $form ),
507
+ 'gaEventLabel' => $this->get_event_var( 'gaEventLabel', $feed, $entry, $form ),
508
+ 'gaEventValue' => $this->get_event_var( 'gaEventValue', $feed, $entry, $form ),
509
  );
510
 
511
  return $ga_event_data;
518
 
519
  if ( isset( $feed['meta'][ $var ] ) && ! empty( $feed['meta'][ $var ] ) ) {
520
  return $feed['meta'][ $var ];
521
+ } else {
 
522
  switch ( $var ) {
523
  case 'gaEventCategory':
524
  return 'Forms';
562
  }
563
  }
564
 
 
565
  // Push the event to google
566
  $this->push_event( $entry, $form, $ga_event_data );
567
  // Push the event to matomo
603
  */
604
  private function push_event( $entry, $form, $ga_event_data ) {
605
 
606
+ // Get all analytics codes to send
607
+ $google_analytics_codes = $this->get_ua_codes( $ga_event_data['gaEventUA'], $this->get_ga_id() );
608
 
609
  /**
610
  * Filter: gform_ua_ids
619
  */
620
  $google_analytics_codes = apply_filters( 'gform_ua_ids', $google_analytics_codes, $form, $entry );
621
 
622
+ if ( ! is_array( $google_analytics_codes ) || empty( $google_analytics_codes ) ) {
623
+ // If GTM, no need to have a GA code.
624
+ if ( ! GFGAET::is_gtm_only() ) {
625
+ return;
626
+ }
627
+ }
628
+ $google_analytics_codes = array_unique( $google_analytics_codes );
629
 
630
  $event = new GFGAET_Measurement_Protocol();
631
  $event->init();
632
 
633
  // Set some defaults
634
+ $event->set_document_path( str_replace( home_url(), '', $entry['source_url'] ) );
635
  $event_url_parsed = parse_url( home_url() );
636
+ $event->set_document_host( $event_url_parsed['host'] );
637
  $event->set_document_location( str_replace( '//', '/', 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'] ) );
638
  $event->set_document_title( $ga_event_data['document_title'] );
639
 
697
  $event->set_event_value( $event_value );
698
  }
699
 
700
+ $feed_id = absint( $ga_event_data['feed_id'] );
701
  $entry_id = $entry['id'];
702
 
703
  if ( GFGAET::is_ga_only() ) {
704
+ $count = 1;
705
  $is_interactive_hit = 'false';
706
+ $interactive_hit = GFGAET::get_interactive_hit_tracker();
707
+ if ( 'interactive_off' == $interactive_hit ) {
708
  $is_interactive_hit = 'false';
709
  } else {
710
  $is_interactive_hit = 'true';
712
  ?>
713
  <script>
714
  <?php
715
+ foreach ( $google_analytics_codes as $ua_code ) {
716
  ?>
717
 
718
  // Check for gtab implementation
721
  nonInteraction: <?php echo esc_js( $is_interactive_hit ); ?>,
722
  'event_category': '<?php echo esc_js( $event_category ); ?>',
723
  'event_label': '<?php echo esc_js( $event_label ); ?>'
724
+ <?php
725
+ if ( 0 !== $event_value && ! empty( $event_value ) ) {
726
+ echo sprintf( ",'value': '%s'", esc_js( $event_value ) ); }
727
+ ?>
728
  }
729
  );
730
  if ( typeof( console ) == 'object' ) {
765
  }
766
 
767
  // Use that tracker
768
+ window.parent.ga( ga_send, 'event', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>'
769
+ <?php
770
+ if ( 0 !== $event_value && ! empty( $event_value ) ) {
771
+ echo ',' . "'" . esc_js( $event_value ) . "'"; }
772
+ ?>
773
+ ,{
774
  nonInteraction: <?php echo esc_js( $is_interactive_hit ); ?>
775
  });
776
 
787
  } elseif ( GFGAET::is_gtm_only() ) {
788
  ?>
789
  <script>
790
+ var utmVariables = localStorage.getItem('googleAnalyticsUTM');
791
+ var utmSource = '',
792
+ utmMedium = '',
793
+ utmCampaign = '',
794
+ utmTerm = '',
795
+ utmContent = '';
796
+ if ( null != utmVariables ) {
797
+ utmVariables = JSON.parse( utmVariables );
798
+ utmSource = utmVariables.source;
799
+ utmMedium = utmVariables.medium;
800
+ utmCampaign = utmVariables.campaign;
801
+ utmTerm = utmVariables.term;
802
+ utmContent = utmVariables.content;
803
+ }
804
  if ( typeof( window.parent.dataLayer ) != 'undefined' ) {
805
  window.parent.dataLayer.push({'event': 'GFTrackEvent',
806
  'GFTrackCategory':'<?php echo esc_js( $event_category ); ?>',
807
  'GFTrackAction':'<?php echo esc_js( $event_action ); ?>',
808
  'GFTrackLabel':'<?php echo esc_js( $event_label ); ?>',
809
  'GFTrackValue': <?php echo absint( $event_value ); ?>,
810
+ 'GFEntryData':<?php echo wp_json_encode( $entry ); ?>,
811
+ 'GFTrackSource': utmSource,
812
+ 'GFTrackMedium': utmMedium,
813
+ 'GFTrackCampaign': utmCampaign,
814
+ 'GFTrackTerm': utmTerm,
815
+ 'GFTrackContent': utmContent,
816
  });
817
  }
818
  </script>
819
  <?php
820
  return;
821
  } else {
822
+ // Push out the event to each UA code
823
+ foreach ( $google_analytics_codes as $ua_code ) {
824
  // Submit the event
825
  $event->send( $ua_code );
826
  }
827
  }
828
 
 
829
  }
830
 
831
  /**
837
  */
838
  private function push_matomo_event( $entry, $form, $ga_event_data ) {
839
 
840
+ if ( false === GFGAET::is_matomo_configured() ) {
841
+ return;
842
+ }
843
 
844
  $event = new GFGAET_Matomo_HTTP_API();
845
  $event->init();
907
  $event->set_matomo_event_value( $event_value );
908
  }
909
 
910
+ $feed_id = absint( $ga_event_data['feed_id'] );
911
  $entry_id = $entry['id'];
912
 
913
  if ( GFGAET::is_matomo_js_only() ) {
915
  <script>
916
  if ( typeof window.parent._paq != 'undefined' ) {
917
 
918
+ window.parent._paq.push(['trackEvent', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>'
919
+ <?php
920
+ if ( 0 !== $event_value && ! empty( $event_value ) ) {
921
+ echo ',' . "'" . esc_js( $event_value ) . "'"; }
922
+ ?>
923
+ ]);
924
 
925
  }
926
  </script>
948
  return false;
949
  }
950
 
951
+ // ---------- Form Settings Pages --------------------------
952
 
953
  /**
954
  * Form settings page title
957
  * @return string Form Settings Title
958
  */
959
  public function feed_settings_title() {
960
+ return __( 'Event Tracking Settings', 'gravity-forms-google-analytics-event-tracking' );
961
  }
962
 
963
  public function maybe_save_feed_settings( $feed_id, $form_id ) {
983
  $is_valid = $this->validate_settings( $sections, $settings );
984
  $result = false;
985
 
986
+ // Check for a valid UA code
987
+ $feed_ua_code = isset( $settings['gaEventUA'] ) ? $settings['gaEventUA'] : '';
988
+ $ua_codes = $this->get_ua_codes( $feed_ua_code, $this->get_ga_id() );
989
 
990
  if ( $is_valid ) {
991
  $settings = $this->filter_settings( $sections, $settings );
992
+ $feed_id = $this->save_feed_settings( $feed_id, $form_id, $settings );
993
  if ( $feed_id ) {
994
  GFCommon::add_message( $this->get_save_success_message( $sections ) );
995
  } else {
1010
  */
1011
  private function get_ua_codes( $feed_ua, $settings_ua ) {
1012
  $google_analytics_codes = array();
1013
+ if ( ! empty( $feed_ua ) ) {
1014
+ $ga_ua = explode( ',', $feed_ua );
1015
+ if ( is_array( $ga_ua ) ) {
1016
+ foreach ( $ga_ua as &$value ) {
1017
+ $value = trim( $value );
1018
+ }
1019
+ }
1020
+ $google_analytics_codes = $ga_ua;
1021
+ }
1022
+ if ( $settings_ua ) {
1023
+ $google_analytics_codes[] = $settings_ua;
1024
+ }
1025
+ $google_analytics_codes = array_unique( $google_analytics_codes );
1026
+ return $google_analytics_codes;
1027
  }
1028
 
1029
  /**
1033
  * @return array Array of form settings
1034
  */
1035
  public function feed_settings_fields() {
1036
+ $ga_id_placeholder = $this->get_ga_id();
1037
  return array(
1038
  array(
1039
+ 'title' => __( 'Feed Settings', 'gravity-forms-google-analytics-event-tracking' ),
1040
+ 'fields' => array(
1041
  array(
1042
  'label' => __( 'Feed Name', 'gravity-forms-google-analytics-event-tracking' ),
1043
  'type' => 'text',
1044
  'name' => 'feedName',
1045
  'class' => 'medium',
1046
  'required' => true,
1047
+ 'tooltip' => '<h6>' . __( 'Feed Name', 'gravity-forms-google-analytics-event-tracking' ) . '</h6>' . __( 'Enter a feed name to uniquely identify this setup.', 'gravity-forms-google-analytics-event-tracking' ),
1048
+ ),
1049
  ),
1050
  ),
1051
  array(
1052
+ 'title' => __( 'Event Tracking Settings', 'gravity-forms-google-analytics-event-tracking' ),
1053
+ 'fields' => array(
1054
  array(
1055
+ 'label' => '',
1056
+ 'type' => 'instruction_field',
1057
+ 'name' => 'instructions',
1058
  ),
1059
  array(
1060
+ 'label' => __( 'Event UA Code', 'gravity-forms-google-analytics-event-tracking' ),
1061
+ 'type' => 'text',
1062
+ 'name' => 'gaEventUA',
1063
+ 'class' => 'medium',
1064
+ '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' ) ),
1065
+ 'placeholder' => $ga_id_placeholder,
1066
  ),
1067
  array(
1068
+ 'label' => __( 'Event Category', 'gravity-forms-google-analytics-event-tracking' ),
1069
+ 'type' => 'text',
1070
+ 'name' => 'gaEventCategory',
1071
+ 'class' => 'medium merge-tag-support mt-position-right',
1072
+ 'tooltip' => sprintf( '<h6>%s</h6>%s', __( 'Event Category', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics event category', 'gravity-forms-google-analytics-event-tracking' ) ),
1073
  ),
1074
  array(
1075
+ 'label' => __( 'Event Action', 'gravity-forms-google-analytics-event-tracking' ),
1076
+ 'type' => 'text',
1077
+ 'name' => 'gaEventAction',
1078
+ 'class' => 'medium merge-tag-support mt-position-right',
1079
+ 'tooltip' => sprintf( '<h6>%s</h6>%s', __( 'Event Action', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics event action', 'gravity-forms-google-analytics-event-tracking' ) ),
1080
  ),
1081
  array(
1082
+ 'label' => __( 'Event Label', 'gravity-forms-google-analytics-event-tracking' ),
1083
+ 'type' => 'text',
1084
+ 'name' => 'gaEventLabel',
1085
+ 'class' => 'medium merge-tag-support mt-position-right',
1086
+ 'tooltip' => sprintf( '<h6>%s</h6>%s', __( 'Event Label', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics event label', 'gravity-forms-google-analytics-event-tracking' ) ),
1087
  ),
1088
  array(
1089
+ 'label' => __( 'Event Value', 'gravity-forms-google-analytics-event-tracking' ),
1090
+ 'type' => 'text',
1091
+ 'name' => 'gaEventValue',
1092
+ 'class' => 'medium merge-tag-support mt-position-right',
1093
+ 'tooltip' => sprintf( '<h6>%s</h6>%s', __( 'Event Value', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics event value. Leave blank to omit pushing a value to Google Analytics. Or to use the purchase value of a payment based form. <strong>Note:</strong> This must be a number (int). Floating numbers (e.g., 20.95) will be rounded up (e.g., 30)', 'gravity-forms-google-analytics-event-tracking' ) ),
1094
  ),
1095
+ ),
1096
  ),
1097
  array(
1098
+ 'title' => __( 'Other Settings', 'gravity-forms-google-analytics-event-tracking' ),
1099
+ 'fields' => array(
1100
  array(
1101
  'name' => 'conditionalLogic',
1102
  'label' => __( 'Conditional Logic', 'gravity-forms-google-analytics-event-tracking' ),
1103
  'type' => 'feed_condition',
1104
+ 'tooltip' => '<h6>' . __( 'Conditional Logic', 'gravity-forms-google-analytics-event-tracking' ) . '</h6>' . __( 'When conditions are enabled, events will only be sent to google when the conditions are met. When disabled, all form submissions will trigger an event.', 'gravity-forms-google-analytics-event-tracking' ),
1105
+ ),
1106
+ ),
1107
  ),
1108
  );
1109
  }
1113
  *
1114
  * @since 1.5.0
1115
  */
1116
+ public function single_setting_row_instruction_field() {
1117
  echo '
1118
  <tr>
1119
  <th colspan="2">
1120
+ <p>' . __( 'If you leave these blank, the following defaults will be used when the event is tracked', 'gravity-forms-google-analytics-event-tracking' ) . ':</p>
1121
  <p>
1122
+ <strong>' . __( 'Event Category', 'gravity-forms-google-analytics-event-tracking' ) . ':</strong> Forms<br>
1123
+ <strong>' . __( 'Event Action', 'gravity-forms-google-analytics-event-tracking' ) . ':</strong> Submission<br>
1124
+ <strong>' . __( 'Event Label', 'gravity-forms-google-analytics-event-tracking' ) . ':</strong> Form: {form_title} ID: {form_id}<br>
1125
+ <strong>' . __( 'Event Value', 'gravity-forms-google-analytics-event-tracking' ) . ':</strong> Payment Amount (on payment forms only, otherwise nothing is sent by default)
1126
  </p>
1127
  </td>
1128
  </tr>';
1130
 
1131
  /**
1132
  * Return the feed list columns
1133
+ *
1134
  * @return array columns
1135
  */
1136
  public function feed_list_columns() {
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.3.12';
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';
@@ -44,6 +44,15 @@ class GFGAET_UA extends GFAddOn {
44
 
45
  }
46
 
 
 
 
 
 
 
 
 
 
47
  /**
48
  * Plugin settings fields
49
  *
@@ -53,77 +62,239 @@ class GFGAET_UA extends GFAddOn {
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://mediaron.com/event-tracking-for-gravity-forms/">See our guide</a>.</p>', 'gravity-forms-google-analytics-event-tracking' ),
57
  'fields' => array(
58
  array(
59
- 'name' => 'gravity_forms_event_tracking_ua',
60
- 'tooltip' => __( 'Enter your UA code (UA-XXXX-Y) Find it <a href="https://support.google.com/analytics/answer/1032385" target="_blank">using this guide</a>.', 'gravity-forms-google-analytics-event-tracking' ),
61
- 'label' => __( 'UA Tracking ID', 'gravity-forms-google-analytics-event-tracking' ),
62
- 'type' => 'text',
63
- 'class' => 'small',
64
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  ),
66
  array(
67
- 'name' => 'gravity_forms_event_tracking_ua_tracker',
68
- 'tooltip' => __( 'Enter your Tracker you would like to send events from if you are using a custom Tracker', 'gravity-forms-google-analytics-event-tracking' ),
69
- 'label' => __( 'UA Tracker Name', 'gravity-forms-google-analytics-event-tracking' ),
70
- 'type' => 'text',
71
- 'class' => 'small',
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  array(
75
  'name' => 'gravity_forms_event_tracking_ua_interaction_hit',
76
- 'tooltip' => __( 'Enter whether the hits are interactive or not.', 'gravity-forms-google-analytics-event-tracking' ),
77
  'label' => __( 'Non-interactive hits', 'gravity-forms-google-analytics-event-tracking' ),
78
  'type' => 'radio',
79
  'default_value' => 'interactive_on',
80
  'choices' => array(
81
  array(
82
  'name' => 'interactive_on',
83
- 'tooltip' => esc_html__( 'Interaction hits are on', 'gravity-forms-google-analytics-event-tracking' ),
84
  'label' => esc_html__( 'Turn on Interactive Hits', 'gravity-forms-google-analytics-event-tracking' ),
85
  'value' => 'interactive_on',
86
  ),
87
  array(
88
  'name' => 'interactive_off',
89
- 'tooltip' => esc_html__( 'Interaction hits are off', 'gravity-forms-google-analytics-event-tracking' ),
90
  'label' => esc_html__( 'Turn off Interactive Hits', 'gravity-forms-google-analytics-event-tracking' ),
91
  'value' => 'interactive_off',
92
  ),
93
  ),
 
 
 
 
94
 
95
  ),
96
  array(
 
 
 
 
 
 
 
 
 
 
 
97
  'type' => 'radio',
98
- 'name' => 'mode',
99
- 'horizontal' => false,
100
- 'default_value' => 'gmp',
101
- 'label' => 'How would you like to send events?',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  'choices' => array(
103
  array(
104
- 'name' => 'ga_on',
105
- 'tooltip' => esc_html__( 'Forms must be Ajax only', 'gravity-forms-google-analytics-event-tracking' ),
106
- 'label' => esc_html__( 'Google Analytics (Ajax only)', 'gravity-forms-google-analytics-event-tracking' ),
107
- 'value' => 'ga',
108
  ),
109
  array(
110
- 'name' => 'gtm_on',
111
- 'tooltip' => esc_html__( 'Forms must be Ajax only', 'gravity-forms-google-analytics-event-tracking' ),
112
- 'label' => esc_html__( 'Google Tag Manager (Ajax only)', 'gravity-forms-google-analytics-event-tracking' ),
113
- 'value' => 'gtm',
114
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  array(
116
- 'name' => 'gmp_on',
117
- 'tooltip' => esc_html__( 'Events will be sent using the measurement protocol.', 'gravity-forms-google-analytics-event-tracking' ),
118
- 'label' => esc_html__( 'Measurement Protocol (Default)', 'gravity-forms-google-analytics-event-tracking' ),
119
- 'value' => 'gmp',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  ),
121
  ),
122
  ),
123
  ),
124
  ),
125
  array(
126
- 'title' => __( 'Matomo (formerly Piwik) Open Analytics Platform', 'gravity-forms-google-analytics-event-tracking' ),
127
  'fields' => array(
128
  array(
129
  'name' => 'gravity_forms_event_tracking_matomo_url',
@@ -176,14 +347,16 @@ class GFGAET_UA extends GFAddOn {
176
  'label' => 'Make all forms Ajax only?',
177
  'choices' => array(
178
  array(
179
- 'name' => 'ajax_on',
180
- 'label' => esc_html__( 'Ajax only', 'gravity-forms-google-analytics-event-tracking' ),
181
- 'value' => 'on',
 
182
  ),
183
  array(
184
- 'name' => 'ajax_off',
185
- 'label' => esc_html__( 'Default', 'gravity-forms-google-analytics-event-tracking' ),
186
- 'value' => 'off',
 
187
  ),
188
  ),
189
  ),
1
  <?php
2
  GFForms::include_addon_framework();
3
  class GFGAET_UA extends GFAddOn {
4
+ protected $_version = '2.4.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';
44
 
45
  }
46
 
47
+ /**
48
+ * Settings icon for Form settings.
49
+ *
50
+ * @since 2.4.0
51
+ */
52
+ public function get_menu_icon() {
53
+ return '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="analytics" class="svg-inline--fa fa-analytics fa-w-18" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M510.62 92.63C516.03 94.74 521.85 96 528 96c26.51 0 48-21.49 48-48S554.51 0 528 0s-48 21.49-48 48c0 2.43.37 4.76.71 7.09l-95.34 76.27c-5.4-2.11-11.23-3.37-17.38-3.37s-11.97 1.26-17.38 3.37L255.29 55.1c.35-2.33.71-4.67.71-7.1 0-26.51-21.49-48-48-48s-48 21.49-48 48c0 4.27.74 8.34 1.78 12.28l-101.5 101.5C56.34 160.74 52.27 160 48 160c-26.51 0-48 21.49-48 48s21.49 48 48 48 48-21.49 48-48c0-4.27-.74-8.34-1.78-12.28l101.5-101.5C199.66 95.26 203.73 96 208 96c6.15 0 11.97-1.26 17.38-3.37l95.34 76.27c-.35 2.33-.71 4.67-.71 7.1 0 26.51 21.49 48 48 48s48-21.49 48-48c0-2.43-.37-4.76-.71-7.09l95.32-76.28zM400 320h-64c-8.84 0-16 7.16-16 16v160c0 8.84 7.16 16 16 16h64c8.84 0 16-7.16 16-16V336c0-8.84-7.16-16-16-16zm160-128h-64c-8.84 0-16 7.16-16 16v288c0 8.84 7.16 16 16 16h64c8.84 0 16-7.16 16-16V208c0-8.84-7.16-16-16-16zm-320 0h-64c-8.84 0-16 7.16-16 16v288c0 8.84 7.16 16 16 16h64c8.84 0 16-7.16 16-16V208c0-8.84-7.16-16-16-16zM80 352H16c-8.84 0-16 7.16-16 16v128c0 8.84 7.16 16 16 16h64c8.84 0 16-7.16 16-16V368c0-8.84-7.16-16-16-16z"></path></svg>';
54
+ }
55
+
56
  /**
57
  * Plugin settings fields
58
  *
62
  return array(
63
  array(
64
  'title' => __( 'Google Analytics and Google Tag Manager', 'gravity-forms-google-analytics-event-tracking' ),
65
+ '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://mediaron.com/event-tracking-for-gravity-forms/?utm_source=wordpress_admin&utm_medium=documentation&utm_campaign=event_tracking">See our guide</a>.</p>', 'gravity-forms-google-analytics-event-tracking' ),
66
  'fields' => array(
67
  array(
68
+ 'type' => 'radio',
69
+ 'name' => 'mode',
70
+ 'horizontal' => false,
71
+ 'default_value' => 'gmp',
72
+ 'label' => 'How would you like to send events?',
73
+ 'choices' => array(
74
+ array(
75
+ 'name' => 'gmp_on',
76
+ 'label' => esc_html__( 'Measurement Protocol (Default)', 'gravity-forms-google-analytics-event-tracking' ),
77
+ 'value' => 'gmp',
78
+ 'icon' => GFGAET::get_plugin_url( '/img/google-brands.png' ),
79
+ ),
80
+ array(
81
+ 'name' => 'ga_on',
82
+ 'label' => esc_html__( 'Google Analytics (Ajax only forms)', 'gravity-forms-google-analytics-event-tracking' ),
83
+ 'value' => 'ga',
84
+ 'icon' => GFGAET::get_plugin_url( '/img/analytics.png' ),
85
+ ),
86
+ array(
87
+ 'name' => 'gtm_on',
88
+ 'label' => esc_html__( 'Google Tag Manager (Ajax only forms)', 'gravity-forms-google-analytics-event-tracking' ),
89
+ 'value' => 'gtm',
90
+ 'icon' => GFGAET::get_plugin_url( '/img/gtm.png' ),
91
+ ),
92
+ ),
93
  ),
94
  array(
95
+ 'name' => 'gravity_forms_event_tracking_ua',
96
+ 'type' => 'hidden',
97
+ 'dependency' => array(
98
+ 'field' => 'mode',
99
+ 'values' => array( 'gmp', 'ga', 'gtm' ),
100
+ ),
101
+ ),
102
+ array(
103
+ 'name' => 'gravity_forms_event_tracking_ua',
104
+ 'tooltip' => __( 'Enter your UA code (UA-XXXX-Y) Find it <a href="https://support.google.com/analytics/answer/1032385" target="_blank">using this guide</a>.', 'gravity-forms-google-analytics-event-tracking' ),
105
+ 'label' => __( 'UA Tracking ID', 'gravity-forms-google-analytics-event-tracking' ),
106
+ 'type' => 'text',
107
+ 'class' => 'small',
108
+ 'dependency' => array(
109
+ 'field' => 'mode',
110
+ 'values' => array( 'ga', 'gmp' ),
111
+ ),
112
 
113
  ),
114
+ array(
115
+ 'name' => 'gravity_forms_event_tracking_ua_tracker',
116
+ 'type' => 'hidden',
117
+ 'dependency' => array(
118
+ 'field' => 'mode',
119
+ 'values' => array( 'gmp', 'ga', 'gtm' ),
120
+ ),
121
+ ),
122
+ array(
123
+ 'name' => 'gravity_forms_event_tracking_ua_tracker',
124
+ 'tooltip' => __( 'Enter your Tracker you would like to send events from if you are using a custom Tracker (Optional)', 'gravity-forms-google-analytics-event-tracking' ),
125
+ 'label' => __( 'UA Tracker Name (optional)', 'gravity-forms-google-analytics-event-tracking' ),
126
+ 'type' => 'text',
127
+ 'class' => 'small',
128
+ 'dependency' => array(
129
+ 'field' => 'mode',
130
+ 'values' => array( 'ga' ),
131
+ ),
132
+ ),
133
+ array(
134
+ 'name' => 'gravity_forms_event_tracking_ua_interaction_hit',
135
+ 'type' => 'hidden',
136
+ 'dependency' => array(
137
+ 'field' => 'mode',
138
+ 'values' => array( 'ga', 'gtm', 'gmp' ),
139
+ ),
140
+ ),
141
  array(
142
  'name' => 'gravity_forms_event_tracking_ua_interaction_hit',
143
+ 'tooltip' => __( 'Enter whether the hits are interactive or not. <a href="https://support.google.com/analytics/answer/6086082?hl=en" target="_blank">Find out more</a>.', 'gravity-forms-google-analytics-event-tracking' ),
144
  'label' => __( 'Non-interactive hits', 'gravity-forms-google-analytics-event-tracking' ),
145
  'type' => 'radio',
146
  'default_value' => 'interactive_on',
147
  'choices' => array(
148
  array(
149
  'name' => 'interactive_on',
150
+ 'tooltip' => esc_html__( 'Turn on interaction hits such as event tracking hits.', 'gravity-forms-google-analytics-event-tracking' ),
151
  'label' => esc_html__( 'Turn on Interactive Hits', 'gravity-forms-google-analytics-event-tracking' ),
152
  'value' => 'interactive_on',
153
  ),
154
  array(
155
  'name' => 'interactive_off',
156
+ 'tooltip' => esc_html__( 'Turn off interaction hits such as event tracking hits.', 'gravity-forms-google-analytics-event-tracking' ),
157
  'label' => esc_html__( 'Turn off Interactive Hits', 'gravity-forms-google-analytics-event-tracking' ),
158
  'value' => 'interactive_off',
159
  ),
160
  ),
161
+ 'dependency' => array(
162
+ 'field' => 'mode',
163
+ 'values' => array( 'ga' ),
164
+ ),
165
 
166
  ),
167
  array(
168
+ 'name' => 'gravity_forms_event_tracking_ua_gtag_install',
169
+ 'type' => 'hidden',
170
+ 'dependency' => array(
171
+ 'field' => 'mode',
172
+ 'values' => array( 'ga', 'gtm', 'gmp' ),
173
+ ),
174
+ ),
175
+ array(
176
+ 'name' => 'gravity_forms_event_tracking_ua_gtag_install',
177
+ 'tooltip' => __( 'Select "Install gtag" if you would like this add-on to install gtag analytics. <a href="https://developers.google.com/analytics/devguides/collection/gtagjs" target="_blank">Find out More</a>.', 'gravity-forms-google-analytics-event-tracking' ),
178
+ 'label' => __( 'Install GTAG Universal Analytics', 'gravity-forms-google-analytics-event-tracking' ),
179
  'type' => 'radio',
180
+ 'default_value' => 'gtag_off',
181
+ 'choices' => array(
182
+ array(
183
+ 'name' => 'gtag_off',
184
+ 'tooltip' => esc_html__( 'You are using a different tool to add analytics.', 'gravity-forms-google-analytics-event-tracking' ),
185
+ 'label' => esc_html__( 'Do not install gtag Universal Analytics.', 'gravity-forms-google-analytics-event-tracking' ),
186
+ 'value' => 'gtag_off',
187
+ ),
188
+ array(
189
+ 'name' => 'gtag_on',
190
+ 'tooltip' => esc_html__( 'This add-on will install Google Analytics tracking for you using gtag.', 'gravity-forms-google-analytics-event-tracking' ),
191
+ 'label' => esc_html__( 'Install gtag Universal Analytics', 'gravity-forms-google-analytics-event-tracking' ),
192
+ 'value' => 'gtag_on',
193
+ ),
194
+ ),
195
+ 'dependency' => array(
196
+ 'field' => 'mode',
197
+ 'values' => array( 'ga' ),
198
+ ),
199
+ ),
200
+ array(
201
+ 'name' => 'gravity_forms_event_tracking_gtm_utm_vars',
202
+ 'type' => 'hidden',
203
+ 'dependency' => array(
204
+ 'field' => 'mode',
205
+ 'values' => array( 'ga', 'gtm', 'gmp' ),
206
+ ),
207
+ ),
208
+ array(
209
+ 'name' => 'gravity_forms_event_tracking_gtm_utm_vars',
210
+ 'tooltip' => __( 'Install a script that will monitor UTM variables and pass these along to Tag Manager when a form is submitted. <a href="https://support.google.com/analytics/answer/1033863?hl=en" target="_blank">Find out more</a>.', 'gravity-forms-google-analytics-event-tracking' ),
211
+ 'label' => __( 'Track UTM variables to send to Tag Manager', 'gravity-forms-google-analytics-event-tracking' ),
212
+ 'type' => 'radio',
213
+ 'default_value' => 'utm_off',
214
  'choices' => array(
215
  array(
216
+ 'name' => 'utm_off',
217
+ 'tooltip' => esc_html__( 'The script for tracking UTM variables will be off and UTM variables will not be sent to Google Tag Manager.', 'gravity-forms-google-analytics-event-tracking' ),
218
+ 'label' => esc_html__( 'Do not track UTM variables', 'gravity-forms-google-analytics-event-tracking' ),
219
+ 'value' => 'utm_off',
220
  ),
221
  array(
222
+ 'name' => 'utm_on',
223
+ 'tooltip' => esc_html__( 'Track UTM variables across your site and send them to Google Tag Manager upon form submission.', 'gravity-forms-google-analytics-event-tracking' ),
224
+ 'label' => esc_html__( 'Track UTM variables', 'gravity-forms-google-analytics-event-tracking' ),
225
+ 'value' => 'utm_on',
226
  ),
227
+ ),
228
+ 'dependency' => array(
229
+ 'field' => 'mode',
230
+ 'values' => array( 'gtm' ),
231
+ ),
232
+ ),
233
+ array(
234
+ 'name' => 'gravity_forms_event_tracking_gtm_install',
235
+ 'type' => 'hidden',
236
+ 'dependency' => array(
237
+ 'field' => 'mode',
238
+ 'values' => array( 'gtm', 'gmp', 'ga' ),
239
+ ),
240
+ ),
241
+ array(
242
+ 'name' => 'gravity_forms_event_tracking_gtm_install',
243
+ 'tooltip' => __( 'Install Tag Manager for supported themes. If you already have Tag Manager installed, you can leave this option disabled. <a href="https://support.google.com/tagmanager/answer/6103696" target="_blank">Find out more</a>.', 'gravity-forms-google-analytics-event-tracking' ),
244
+ 'label' => __( 'Install Tag Manager', 'gravity-forms-google-analytics-event-tracking' ),
245
+ 'type' => 'radio',
246
+ 'default_value' => 'gtm_install_off',
247
+ 'choices' => array(
248
  array(
249
+ 'name' => 'gtm_install_off',
250
+ 'tooltip' => esc_html__( 'You already have Tag Manager installed.', 'gravity-forms-google-analytics-event-tracking' ),
251
+ 'label' => esc_html__( 'Do not install Tag Manager', 'gravity-forms-google-analytics-event-tracking' ),
252
+ 'value' => 'gtm_install_off',
253
+ ),
254
+ array(
255
+ 'name' => 'gtm_install_on',
256
+ 'tooltip' => esc_html__( 'Install Tag Manager for supported themes', 'gravity-forms-google-analytics-event-tracking' ),
257
+ 'label' => esc_html__( 'Install Tag Manager', 'gravity-forms-google-analytics-event-tracking' ),
258
+ 'value' => 'gtm_install_on',
259
+ ),
260
+ ),
261
+ 'dependency' => array(
262
+ 'field' => 'mode',
263
+ 'values' => array( 'gtm' ),
264
+ ),
265
+ ),
266
+ array(
267
+ 'name' => 'gravity_forms_event_tracking_gtm_account_id',
268
+ 'type' => 'hidden',
269
+ 'dependency' => array(
270
+ 'field' => 'gravity_forms_event_tracking_gtm_install',
271
+ 'values' => array( 'gtm_install_on' ),
272
+ ),
273
+ ),
274
+ array(
275
+ 'name' => 'gravity_forms_event_tracking_gtm_account_id',
276
+ 'tooltip' => __( 'Enter your GTM account ID which can be found in your workspace settings in Tag Manager', 'gravity-forms-google-analytics-event-tracking' ),
277
+ 'label' => __( 'Tag Manager Account ID', 'gravity-forms-google-analytics-event-tracking' ),
278
+ 'type' => 'text',
279
+ 'class' => 'small',
280
+ 'dependency' => array(
281
+ 'operator' => 'ALL', // Defaults to ALL.
282
+ 'fields' => array(
283
+ array(
284
+ 'field' => 'gravity_forms_event_tracking_gtm_install',
285
+ 'values' => array( 'gtm_install_on' ),
286
+ ),
287
+ array(
288
+ 'field' => 'mode',
289
+ 'values' => array( 'gtm' ),
290
+ ),
291
  ),
292
  ),
293
  ),
294
  ),
295
  ),
296
  array(
297
+ 'title' => __( 'Matomo Open Analytics Platform', 'gravity-forms-google-analytics-event-tracking' ),
298
  'fields' => array(
299
  array(
300
  'name' => 'gravity_forms_event_tracking_matomo_url',
347
  'label' => 'Make all forms Ajax only?',
348
  'choices' => array(
349
  array(
350
+ 'name' => 'ajax_on',
351
+ 'label' => esc_html__( 'Ajax only', 'gravity-forms-google-analytics-event-tracking' ),
352
+ 'value' => 'on',
353
+ 'tooltip' => esc_html__( 'For Google Analytics and Tag Manager mode, forms need to be Ajax only. Choosing this option will make all forms Ajax only.', 'gravity-forms-google-analytics-event-tracking' ),
354
  ),
355
  array(
356
+ 'name' => 'ajax_off',
357
+ 'label' => esc_html__( 'Default', 'gravity-forms-google-analytics-event-tracking' ),
358
+ 'value' => 'off',
359
+ 'tooltip' => esc_html__( 'For Google Analytics and Tag Manager mode, forms must be Ajax only. Choose this option if the forms you need Event Tracking on are already using Ajax.', 'gravity-forms-google-analytics-event-tracking' ),
360
  ),
361
  ),
362
  ),
js/utm-tag-manager.js ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function (GF_EventTracking_UTM_Tag_Manager, $) {
2
+ jQuery( document ).ready( function() {
3
+ var hrefObject = wpAjax.unserialize( window.location.href );
4
+ if ( typeof hrefObject.utm_source !== 'undefined' ) {
5
+ var utmSource = decodeURIComponent( hrefObject.utm_source );
6
+ var utmMedium = '',
7
+ utmCampaign = '',
8
+ utmTerm = '',
9
+ utmContent = '';
10
+ if ( typeof hrefObject.utm_medium !== 'undefined' ) {
11
+ utmMedium = decodeURIComponent( hrefObject.utm_medium );
12
+ }
13
+ if ( typeof hrefObject.utm_campaign !== 'undefined' ) {
14
+ utmCampaign = decodeURIComponent( hrefObject.utm_campaign );
15
+ }
16
+ if ( typeof hrefObject.utm_term !== 'undefined' ) {
17
+ utmTerm = decodeURIComponent( hrefObject.utm_term );
18
+ }
19
+ if ( typeof hrefObject.utm_content !== 'undefined' ) {
20
+ utmContent = decodeURIComponent( hrefObject.utm_content );
21
+ }
22
+ var utmObject = {
23
+ source: utmSource,
24
+ medium: utmMedium,
25
+ campaign: utmCampaign,
26
+ term: utmTerm,
27
+ content: utmContent
28
+ };
29
+ localStorage.setItem( 'googleAnalyticsUTM', JSON.stringify( utmObject ) );
30
+ }
31
+ } );
32
+ }(window.GF_EventTracking_UTM_Tag_Manager = window.GF_EventTracking_UTM_Tag_Manager || {}, jQuery));