Event Tracking for Gravity Forms - Version 2.2.0

Version Description

  • Released 2018-08-19
  • Bug fix: Non-integer values being sent to Google Analytics weren't tracking as conversions
  • Enhancement: Event values are now sent using the Measurement Protocol, Google Tag Manager, Matamo, and Google Analytics
  • Enhancement: Can now set event values to pagination using filters
  • Note: Google only accepts integer values, so total fields and such will be rounded up or down when viewing your conversion reports
Download this release

Release Info

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

Code changes from version 2.1.1 to 2.2.0

README.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: ronalfy, bigwing, nmarks, kzeni
3
  Tags: gravity forms, google analytics, google tag manager, matomo, piwik, event tracking
4
  Requires at least:4.0
5
  Tested up to: 4.9
6
- Stable tag: 2.1.1
7
  Requires PHP: 5.6
8
- Donate link: https://mediaron.com/contribute/
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -43,11 +43,9 @@ Looking for help setting things up? [Read Our Setup Guide](https://mediaron.com/
43
 
44
  For payment based forms, you can leave the value blank to convert using the total payment amount.
45
 
46
- <h3>Help Contribute</h3>
47
 
48
- * Leave a star rating
49
- * <a href="https://translate.wordpress.org/projects/wp-plugins/gravity-forms-google-analytics-event-tracking">Contribute a translation</a>
50
- * <a href="https://github.com/ronalfy/wordpress-gravity-forms-event-tracking">Contribute some code</a>
51
 
52
  == Installation ==
53
 
@@ -57,7 +55,7 @@ For payment based forms, you can leave the value blank to convert using the tota
57
  = Using The WordPress Dashboard =
58
 
59
  1. Navigate to the 'Add New' in the plugins dashboard
60
- 2. Search for gravity-forms-google-analytics-event-tracking
61
  3. Click 'Install Now'
62
  4. Activate the plugin on the Plugin dashboard
63
 
@@ -85,12 +83,27 @@ For payment based forms, you can leave the value blank to convert using the tota
85
 
86
  = How do I track using JavaScript only? =
87
 
 
 
 
88
  See <a href="https://mediaron.com/event-tracking-for-gravity-forms/google-analytics-mode/">Going Advanced</a>.
89
 
90
- = Does this work with Google Tag Manager =
 
 
91
 
92
  Yes. <a href="https://mediaron.com/event-tracking-for-gravity-forms/google-tag-manager/">Read our Guide on Google Tag Manager</a>.
93
 
 
 
 
 
 
 
 
 
 
 
94
  = Are there any filters/hooks? =
95
 
96
  Check out the documentation on [github](https://github.com/ronalfy/wordpress-gravity-forms-event-tracking)
@@ -103,6 +116,13 @@ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gra
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
 
 
106
  = 2.1.1 =
107
  * Released 2018-06-22
108
  * Documentation update
@@ -223,5 +243,8 @@ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gra
223
 
224
  == Upgrade Notice ==
225
 
 
 
 
226
  = 2.1.0 =
227
  Enhancement: Added Matomo (formerly Piwik) support
3
  Tags: gravity forms, google analytics, google tag manager, matomo, piwik, event tracking
4
  Requires at least:4.0
5
  Tested up to: 4.9
6
+ Stable tag: 2.2.0
7
  Requires PHP: 5.6
8
+ Donate link: https://mediaron.com/give/
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
43
 
44
  For payment based forms, you can leave the value blank to convert using the total payment amount.
45
 
46
+ Development happens on <a href="https://github.com/ronalfy/wordpress-gravity-forms-event-tracking/">GitHub</a>.
47
 
48
+ > Please <a href="https://wordpress.org/support/plugin/gravity-forms-google-analytics-event-tracking/reviews/#new-post">Rate the Plugin</a> or <a href="https://mediaron.com/give/">Give Back</a> to show support.
 
 
49
 
50
  == Installation ==
51
 
55
  = Using The WordPress Dashboard =
56
 
57
  1. Navigate to the 'Add New' in the plugins dashboard
58
+ 2. Search for Event Tracking for Gravity Forms
59
  3. Click 'Install Now'
60
  4. Activate the plugin on the Plugin dashboard
61
 
83
 
84
  = How do I track using JavaScript only? =
85
 
86
+ https://www.youtube.com/watch?v=9749XKDOXLw
87
+
88
+
89
  See <a href="https://mediaron.com/event-tracking-for-gravity-forms/google-analytics-mode/">Going Advanced</a>.
90
 
91
+ = Does this work with Google Tag Manager? =
92
+
93
+ https://www.youtube.com/watch?v=a0Mg5Nw3lxc
94
 
95
  Yes. <a href="https://mediaron.com/event-tracking-for-gravity-forms/google-tag-manager/">Read our Guide on Google Tag Manager</a>.
96
 
97
+ = Can I set values for my form conversions? =
98
+
99
+ https://www.youtube.com/watch?v=GBFOE1QvQeI
100
+
101
+ Yes, the video above shows you how. Please note that values can be integers only, so the result may be rounded up or down.
102
+
103
+ = Can I set a value for pagination? =
104
+
105
+ Yes, check out <a href="https://github.com/ronalfy/wordpress-gravity-forms-event-tracking#gform_pagination_event_action">our filters on GitHub</a>.
106
+
107
  = Are there any filters/hooks? =
108
 
109
  Check out the documentation on [github](https://github.com/ronalfy/wordpress-gravity-forms-event-tracking)
116
 
117
  == Changelog ==
118
 
119
+ = 2.2.0 =
120
+ * Released 2018-08-19
121
+ * Bug fix: Non-integer values being sent to Google Analytics weren't tracking as conversions
122
+ * Enhancement: Event values are now sent using the Measurement Protocol, Google Tag Manager, Matamo, and Google Analytics
123
+ * Enhancement: Can now set event values to pagination <a href="https://github.com/ronalfy/wordpress-gravity-forms-event-tracking#gform_pagination_event_value">using filters</a>
124
+ * Note: Google only accepts integer values, so total fields and such will be rounded up or down when viewing your conversion reports
125
+
126
  = 2.1.1 =
127
  * Released 2018-06-22
128
  * Documentation update
243
 
244
  == Upgrade Notice ==
245
 
246
+ = 2.2.0 =
247
+ Event values can now be sent using the Measurement Protocol, Google Analytics, Google Tag Manager, and Matomo. Please double-check your conversions after you update.
248
+
249
  = 2.1.0 =
250
  Enhancement: Added Matomo (formerly Piwik) support
gravity-forms-event-tracking.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Gravity Forms Event Tracking
4
  * Plugin URI: https://wordpress.org/plugins/gravity-forms-google-analytics-event-tracking/
5
  * Description: Add event tracking to your Gravity Forms with ease using Google Analytics, Tag Manager, or Matomo (formerly Piwik).
6
- * Version: 2.1.1
7
  * Author: Ronald Huereca
8
  * Author URI: https://mediaron.com
9
  * Text Domain: gravity-forms-google-analytics-event-tracking
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.2.0
7
  * Author: Ronald Huereca
8
  * Author URI: https://mediaron.com
9
  * Text Domain: gravity-forms-google-analytics-event-tracking
includes/GFGAET_Measurement_Protocol.php CHANGED
@@ -80,6 +80,7 @@ class GFGAET_Measurement_Protocol {
80
 
81
  // Perform the POST
82
  $response = wp_remote_get( esc_url_raw( $payload ) );
 
83
  }
84
 
85
 
80
 
81
  // Perform the POST
82
  $response = wp_remote_get( esc_url_raw( $payload ) );
83
+
84
  }
85
 
86
 
includes/GFGAET_Pagination.php CHANGED
@@ -88,9 +88,29 @@ class GFGAET_Pagination {
88
  $event_label = sprintf( '%s::%d::%d', esc_html( $form['title'] ), absint( $source_page_number ), absint( $current_page_number ) );
89
  $event_label = apply_filters( 'gform_pagination_event_label', $event_label, $form, $source_page_number, $current_page_number );
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  $event->set_event_category( $event_category );
92
  $event->set_event_action( $event_action );
93
  $event->set_event_label( $event_label );
 
 
 
94
 
95
  if ( GFGAET::is_ga_only() ) {
96
  ?>
@@ -114,7 +134,7 @@ class GFGAET_Pagination {
114
  } else {
115
  // UA code doesn't match, use another tracker
116
  window.parent.ga( 'create', '<?php echo esc_js( $ua_code ); ?>', 'auto', 'GTGAET_Tracker' );
117
- 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 ); ?>' );
118
  }
119
  }
120
  </script>
@@ -127,7 +147,8 @@ class GFGAET_Pagination {
127
  window.parent.dataLayer.push({'event': 'GFTrackEvent',
128
  'GFTrackCategory':'<?php echo esc_js( $event_category ); ?>',
129
  'GFTrackAction':'<?php echo esc_js( $event_action ); ?>',
130
- 'GFTrackLabel':'<?php echo esc_js( $event_label ); ?>'
 
131
  });
132
  }
133
  </script>
@@ -199,6 +220,25 @@ class GFGAET_Pagination {
199
  $event_label = sprintf( '%s::%d::%d', esc_html( $form['title'] ), absint( $source_page_number ), absint( $current_page_number ) );
200
  $event_label = apply_filters( 'gform_pagination_event_label', $event_label, $form, $source_page_number, $current_page_number );
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  $event->set_matomo_event_category( $event_category );
203
  $event->set_matomo_event_action( $event_action );
204
  $event->set_matomo_event_label( $event_label );
@@ -208,7 +248,7 @@ class GFGAET_Pagination {
208
  <script>
209
  if ( typeof window.parent._paq != 'undefined' ) {
210
 
211
- window.parent._paq.push(['trackEvent', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>']);
212
 
213
  }
214
  </script>
88
  $event_label = sprintf( '%s::%d::%d', esc_html( $form['title'] ), absint( $source_page_number ), absint( $current_page_number ) );
89
  $event_label = apply_filters( 'gform_pagination_event_label', $event_label, $form, $source_page_number, $current_page_number );
90
 
91
+ /**
92
+ * Filter: gform_pagination_event_value
93
+ *
94
+ * Filter the event value dynamically
95
+ *
96
+ * @since 2.2.0
97
+ *
98
+ * @param int $event_value Event Value
99
+ * @param array $form Gravity Form form array
100
+ * @param int $source_page_number Source page number
101
+ * @param int $current_page_number Current Page Number
102
+ */
103
+ $event_value = 0;
104
+ // Value is rounded up (Google likes integers only) before given an absolute value
105
+ $event_value = absint( round( GFCommon::to_number( apply_filters( 'gform_pagination_event_value', $event_value, $form, $source_page_number, $current_page_number ) ) ) );
106
+
107
+ // Set environmental variables for the measurement protocol
108
  $event->set_event_category( $event_category );
109
  $event->set_event_action( $event_action );
110
  $event->set_event_label( $event_label );
111
+ if ( 0 !== $event_value ) {
112
+ $event->set_event_value( $event_value );
113
+ }
114
 
115
  if ( GFGAET::is_ga_only() ) {
116
  ?>
134
  } else {
135
  // UA code doesn't match, use another tracker
136
  window.parent.ga( 'create', '<?php echo esc_js( $ua_code ); ?>', 'auto', 'GTGAET_Tracker' );
137
+ 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 ) . "'"; } ?>);
138
  }
139
  }
140
  </script>
147
  window.parent.dataLayer.push({'event': 'GFTrackEvent',
148
  'GFTrackCategory':'<?php echo esc_js( $event_category ); ?>',
149
  'GFTrackAction':'<?php echo esc_js( $event_action ); ?>',
150
+ 'GFTrackLabel':'<?php echo esc_js( $event_label ); ?>',
151
+ 'GFTrackValue': <?php echo absint( $event_value ); ?>
152
  });
153
  }
154
  </script>
220
  $event_label = sprintf( '%s::%d::%d', esc_html( $form['title'] ), absint( $source_page_number ), absint( $current_page_number ) );
221
  $event_label = apply_filters( 'gform_pagination_event_label', $event_label, $form, $source_page_number, $current_page_number );
222
 
223
+ /**
224
+ * Filter: gform_pagination_event_value
225
+ *
226
+ * Filter the event value dynamically
227
+ *
228
+ * @since 2.2.0
229
+ *
230
+ * @param int $event_value Event Value
231
+ * @param array $form Gravity Form form array
232
+ * @param int $source_page_number Source page number
233
+ * @param int $current_page_number Current Page Number
234
+ */
235
+ $event_value = 0;
236
+ // Value is rounded up (Google likes integers only) before given an absolute value
237
+ $event_value = absint( round( GFCommon::to_number( apply_filters( 'gform_pagination_event_value', $event_value, $form, $source_page_number, $current_page_number ) ) ) );
238
+ if ( 0 !== $event_value ) {
239
+ $event->set_matomo_event_value( $event_value );
240
+ }
241
+
242
  $event->set_matomo_event_category( $event_category );
243
  $event->set_matomo_event_action( $event_action );
244
  $event->set_matomo_event_label( $event_label );
248
  <script>
249
  if ( typeof window.parent._paq != 'undefined' ) {
250
 
251
+ 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 ) . "'"; } ?>]);
252
 
