Version Description
- Released 2015-12-11
- Ability to add multiple UA codes in the feed settings.
Download this release
Release Info
Developer | ronalfy |
Plugin | Event Tracking for Gravity Forms |
Version | 1.6.5 |
Comparing to | |
See all releases |
Code changes from version 1.6.4 to 1.6.5
README.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: nmarks, ronalfy
|
|
3 |
Tags: gravity forms, google analytics, event tracking, adopt-me
|
4 |
Requires at least:4.0
|
5 |
Tested up to: 4.4
|
6 |
-
Stable tag: 1.6.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -83,6 +83,10 @@ Check out the documentation on [github](https://github.com/nathanmarks/wordpress
|
|
83 |
|
84 |
== Changelog ==
|
85 |
|
|
|
|
|
|
|
|
|
86 |
= 1.6.4 =
|
87 |
* Released 2015-09-22
|
88 |
* Testing with WordPress 4.3.
|
@@ -146,5 +150,8 @@ Check out the documentation on [github](https://github.com/nathanmarks/wordpress
|
|
146 |
|
147 |
== Upgrade Notice ==
|
148 |
|
|
|
|
|
|
|
149 |
= 1.6.4 =
|
150 |
WordPress 4.3 compatibility and better internationalization.
|
3 |
Tags: gravity forms, google analytics, event tracking, adopt-me
|
4 |
Requires at least:4.0
|
5 |
Tested up to: 4.4
|
6 |
+
Stable tag: 1.6.5
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
83 |
|
84 |
== Changelog ==
|
85 |
|
86 |
+
= 1.6.5 =
|
87 |
+
* Released 2015-12-11
|
88 |
+
* Ability to add multiple UA codes in the feed settings.
|
89 |
+
|
90 |
= 1.6.4 =
|
91 |
* Released 2015-09-22
|
92 |
* Testing with WordPress 4.3.
|
150 |
|
151 |
== Upgrade Notice ==
|
152 |
|
153 |
+
= 1.6.5 =
|
154 |
+
Ability to add multiple UA codes in the feed settings
|
155 |
+
|
156 |
= 1.6.4 =
|
157 |
WordPress 4.3 compatibility and better internationalization.
|
gravity-forms-event-tracking.php
CHANGED
@@ -10,7 +10,7 @@
|
|
10 |
* Plugin Name: Gravity Forms Google Analytics Event Tracking
|
11 |
* Plugin URI: https://wordpress.org/plugins/gravity-forms-google-analytics-event-tracking/
|
12 |
* Description: Add Google Analytics event tracking to your Gravity Forms with ease.
|
13 |
-
* Version: 1.6.
|
14 |
* Author: Ronald Huereca
|
15 |
* Author URI: http://mediaron.com
|
16 |
* Text Domain: gravity-forms-google-analytics-event-tracking
|
10 |
* Plugin Name: Gravity Forms Google Analytics Event Tracking
|
11 |
* Plugin URI: https://wordpress.org/plugins/gravity-forms-google-analytics-event-tracking/
|
12 |
* Description: Add Google Analytics event tracking to your Gravity Forms with ease.
|
13 |
+
* Version: 1.6.5
|
14 |
* Author: Ronald Huereca
|
15 |
* Author URI: http://mediaron.com
|
16 |
* Text Domain: gravity-forms-google-analytics-event-tracking
|
includes/class-gravity-forms-event-tracking-feed.php
CHANGED
@@ -144,7 +144,7 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
144 |
*/
|
145 |
private function load_ua_settings() {
|
146 |
$gravity_forms_add_on_settings = get_option( 'gravityformsaddon_gravity-forms-event-tracking_settings', array() );
|
147 |
-
|
148 |
$this->ua_id = $ua_id = false;
|
149 |
|
150 |
$ua_id = $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_ua' ];
|
@@ -159,6 +159,21 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
159 |
if ( ! $this->ua_id )
|
160 |
return false;
|
161 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
/**
|
164 |
* Load the google measurement protocol PHP client.
|
@@ -180,7 +195,7 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
180 |
global $post;
|
181 |
|
182 |
// Paypal will need this cookie for the IPN
|
183 |
-
$ga_cookie = $_COOKIE['_ga'];
|
184 |
|
185 |
// Location
|
186 |
$document_location = 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'];
|
@@ -190,9 +205,10 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
190 |
|
191 |
// Store everything we need for later
|
192 |
$ga_event_data = array(
|
193 |
-
'ga_cookie' => $
|
194 |
'document_location' => $document_location,
|
195 |
'document_title' => $document_title,
|
|
|
196 |
'gaEventCategory' => $this->get_event_var( 'gaEventCategory', $feed, $entry, $form ),
|
197 |
'gaEventAction' => $this->get_event_var( 'gaEventAction', $feed, $entry, $form ),
|
198 |
'gaEventLabel' => $this->get_event_var( 'gaEventLabel', $feed, $entry, $form ),
|
@@ -246,7 +262,7 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
246 |
$ga_event_data['gaEventValue'] = $this->get_event_value( $entry, $form );
|
247 |
}
|
248 |
|
249 |
-
$event_vars = array( 'gaEventCategory', 'gaEventAction', 'gaEventLabel', 'gaEventValue' );
|
250 |
|
251 |
foreach ( $event_vars as $var ) {
|
252 |
if ( $ga_event_data[ $var ] ) {
|
@@ -291,9 +307,36 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
291 |
* @param array $form Gravity Forms form object
|
292 |
*/
|
293 |
private function push_event( $entry, $form, $ga_event_data ) {
|
294 |
-
|
295 |
-
|
296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
$event = new \Racecore\GATracking\Tracking\Event();
|
298 |
|
299 |
// Set some defaults
|
@@ -301,25 +344,28 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
301 |
$event->setDocumentTitle( $ga_event_data['document_title'] );
|
302 |
|
303 |
// Set our event object variables
|
304 |
-
$event->setEventCategory( apply_filters( 'gform_event_category', $ga_event_data['gaEventCategory'], $form ) );
|
305 |
-
$event->setEventAction( apply_filters( 'gform_event_action', $ga_event_data['gaEventAction'], $form ) );
|
306 |
-
$event->setEventLabel( apply_filters( 'gform_event_label', $ga_event_data['gaEventLabel'], $form ) );
|
307 |
|
308 |
|
309 |
-
if ( $event_value = apply_filters( 'gform_event_value', $ga_event_data['gaEventValue'], $form ) ) {
|
310 |
// Event value must be a valid float!
|
311 |
$event_value = GFCommon::to_number( $event_value );
|
312 |
$event->setEventValue( $event_value );
|
313 |
}
|
314 |
-
|
315 |
-
//
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
|
|
|
|
|
|
323 |
}
|
324 |
|
325 |
/**
|
@@ -348,7 +394,7 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
348 |
return array(
|
349 |
array(
|
350 |
'title' => __( 'Google Analytics', 'gravity-forms-google-analytics-event-tracking' ),
|
351 |
-
'description' => __( 'Enter your UA code (UA-XXXX-Y)
|
352 |
'fields' => array(
|
353 |
array(
|
354 |
'name' => 'gravity_forms_event_tracking_ua',
|
@@ -356,7 +402,6 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
356 |
'type' => 'text',
|
357 |
'class' => 'medium',
|
358 |
'tooltip' => 'UA-XXXX-Y',
|
359 |
-
'feedback_callback' => array( $this, 'ua_validation' )
|
360 |
),
|
361 |
)
|
362 |
),
|
@@ -382,6 +427,7 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
382 |
* @return array Array of form settings
|
383 |
*/
|
384 |
public function feed_settings_fields() {
|
|
|
385 |
return array(
|
386 |
array(
|
387 |
"title" => __( 'Feed Settings', 'gravity-forms-google-analytics-event-tracking' ),
|
@@ -404,6 +450,14 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
|
|
404 |
"type" => "instruction_field",
|
405 |
"name" => "instructions"
|
406 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
array(
|
408 |
"label" => __( 'Event Category', 'gravity-forms-google-analytics-event-tracking' ),
|
409 |
"type" => "text",
|
144 |
*/
|
145 |
private function load_ua_settings() {
|
146 |
$gravity_forms_add_on_settings = get_option( 'gravityformsaddon_gravity-forms-event-tracking_settings', array() );
|
147 |
+
|
148 |
$this->ua_id = $ua_id = false;
|
149 |
|
150 |
$ua_id = $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_ua' ];
|
159 |
if ( ! $this->ua_id )
|
160 |
return false;
|
161 |
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Load UA Settings
|
165 |
+
*
|
166 |
+
* @since 1.4.0
|
167 |
+
* @return bool Returns true if UA ID is loaded, false otherwise
|
168 |
+
*/
|
169 |
+
private function get_ga_id() {
|
170 |
+
$this->load_ua_settings();
|
171 |
+
if ( $this->ua_id == false ) {
|
172 |
+
return '';
|
173 |
+
} else {
|
174 |
+
return $this->ua_id;
|
175 |
+
}
|
176 |
+
}
|
177 |
|
178 |
/**
|
179 |
* Load the google measurement protocol PHP client.
|
195 |
global $post;
|
196 |
|
197 |
// Paypal will need this cookie for the IPN
|
198 |
+
$ga_cookie = isset( $_COOKIE['_ga'] ) ? $_COOKIE['_ga'] : '';
|
199 |
|
200 |
// Location
|
201 |
$document_location = 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI'];
|
205 |
|
206 |
// Store everything we need for later
|
207 |
$ga_event_data = array(
|
208 |
+
'ga_cookie' => $ga_cookie,
|
209 |
'document_location' => $document_location,
|
210 |
'document_title' => $document_title,
|
211 |
+
'gaEventUA' => $this->get_event_var( 'gaEventUA', $feed, $entry, $form ),
|
212 |
'gaEventCategory' => $this->get_event_var( 'gaEventCategory', $feed, $entry, $form ),
|
213 |
'gaEventAction' => $this->get_event_var( 'gaEventAction', $feed, $entry, $form ),
|
214 |
'gaEventLabel' => $this->get_event_var( 'gaEventLabel', $feed, $entry, $form ),
|
262 |
$ga_event_data['gaEventValue'] = $this->get_event_value( $entry, $form );
|
263 |
}
|
264 |
|
265 |
+
$event_vars = array( 'gaEventUA', 'gaEventCategory', 'gaEventAction', 'gaEventLabel', 'gaEventValue' );
|
266 |
|
267 |
foreach ( $event_vars as $var ) {
|
268 |
if ( $ga_event_data[ $var ] ) {
|
307 |
* @param array $form Gravity Forms form object
|
308 |
*/
|
309 |
private function push_event( $entry, $form, $ga_event_data ) {
|
310 |
+
|
311 |
+
//Get all analytics codes to send
|
312 |
+
$google_analytics_codes = array();
|
313 |
+
if ( !empty( $ga_event_data[ 'gaEventUA' ] ) ) {
|
314 |
+
$ga_ua = explode( ',', $ga_event_data[ 'gaEventUA' ] );
|
315 |
+
if ( is_array( $ga_ua ) ) {
|
316 |
+
foreach( $ga_ua as &$value ) {
|
317 |
+
$value = trim( $value );
|
318 |
+
}
|
319 |
+
}
|
320 |
+
$google_analytics_codes = $ga_ua;
|
321 |
+
}
|
322 |
+
if( $this->ua_id ) {
|
323 |
+
$google_analytics_codes[] = $this->ua_id;
|
324 |
+
}
|
325 |
+
$google_analytics_codes = array_unique( $google_analytics_codes );
|
326 |
+
|
327 |
+
/**
|
328 |
+
* Filter: gform_ua_ids
|
329 |
+
*
|
330 |
+
* Filter all outgoing UA IDs to send events to
|
331 |
+
*
|
332 |
+
* @since 1.6.5
|
333 |
+
*
|
334 |
+
* @param array $google_analytics_codes UA codes
|
335 |
+
* @param object $form Gravity Form form object
|
336 |
+
* @param object $entry Gravity Form Entry Object
|
337 |
+
*/
|
338 |
+
$google_analytics_codes = apply_filters( 'gform_ua_ids', $google_analytics_codes, $form, $entry );
|
339 |
+
|
340 |
$event = new \Racecore\GATracking\Tracking\Event();
|
341 |
|
342 |
// Set some defaults
|
344 |
$event->setDocumentTitle( $ga_event_data['document_title'] );
|
345 |
|
346 |
// Set our event object variables
|
347 |
+
$event->setEventCategory( apply_filters( 'gform_event_category', $ga_event_data['gaEventCategory'], $form, $entry ) );
|
348 |
+
$event->setEventAction( apply_filters( 'gform_event_action', $ga_event_data['gaEventAction'], $form, $entry ) );
|
349 |
+
$event->setEventLabel( apply_filters( 'gform_event_label', $ga_event_data['gaEventLabel'], $form, $entry ) );
|
350 |
|
351 |
|
352 |
+
if ( $event_value = apply_filters( 'gform_event_value', $ga_event_data['gaEventValue'], $form, $entry ) ) {
|
353 |
// Event value must be a valid float!
|
354 |
$event_value = GFCommon::to_number( $event_value );
|
355 |
$event->setEventValue( $event_value );
|
356 |
}
|
357 |
+
|
358 |
+
//Push out the event to each UA code
|
359 |
+
foreach( $google_analytics_codes as $ua_code ) {
|
360 |
+
$tracking = new \Racecore\GATracking\GATracking( $ua_code );
|
361 |
+
$tracking->addTracking( $event );
|
362 |
+
|
363 |
+
try {
|
364 |
+
$tracking->send();
|
365 |
+
} catch (Exception $e) {
|
366 |
+
error_log( $e->getMessage() . ' in ' . get_class( $e ) );
|
367 |
+
}
|
368 |
+
}// Init tracking object
|
369 |
}
|
370 |
|
371 |
/**
|
394 |
return array(
|
395 |
array(
|
396 |
'title' => __( 'Google Analytics', 'gravity-forms-google-analytics-event-tracking' ),
|
397 |
+
'description' => __( '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' ),
|
398 |
'fields' => array(
|
399 |
array(
|
400 |
'name' => 'gravity_forms_event_tracking_ua',
|
402 |
'type' => 'text',
|
403 |
'class' => 'medium',
|
404 |
'tooltip' => 'UA-XXXX-Y',
|
|
|
405 |
),
|
406 |
)
|
407 |
),
|
427 |
* @return array Array of form settings
|
428 |
*/
|
429 |
public function feed_settings_fields() {
|
430 |
+
$ga_id_placeholder = $this->get_ga_id();
|
431 |
return array(
|
432 |
array(
|
433 |
"title" => __( 'Feed Settings', 'gravity-forms-google-analytics-event-tracking' ),
|
450 |
"type" => "instruction_field",
|
451 |
"name" => "instructions"
|
452 |
),
|
453 |
+
array(
|
454 |
+
"label" => __( 'Event UA Code', 'gravity-forms-google-analytics-event-tracking' ),
|
455 |
+
"type" => "text",
|
456 |
+
"name" => "gaEventUA",
|
457 |
+
"class" => "medium",
|
458 |
+
"tooltip" => sprintf( '<h6>%s</h6>%s', __( 'Google Analytics UA Code', 'gravity-forms-google-analytics-event-tracking' ), __( 'Leave empty to use global GA Code. You can enter multiple UA codes as long as they are comma separated.', 'gravity-forms-google-analytics-event-tracking' ) ),
|
459 |
+
"placeholder" => $ga_id_placeholder,
|
460 |
+
),
|
461 |
array(
|
462 |
"label" => __( 'Event Category', 'gravity-forms-google-analytics-event-tracking' ),
|
463 |
"type" => "text",
|