Event Tracking for Gravity Forms - Version 2.2.4

Version Description

  • Released 2018-10-02
  • Adding support for custom trackers
Download this release

Release Info

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

Code changes from version 2.2.2 to 2.2.4

README.txt CHANGED
@@ -3,7 +3,7 @@ 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.2.2
7
  Requires PHP: 5.6
8
  Donate link: https://mediaron.com/give/
9
  License: GPLv2 or later
@@ -116,6 +116,10 @@ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gra
116
 
117
  == Changelog ==
118
 
 
 
 
 
119
  = 2.2.2 =
120
  * Released 2018-08-27
121
  * Adding support for gtag
@@ -251,6 +255,9 @@ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gra
251
 
252
  == Upgrade Notice ==
253
 
 
 
 
254
  = 2.2.2 =
255
  Adding support for gtag
256
 
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.4
7
  Requires PHP: 5.6
8
  Donate link: https://mediaron.com/give/
9
  License: GPLv2 or later
116
 
117
  == Changelog ==
118
 
119
+ = 2.2.4 =
120
+ * Released 2018-10-02
121
+ * Adding support for custom trackers
122
+
123
  = 2.2.2 =
124
  * Released 2018-08-27
125
  * Adding support for gtag
255
 
256
  == Upgrade Notice ==
257
 
258
+ = 2.2.4 =
259
+ Adding support for custom trackers
260
+
261
  = 2.2.2 =
262
  Adding support for gtag
263
 
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.2.2
7
  * Author: Ronald Huereca
8
  * Author URI: https://mediaron.com
9
  * Text Domain: gravity-forms-google-analytics-event-tracking
@@ -146,6 +146,20 @@ class GFGAET {
146
  }
147
  return false;
148
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
  /**
151
  * Checks whether Google Analytics mode is activated for sending events.
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.4
7
  * Author: Ronald Huereca
8
  * Author URI: https://mediaron.com
9
  * Text Domain: gravity-forms-google-analytics-event-tracking
146
  }
147
  return false;
148
  }
149
+
150
+ /**
151
+ * Get the Google Analytics Tracker
152
+ *
153
+ * @since 2.2.4
154
+ * @return string Returns a custom tracker or empty string if not set
155
+ */
156
+ public static function get_ua_tracker() {
157
+ $gravity_forms_add_on_settings = get_option( 'gravityformsaddon_GFGAET_UA_settings', array() );
158
+
159
+ $tracker = isset( $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_ua_tracker' ] ) ? trim($gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_ua_tracker' ]) : '';
160
+
161
+ return $tracker;
162
+ }
163
 