253
  }
254
  </script>
includes/GFGAET_Submission_Feeds.php CHANGED
@@ -336,8 +336,8 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
336
  */
337
  $event_value = apply_filters( 'gform_event_value', $ga_event_data['gaEventValue'], $form, $entry );
338
  if ( $event_value ) {
339
- // Event value must be a valid float!
340
- $event_value = GFCommon::to_number( $event_value );
341
  $event->set_event_value( $event_value );
342
  }
343
 
@@ -368,11 +368,11 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
368
 
369
  // If UA code matches, use that tracker
370
  if ( default_ua_code == '<?php echo esc_js( $ua_code ); ?>' ) {
371
- window.parent.ga( 'send', 'event', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>' );
372
  } else {
373
  // UA code doesn't match, use another tracker
374
  window.parent.ga( 'create', '<?php echo esc_js( $ua_code ); ?>', 'auto', 'GTGAET_Tracker<?php echo absint( $count ); ?>' );
375
- window.parent.ga( 'GTGAET_Tracker<?php echo absint( $count ); ?>.send', 'event', '<?php echo esc_js( $event_category );?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>' );
376
  }
377
 
378
  sessionStorage.setItem('feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>', true );
@@ -396,6 +396,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
396
  'GFTrackCategory':'<?php echo esc_js( $event_category ); ?>',
397
  'GFTrackAction':'<?php echo esc_js( $event_action ); ?>',
398
  'GFTrackLabel':'<?php echo esc_js( $event_label ); ?>',
 
399
  'GFEntryData':<?php echo json_encode( $entry ); ?>
400
  });
401
  sessionStorage.setItem("feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>", "true");
@@ -485,8 +486,8 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
485
  */
486
  $event_value = apply_filters( 'gform_event_value', $ga_event_data['gaEventValue'], $form, $entry );
487
  if ( $event_value ) {
488
- // Event value must be a valid float!
489
- $event_value = GFCommon::to_number( $event_value );
490
  $event->set_matomo_event_value( $event_value );
491
  }
492
 
@@ -500,7 +501,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
500
  if ( null == matomo_feed_submission ) {
501
  if ( typeof window.parent._paq != 'undefined' ) {
502
 
503
- window.parent._paq.push(['trackEvent', '<?php echo esc_js( $event_category ); ?>', '<?php echo esc_js( $event_action ); ?>', '<?php echo esc_js( $event_label ); ?>']);
504
 
505
  sessionStorage.setItem('matomo_feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>', true );
506
  }
@@ -672,7 +673,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
672
  "type" => "text",
673
  "name" => "gaEventValue",
674
  "class" => "medium merge-tag-support mt-position-right",
675
- "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/float).', 'gravity-forms-google-analytics-event-tracking' ) ),
676
  ),
677
  )
678
  ),
336
  */
337
  $event_value = apply_filters( 'gform_event_value', $ga_event_data['gaEventValue'], $form, $entry );