164
  /**
165
  * Checks whether Google Analytics mode is activated for sending events.
includes/GFGAET_Submission_Feeds.php CHANGED
@@ -362,30 +362,46 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
362
  <?php if ( 0 !== $event_value && !empty( $event_value ) ) { echo sprintf( ",'value': '%s'", esc_js( $event_value ) ); } ?>
363
  }
364
  );
 
 
 
365
  sessionStorage.setItem('feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>', true );
366
  } else {
367
  // Check for GA from Monster Insights Plugin
368
  if ( typeof window.parent.ga == 'undefined' ) {
 
369
  if ( typeof window.parent.__gaTracker != 'undefined' ) {
 
 
 
370
  window.parent.ga = window.parent.__gaTracker;
371
  }
372
  }
 
 
 
373
  if ( typeof window.parent.ga != 'undefined' ) {
374
-
 
 
375
  // Try to get original UA code from third-party plugins or tag manager
376
- var default_ua_code = null;
377
- window.parent.ga(function(tracker) {
378
- default_ua_code = tracker.get('trackingId');
379
- });
380
 
381
- // If UA code matches, use that tracker
382
- if ( default_ua_code == '<?php echo esc_js( $ua_code ); ?>' ) {
383
- 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 && !empty( $event_value ) ) { echo ',' . "'" . esc_js( $event_value ) . "'"; } ?>);
384
- } else {
385
- // UA code doesn't match, use another tracker
386
- window.parent.ga( 'create', '<?php echo esc_js( $ua_code ); ?>', 'auto', 'GTGAET_Tracker<?php echo absint( $count ); ?>' );
387
- 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 ) . "'"; } ?>);
 
 
 
 
 
388
  }
 
 
 
389
 
390
  sessionStorage.setItem('feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>', true );
391
  }
@@ -399,7 +415,7 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
399
  </script>
400
  <?php
401
  return;
402
- } else if ( GFGAET::is_gtm_only() ) {
403
  ?>
404
  <script>
405
  var form_submission = sessionStorage.getItem('feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>');
@@ -418,13 +434,15 @@ class GFGAET_Submission_Feeds extends GFFeedAddOn {
418
  </script>
419
  <?php
420
  return;
 
 
 
 
 
 
421
  }
422
 
423
- //Push out the event to each UA code
424
- foreach( $google_analytics_codes as $ua_code ) {
425
- // Submit the event
426
- $event->send( $ua_code );
427
- }
428
  }
429
 
430
  /**
362
  <?php if ( 0 !== $event_value && !empty( $event_value ) ) { echo sprintf( ",'value': '%s'", esc_js( $event_value ) ); } ?>
363
  }
364
  );
365
+ if ( typeof( console ) == 'object' ) {
366
+ console.log('gtag tried');
367
+ }
368
  sessionStorage.setItem('feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>', true );
369
  } else {
370
  // Check for GA from Monster Insights Plugin
371
  if ( typeof window.parent.ga == 'undefined' ) {
372
+ console.log('ga not found');
373
  if ( typeof window.parent.__gaTracker != 'undefined' ) {
374
+ if( typeof( console ) == 'object' ) {
375
+ console.log('monster insights found');
376
+ }
377
  window.parent.ga = window.parent.__gaTracker;
378
  }
379
  }
380
+ if ( typeof( console ) == 'object' ) {
381
+ console.log('try window.parent.ga');
382
+ }
383
  if ( typeof window.parent.ga != 'undefined' ) {
384
+
385
+ var ga_tracker = '';
386
+ var ga_send = 'send';
387
  // Try to get original UA code from third-party plugins or tag manager
 
 
 
 
388
 
389
+ ga_tracker = '<?php echo esc_js( GFGAET::get_ua_tracker() ); ?>';
390
+ if ( typeof( console ) == 'object' ) {
391
+ console.log( 'tracker name' );
392
+ console.log( ga_tracker );
393
+ }
394
+ if( ga_tracker.length > 0 ) {
395
+ ga_send = ga_tracker + '.' + ga_send;
396
+ }
397
+ if ( typeof( console ) == 'object' ) {
398
+ console.log( 'send command' );
399
+ console.log( ga_send );
400
+ console.log( <?php echo $event_value; ?> );
401
  }
402
+
403
+ // Use that tracker
404
+ 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 ) . "'"; } ?>);
405
 
406
  sessionStorage.setItem('feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>', true );
407
  }
415
  </script>
416
  <?php
417
  return;
418
+ } elseif ( GFGAET::is_gtm_only() ) {
419
  ?>
420
  <script>
421
  var form_submission = sessionStorage.getItem('feed_<?php echo absint( $feed_id ); ?>_entry_<?php echo absint( $entry[ 'id' ] ); ?>');
434
  </script>
435
  <?php
436
  return;
437
+ } else {
438
+ //Push out the event to each UA code
439
+ foreach( $google_analytics_codes as $ua_code ) {
440
+ // Submit the event
441
+ $event->send( $ua_code );
442
+ }
443
  }
444
 
445
+
 
 
 
 
446
  }
447
 
448
  /**
includes/GFGAET_UA.php CHANGED
@@ -62,6 +62,14 @@ class GFGAET_UA extends GFAddOn {
62
  'type' => 'text',
63
  'class' => 'small',
64
 
 
 
 
 
 
 
 
 
65
  ),
66
  array(
67
  'type' => 'radio',
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
  'type' => 'radio',