338
  if ( $event_value ) {
339
+ // Event value must be a valid integer!
340
+ $event_value = absint( round( GFCommon::to_number( $event_value ) ) );
341
  $event->set_event_value( $event_value );
342
  }
343
 
368
 
369
  // If UA code matches, use that tracker
370
  if ( default_ua_code == '<?php echo esc_js( $ua_code ); ?>' ) {
371
+ window.parent.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 ) { echo ',' . "'" . esc_js( $event_value ) . "'"; } ?>);
372
  } else {
373
  // UA code doesn't match, use another tracker
374
  window.parent.ga( 'create', '<?php echo esc_js( $ua_code ); ?>', 'auto', 'GTGAET_Tracker<?php echo absint( $count ); ?>' );
375
+ window.parent.ga( 'GTGAET_Tracker<?php echo absint( $count ); ?>.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 ) . "'"; } ?>);
376
  }
377
 
378
  sessionStorage.setItem('feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>', true );
396
  'GFTrackCategory':'<?php echo esc_js( $event_category ); ?>',
397
  'GFTrackAction':'<?php echo esc_js( $event_action ); ?>',
398
  'GFTrackLabel':'<?php echo esc_js( $event_label ); ?>',
399
+ 'GFTrackValue': <?php echo absint( $event_value ); ?>,
400
  'GFEntryData':<?php echo json_encode( $entry ); ?>
401
  });
402
  sessionStorage.setItem("feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>", "true");
486
  */
487
  $event_value = apply_filters( 'gform_event_value', $ga_event_data['gaEventValue'], $form, $entry );
488
  if ( $event_value ) {
489
+ // Event value must be a valid integer!
490
+ $event_value = absint( round( GFCommon::to_number( $event_value ) ) );
491
  $event->set_matomo_event_value( $event_value );
492
  }
493
 
501
  if ( null == matomo_feed_submission ) {
502
  if ( typeof window.parent._paq != 'undefined' ) {
503
 
504
+ 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 ) . "'"; } ?>]);
505
 
506
  sessionStorage.setItem('matomo_feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>', true );
507
  }
673
  "type" => "text",
674
  "name" => "gaEventValue",
675
  "class" => "medium merge-tag-support mt-position-right",
676
+ "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' ) ),
677
  ),
678
  )
679
  ),