Event Tracking for Gravity Forms - Version 1.7.0

Version Description

  • Released 2016-03-28
  • Plugin will now display an error if an incompatible version of PHP is installed.
  • Bug Fix: Plugin no longer shows a notice if a UA code isn't set
  • Bug Fix: Plugin will now trigger events if a UA code is set in the feed but not in the settings
  • Enhancement: Document Path will now be set as part of event creation
  • Enhancement: Measurement protocol updated
  • Enhancement: Measurement protocol will not detect SSL and use the appropriate protocol
Download this release

Release Info

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

Code changes from version 1.6.5 to 1.7.0

Files changed (27) hide show
  1. README.txt +26 -6
  2. gravity-forms-event-tracking.php +23 -3
  3. includes/class-gravity-forms-event-tracking-feed.php +134 -29
  4. includes/vendor/ga-mp/src/Racecore/GATracking/Autoloader.php +73 -74
  5. includes/vendor/ga-mp/src/Racecore/GATracking/Client/AbstractClientAdapter.php +63 -0
  6. includes/vendor/ga-mp/src/Racecore/GATracking/Client/Adapter/Socket.php +123 -0
  7. includes/vendor/ga-mp/src/Racecore/GATracking/Client/ClientAdapterInterface.php +12 -0
  8. includes/vendor/ga-mp/src/Racecore/GATracking/Exception.php +3 -2
  9. includes/vendor/ga-mp/src/Racecore/GATracking/Exception/EndpointServerException.php +2 -1
  10. includes/vendor/ga-mp/src/Racecore/GATracking/Exception/InvalidArgumentException.php +25 -0
  11. includes/vendor/ga-mp/src/Racecore/GATracking/Exception/InvalidOptionException.php +25 -0
  12. includes/vendor/ga-mp/src/Racecore/GATracking/Exception/MissingConfigurationException.php +2 -1
  13. includes/vendor/ga-mp/src/Racecore/GATracking/Exception/MissingTrackingParameterException.php +2 -1
  14. includes/vendor/ga-mp/src/Racecore/GATracking/GATracking.php +212 -304
  15. includes/vendor/ga-mp/src/Racecore/GATracking/Request/TrackingRequest.php +48 -0
  16. includes/vendor/ga-mp/src/Racecore/GATracking/Request/TrackingRequestCollection.php +87 -0
  17. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/AbstractTracking.php +508 -685
  18. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/App/Event.php +2 -1
  19. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/App/Screen.php +2 -1
  20. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Ecommerce/Item.php +4 -15
  21. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Ecommerce/Transaction.php +5 -7
  22. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Event.php +2 -1
  23. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Exception.php +2 -1
  24. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Factory.php +43 -0
  25. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Page.php +2 -1
  26. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Social.php +3 -1
  27. includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/User/Timing.php +2 -1
README.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Gravity Forms Google Analytics Event Tracking ===
2
  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.5
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -29,12 +29,20 @@ Looking for help setting things up? [Read My Setup Guide](http://nvis.io/x8fld)
29
  - Awesomeness
30
 
31
  = Configuration =
32
- After installing, you setup your UA ID in the Event Tracking tab on Gravity Forms' settings page and then customize your event category/action/label/value on the form event tracking settings page (see screenshots for more information).
 
 
 
 
 
 
 
 
33
 
34
  For payment based forms, you can leave the value blank to convert using the total payment amount.
35
 
36
  = Hooks/Filters =
37
- Check out the documentation on [github](https://github.com/nathanmarks/wordpress-gravity-forms-event-tracking)
38
 
39
  == Installation ==
40
 
@@ -73,7 +81,7 @@ Looking for help setting things up? [Read My Setup Guide](http://nvis.io/x8fld)
73
 
74
  = Are there any filters/hooks? =
75
 
76
- Check out the documentation on [github](https://github.com/nathanmarks/wordpress-gravity-forms-event-tracking)
77
 
78
  == Screenshots ==
79
 
@@ -83,6 +91,15 @@ Check out the documentation on [github](https://github.com/nathanmarks/wordpress
83
 
84
  == Changelog ==
85
 
 
 
 
 
 
 
 
 
 
86
  = 1.6.5 =
87
  * Released 2015-12-11
88
  * Ability to add multiple UA codes in the feed settings.
@@ -150,6 +167,9 @@ Check out the documentation on [github](https://github.com/nathanmarks/wordpress
150
 
151
  == Upgrade Notice ==
152
 
 
 
 
153
  = 1.6.5 =
154
  Ability to add multiple UA codes in the feed settings
155
 
1
  === Gravity Forms Google Analytics Event Tracking ===
2
  Contributors: nmarks, ronalfy
3
+ Tags: gravity forms, google analytics, event tracking
4
  Requires at least:4.0
5
+ Tested up to: 4.5
6
+ Stable tag: 1.7.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
29
  - Awesomeness
30
 
31
  = Configuration =
32
+ If you meet all the requirements of this plugin, you can simply install this plugin in your WordPress plugins folder.
33
+
34
+ Once this plugin is activated, you can browse to the Gravity Forms settings and find a new sub-menu item called <strong>Event Tracker</strong>. There, you will enter your <a href="https://support.google.com/analytics/answer/1032385?hl=en">Google Analytics Tracking Code</a>.
35
+
36
+ The plugin provides some <a href="http://www.nvisionsolutions.ca/blog/search-engine-optimization/gravity-forms-scalable-event-tracking-google-analytics/">default event categories, labels, and actions</a>. You can override these per form by going into the individual form's settings.
37
+
38
+ Within Google Analytics, you will want to set up an <a href="https://support.google.com/analytics/answer/1032415?hl=en">event-based goal</a> and match the event label, event category, and event action with the ones you set up.
39
+
40
+ On each form, you need to make sure to setup an Event Tracking Feed. Open each forms settings, go to the "Event Tracking" section, and set one up. Leave the fields blank to use the default values.
41
 
42
  For payment based forms, you can leave the value blank to convert using the total payment amount.
43
 
44
  = Hooks/Filters =
45
+ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gravity-forms-event-tracking)
46
 
47
  == Installation ==
48
 
81
 
82
  = Are there any filters/hooks? =
83
 
84
+ Check out the documentation on [github](https://github.com/ronalfy/wordpress-gravity-forms-event-tracking)
85
 
86
  == Screenshots ==
87
 
91
 
92
  == Changelog ==
93
 
94
+ = 1.7.0 =
95
+ * Released 2016-03-28
96
+ * Plugin will now display an error if an incompatible version of PHP is installed.
97
+ * Bug Fix: Plugin no longer shows a notice if a UA code isn't set
98
+ * Bug Fix: Plugin will now trigger events if a UA code is set in the feed but not in the settings
99
+ * Enhancement: Document Path will now be set as part of event creation
100
+ * Enhancement: Measurement protocol updated
101
+ * Enhancement: Measurement protocol will not detect SSL and use the appropriate protocol
102
+
103
  = 1.6.5 =
104
  * Released 2015-12-11
105
  * Ability to add multiple UA codes in the feed settings.
167
 
168
  == Upgrade Notice ==
169
 
170
+ = 1.7.0 =
171
+ Updates to measurement protocol. Friendly notices for incompatible PHP versions and no UA codes.
172
+
173
  = 1.6.5 =
174
  Ability to add multiple UA codes in the feed settings
175
 
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.5
14
  * Author: Ronald Huereca
15
  * Author URI: http://mediaron.com
16
  * Text Domain: gravity-forms-google-analytics-event-tracking
@@ -28,7 +28,7 @@ if ( ! defined( 'WPINC' ) ) {
28
  class Gravity_Forms_Event_Tracking_Bootstrap {
29
 
30
  public static function load(){
31
-
32
  if ( ! method_exists( 'GFForms', 'include_feed_addon_framework' ) ) {
33
  return;
34
  }
@@ -41,4 +41,24 @@ class Gravity_Forms_Event_Tracking_Bootstrap {
41
 
42
  }
43
 
44
- add_action( 'gform_loaded', array( 'Gravity_Forms_Event_Tracking_Bootstrap', 'load' ), 5 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.7.0
14
  * Author: Ronald Huereca
15
  * Author URI: http://mediaron.com
16
  * Text Domain: gravity-forms-google-analytics-event-tracking
28
  class Gravity_Forms_Event_Tracking_Bootstrap {
29
 
30
  public static function load(){
31
+ if ( ! gravity_forms_event_tracking_has_minimum_php() ) return;
32
  if ( ! method_exists( 'GFForms', 'include_feed_addon_framework' ) ) {
33
  return;
34
  }
41
 
42
  }
43
 
44
+ add_action( 'gform_loaded', array( 'Gravity_Forms_Event_Tracking_Bootstrap', 'load' ), 5 );
45
+
46
+
47
+
48
+ //Make sure minimum version of PHP version is supported
49
+ //Returns true if minimum PHP is met, false if not
50
+ function gravity_forms_event_tracking_has_minimum_php() {
51
+ if( ! version_compare( '5.3', PHP_VERSION, '<=' ) ) {
52
+ return false;
53
+ }
54
+ return true;
55
+ }
56
+
57
+ //Spit out error if user isn't using minimum version of PHP
58
+ function gravity_forms_event_tracking_activation() {
59
+ if( !gravity_forms_event_tracking_has_minimum_php() ) {
60
+ deactivate_plugins( plugin_basename( __FILE__ ) );
61
+ 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 ) ) );
62
+ }
63
+ }
64
+ register_activation_hook( __FILE__, 'gravity_forms_event_tracking_activation' );
includes/class-gravity-forms-event-tracking-feed.php CHANGED
@@ -94,16 +94,14 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
94
  // Move this hook so everything else is all done and dusted first!
95
  remove_filter( 'gform_entry_post_save', array( $this, 'maybe_process_feed' ) );
96
 
 
 
97
 
98
- if ( $this->load_ua_settings() ) {
99
- $this->load_measurement_client();
100
 
101
- add_filter( 'gform_after_submission', array( $this, 'maybe_process_feed' ), 10, 2 );
102
-
103
- // IPN hook for paypal standard!
104
- if ( class_exists( 'GFPayPal' ) ) {
105
- add_action( 'gform_paypal_post_ipn', array( $this, 'paypal_track_form_post_ipn' ), 10, 2 );
106
- }
107
  }
108
 
109
  }
@@ -147,7 +145,7 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
147
 
148
  $this->ua_id = $ua_id = false;
149
 
150
- $ua_id = $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_ua' ];
151
 
152
  $ua_regex = "/^UA-[0-9]{5,}-[0-9]{1,}$/";
153
 
@@ -309,20 +307,7 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
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
@@ -335,20 +320,65 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
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
 
343
  $event->setDocumentLocation( $ga_event_data['document_location'] );
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 );
@@ -357,11 +387,15 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
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
  }
@@ -419,6 +453,77 @@ class Gravity_Forms_Event_Tracking extends GFFeedAddOn {
419
  public function feed_settings_title() {
420
  return __( 'Event Tracking Feed Settings', 'gravity-forms-google-analytics-event-tracking' );
421
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
 
423
  /**
424
  * Form settings fields
94
  // Move this hook so everything else is all done and dusted first!
95
  remove_filter( 'gform_entry_post_save', array( $this, 'maybe_process_feed' ) );
96
 
97
+ $this->load_ua_settings();
98
+ $this->load_measurement_client();
99
 
100
+ add_filter( 'gform_after_submission', array( $this, 'maybe_process_feed' ), 10, 2 );
 
101
 
102
+ // IPN hook for paypal standard!
103
+ if ( class_exists( 'GFPayPal' ) ) {
104
+ add_action( 'gform_paypal_post_ipn', array( $this, 'paypal_track_form_post_ipn' ), 10, 2 );
 
 
 
105
  }
106
 
107
  }
145
 
146
  $this->ua_id = $ua_id = false;
147
 
148
+ $ua_id = isset( $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_ua' ] ) ? $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_ua' ] : '';
149
 
150
  $ua_regex = "/^UA-[0-9]{5,}-[0-9]{1,}$/";
151
 
307
  private function push_event( $entry, $form, $ga_event_data ) {
308
 
309
  //Get all analytics codes to send
310
+ $google_analytics_codes = $this->get_ua_codes( $ga_event_data[ 'gaEventUA' ], $this->ua_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
311
 
312
  /**
313
  * Filter: gform_ua_ids
320
  * @param object $form Gravity Form form object
321
  * @param object $entry Gravity Form Entry Object
322
  */
323
+ $google_analytics_codes = apply_filters( 'gform_ua_ids', $google_analytics_codes, $form, $entry );
324
 
325
+ if ( !is_array( $google_analytics_codes ) || empty( $google_analytics_codes ) ) return;
326
+
327
  $event = new \Racecore\GATracking\Tracking\Event();
328
+
329
  // Set some defaults
330
+ $event->setDocumentPath( str_replace( home_url(), '', $entry[ 'source_url' ] ) );
331
  $event->setDocumentLocation( $ga_event_data['document_location'] );
332
  $event->setDocumentTitle( $ga_event_data['document_title'] );
333
 
334
  // Set our event object variables
335
+ /**
336
+ * Filter: gform_event_category
337
+ *
338
+ * Filter the event category dynamically
339
+ *
340
+ * @since 1.6.5
341
+ *
342
+ * @param string $category Event Category
343
+ * @param object $form Gravity Form form object
344
+ * @param object $entry Gravity Form Entry Object
345
+ */
346
  $event->setEventCategory( apply_filters( 'gform_event_category', $ga_event_data['gaEventCategory'], $form, $entry ) );
347
+ /**
348
+ * Filter: gform_event_action
349
+ *
350
+ * Filter the event action dynamically
351
+ *
352
+ * @since 1.6.5
353
+ *
354
+ * @param string $action Event Action
355
+ * @param object $form Gravity Form form object
356
+ * @param object $entry Gravity Form Entry Object
357
+ */
358
  $event->setEventAction( apply_filters( 'gform_event_action', $ga_event_data['gaEventAction'], $form, $entry ) );
359
+ /**
360
+ * Filter: gform_event_label
361
+ *
362
+ * Filter the event label dynamically
363
+ *
364
+ * @since 1.6.5
365
+ *
366
+ * @param string $label Event Label
367
+ * @param object $form Gravity Form form object
368
+ * @param object $entry Gravity Form Entry Object
369
+ */
370
  $event->setEventLabel( apply_filters( 'gform_event_label', $ga_event_data['gaEventLabel'], $form, $entry ) );
371
 
372
+ /**
373
+ * Filter: gform_event_value
374
+ *
375
+ * Filter the event value dynamically
376
+ *
377
+ * @since 1.6.5
378
+ *
379
+ * @param object $form Gravity Form form object
380
+ * @param object $entry Gravity Form Entry Object
381
+ */
382
  if ( $event_value = apply_filters( 'gform_event_value', $ga_event_data['gaEventValue'], $form, $entry ) ) {
383
  // Event value must be a valid float!
384
  $event_value = GFCommon::to_number( $event_value );
387
 
388
  //Push out the event to each UA code
389
  foreach( $google_analytics_codes as $ua_code ) {
390
+ $options = array(
391
+ 'adapter' => array(
392
+ 'ssl' => is_ssl()
393
+ )
394
+ );
395
+ $tracking = new \Racecore\GATracking\GATracking( $ua_code, $options );
396
 
397
  try {
398
+ $tracking->sendTracking( $event );
399
  } catch (Exception $e) {
400
  error_log( $e->getMessage() . ' in ' . get_class( $e ) );
401
  }
453
  public function feed_settings_title() {
454
  return __( 'Event Tracking Feed Settings', 'gravity-forms-google-analytics-event-tracking' );
455
  }
456
+
457
+ public function maybe_save_feed_settings( $feed_id, $form_id ) {
458
+ if ( ! rgpost( 'gform-settings-save' ) ) {
459
+ return $feed_id;
460
+ }
461
+
462
+ check_admin_referer( $this->_slug . '_save_settings', '_' . $this->_slug . '_save_settings_nonce' );
463
+
464
+ if ( ! $this->current_user_can_any( $this->_capabilities_form_settings ) ) {
465
+ GFCommon::add_error_message( esc_html__( "You don't have sufficient permissions to update the form settings.", 'gravityforms' ) );
466
+ return $feed_id;
467
+ }
468
+
469
+ // store a copy of the previous settings for cases where action would only happen if value has changed
470
+ $feed = $this->get_feed( $feed_id );
471
+ $this->set_previous_settings( $feed['meta'] );
472
+
473
+ $settings = $this->get_posted_settings();
474
+ $sections = $this->get_feed_settings_fields();
475
+ $settings = $this->trim_conditional_logic_vales( $settings, $form_id );
476
+
477
+ $is_valid = $this->validate_settings( $sections, $settings );
478
+ $result = false;
479
+
480
+ //Check for a valid UA code
481
+ $feed_ua_code = isset( $settings[ 'gaEventUA' ] ) ? $settings[ 'gaEventUA' ] : '';
482
+ $ua_codes = $this->get_ua_codes( $feed_ua_code, $this->get_ga_id() );
483
+ if ( empty( $ua_codes ) ) {
484
+ GFCommon::add_error_message( __( 'You must set a UA code for event tracking to work.', 'gravity-forms-google-analytics-event-tracking' ) );
485
+ return $feed_id;
486
+ }
487
+
488
+
489
+ if ( $is_valid ) {
490
+ $settings = $this->filter_settings( $sections, $settings );
491
+ $feed_id = $this->save_feed_settings( $feed_id, $form_id, $settings );
492
+ if ( $feed_id ) {
493
+ GFCommon::add_message( $this->get_save_success_message( $sections ) );
494
+ } else {
495
+ GFCommon::add_error_message( $this->get_save_error_message( $sections ) );
496
+ }
497
+ } else {
498
+ GFCommon::add_error_message( $this->get_save_error_message( $sections ) );
499
+ }
500
+
501
+ return $feed_id;
502
+ }
503
+
504
+ /**
505
+ * Return Google Analytics GA Codes
506
+ *
507
+ * @since 1.7.0
508
+ * @return array Array of GA codes
509
+ */
510
+ private function get_ua_codes( $feed_ua, $settings_ua ) {
511
+ $google_analytics_codes = array();
512
+ if ( !empty( $feed_ua ) ) {
513
+ $ga_ua = explode( ',', $feed_ua );
514
+ if ( is_array( $ga_ua ) ) {
515
+ foreach( $ga_ua as &$value ) {
516
+ $value = trim( $value );
517
+ }
518
+ }
519
+ $google_analytics_codes = $ga_ua;
520
+ }
521
+ if( $settings_ua ) {
522
+ $google_analytics_codes[] = $settings_ua;
523
+ }
524
+ $google_analytics_codes = array_unique( $google_analytics_codes );
525
+ return $google_analytics_codes;
526
+ }
527
 
528
  /**
529
  * Form settings fields
includes/vendor/ga-mp/src/Racecore/GATracking/Autoloader.php CHANGED
@@ -1,74 +1,73 @@
1
- <?php
2
- namespace Racecore\GATracking;
3
-
4
- /**
5
- * Google Analytics Measurement PHP Class
6
- * Licensed under the 3-clause BSD License.
7
- * This source file is subject to the 3-clause BSD License that is
8
- * bundled with this package in the LICENSE file. It is also available at
9
- * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
10
- *
11
- * Google Documentation
12
- * https://developers.google.com/analytics/devguides/collection/protocol/v1/
13
- *
14
- * @author Marco Rieger
15
- * @email Rieger(at)racecore.de
16
- * @git https://github.com/ins0
17
- * @url http://www.racecore.de
18
- * @package Racecore\GATracking
19
- */
20
- class Autoloader
21
- {
22
- private $folder;
23
-
24
- /**
25
- * Constructor
26
- *
27
- * @param string $folder
28
- */
29
- public function __construct( $folder = null )
30
- {
31
- if ( ! $folder )
32
- {
33
- $folder = dirname(__FILE__) . '/..';
34
- }
35
-
36
- $this->folder = $folder;
37
- }
38
-
39
- /**
40
- * Handel autoloading of classes
41
- *
42
- * @param $class
43
- * @return bool|mixed
44
- */
45
- public function autoload( $class )
46
- {
47
- $filePath = $this->folder . '/' . str_replace('\\', '/', $class) . '.php';
48
-
49
- if (file_exists($filePath))
50
- {
51
- return ( (require_once $filePath) === false ? true : false );
52
- }
53
-
54
- return false;
55
- }
56
-
57
- /**
58
- * Register SPL Autoload
59
- *
60
- * @param null $folder
61
- * @return bool
62
- */
63
- public static function register( $folder = null )
64
- {
65
- ini_set('unserialize_callback_func', 'spl_autoload_call');
66
-
67
- return spl_autoload_register(
68
- array(
69
- new self($folder),
70
- 'autoload'
71
- )
72
- );
73
- }
74
- }
1
+ <?php
2
+
3
+ namespace Racecore\GATracking;
4
+
5
+ /**
6
+ * Google Analytics Measurement PHP Class
7
+ * Licensed under the 3-clause BSD License.
8
+ * This source file is subject to the 3-clause BSD License that is
9
+ * bundled with this package in the LICENSE file. It is also available at
10
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
11
+ *
12
+ * Google Documentation
13
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
14
+ *
15
+ * @author Marco Rieger
16
+ * @email Rieger(at)racecore.de
17
+ * @git https://github.com/ins0
18
+ * @url http://www.racecore.de
19
+ * @package Racecore\GATracking
20
+ */
21
+ class Autoloader
22
+ {
23
+ private $folder;
24
+
25
+ /**
26
+ * Constructor
27
+ *
28
+ * @param string $folder
29
+ */
30
+ public function __construct($folder = null)
31
+ {
32
+ if (!$folder) {
33
+ $folder = dirname(__FILE__) . '/..';
34
+ }
35
+
36
+ $this->folder = $folder;
37
+ }
38
+
39
+ /**
40
+ * Handel autoloading of classes
41
+ *
42
+ * @param $class
43
+ * @return bool|mixed
44
+ */
45
+ public function autoload($class)
46
+ {
47
+ $filePath = $this->folder . '/' . str_replace('\\', '/', $class) . '.php';
48
+
49
+ if (file_exists($filePath)) {
50
+ return ( (require_once $filePath) === false ? true : false );
51
+ }
52
+
53
+ return false;
54
+ }
55
+
56
+ /**
57
+ * Register SPL Autoload
58
+ *
59
+ * @param null $folder
60
+ * @return bool
61
+ */
62
+ public static function register($folder = null)
63
+ {
64
+ ini_set('unserialize_callback_func', 'spl_autoload_call');
65
+
66
+ return spl_autoload_register(
67
+ array(
68
+ new self($folder),
69
+ 'autoload'
70
+ )
71
+ );
72
+ }
73
+ }
 
includes/vendor/ga-mp/src/Racecore/GATracking/Client/AbstractClientAdapter.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Racecore\GATracking\Client;
4
+
5
+ use Racecore\GATracking\Exception;
6
+ use Racecore\GATracking\Request;
7
+
8
+ class AbstractClientAdapter implements ClientAdapterInterface
9
+ {
10
+ private $options = array();
11
+
12
+ public function __construct($options = array())
13
+ {
14
+ $this->options = $options;
15
+ }
16
+
17
+ /**
18
+ * Set Options
19
+ *
20
+ * @param $options
21
+ * @throws Exception\InvalidArgumentException
22
+ */
23
+ public function setOptions($options)
24
+ {
25
+ if (!is_array($options)) {
26
+ throw new Exception\InvalidArgumentException(sprintf(
27
+ '[%s] expects array; received [%s]',
28
+ __METHOD__,
29
+ gettype($options)
30
+ ));
31
+ }
32
+
33
+ $this->options = $options;
34
+ }
35
+
36
+ /**
37
+ * Return Options
38
+ * @return array
39
+ */
40
+ public function getOptions()
41
+ {
42
+ return $this->options;
43
+ }
44
+
45
+ /**
46
+ * Return Single Option
47
+ * @param $key
48
+ * @return null|mixed
49
+ */
50
+ public function getOption($key)
51
+ {
52
+ if (!isset($this->options[$key])) {
53
+ return null;
54
+ }
55
+
56
+ return $this->options[$key];
57
+ }
58
+
59
+ public function send($url, Request\TrackingRequestCollection $collection)
60
+ {
61
+
62
+ }
63
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Client/Adapter/Socket.php ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Racecore\GATracking\Client\Adapter;
4
+
5
+ use Racecore\GATracking\Client;
6
+ use Racecore\GATracking\Exception;
7
+ use Racecore\GATracking\Request;
8
+
9
+ class Socket extends Client\AbstractClientAdapter
10
+ {
11
+ const READ_TIMEOUT = 3;
12
+ const READ_BUFFER = 8192;
13
+
14
+ private $connection = null;
15
+
16
+ /**
17
+ * Create Connection to the Google Server
18
+ * @param $endpoint
19
+ * @throws Exception\EndpointServerException
20
+ */
21
+ private function createConenction($endpoint)
22
+ {
23
+ // port
24
+ $port = $this->getOption('ssl') == true ? 443 : 80;
25
+
26
+ $connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
27
+ socket_connect($connection, $endpoint['host'], $port);
28
+ socket_set_option($connection, SOL_SOCKET, SO_RCVTIMEO, array('sec' => self::READ_TIMEOUT, 'usec' => 0));
29
+
30
+ if ($this->getOption('async')) {
31
+ socket_set_nonblock($connection);
32
+ }
33
+
34
+ if (!$connection) {
35
+ throw new Exception\EndpointServerException('Analytics Host not reachable! Error:');
36
+ }
37
+
38
+ $this->connection = $connection;
39
+ }
40
+
41
+ /**
42
+ * Write the connection header
43
+ * @param $endpoint
44
+ * @param Request\TrackingRequest $request
45
+ * @param bool $lastData
46
+ * @return string
47
+ * @throws Exception\EndpointServerException
48
+ */
49
+ private function writeHeader($endpoint, Request\TrackingRequest $request, $lastData = false)
50
+ {
51
+ // create data
52
+ $payloadString = http_build_query($request->getPayload());
53
+ $payloadLength = strlen($payloadString);
54
+
55
+ $header = 'POST ' . $endpoint['path'] . ' HTTP/1.1' . "\r\n" .
56
+ 'Host: ' . $endpoint['host'] . "\r\n" .
57
+ 'User-Agent: Google-Measurement-PHP-Client' . "\r\n" .
58
+ 'Content-Length: ' . $payloadLength . "\r\n" .
59
+ ($lastData ? 'Connection: Close' . "\r\n" : '') . "\r\n";
60
+
61
+ // fwrite + check if fwrite was ok
62
+ if (!socket_write($this->connection, $header) || !socket_write($this->connection, $payloadString)) {
63
+ throw new Exception\EndpointServerException('Server closed connection unexpectedly');
64
+ }
65
+
66
+ return $header;
67
+ }
68
+
69
+ /**
70
+ * Read from the current connection
71
+ * @param Request\TrackingRequest $request
72
+ * @return array|false
73
+ */
74
+ private function readConnection(Request\TrackingRequest $request)
75
+ {
76
+ // response
77
+ $response = '';
78
+
79
+ // receive response
80
+ do {
81
+ $out = @socket_read($this->connection, self::READ_BUFFER);
82
+ $response .= $out;
83
+
84
+ if (!$out || strlen($out) < self::READ_BUFFER) {
85
+ break;
86
+ }
87
+ } while (true);
88
+
89
+ // response
90
+ $responseContainer = explode("\r\n\r\n", $response, 2);
91
+ return explode("\r\n", $responseContainer[0]);
92
+ }
93
+
94
+ /**
95
+ * Send the Request Collection to a Server
96
+ * @param $url
97
+ * @param Request\TrackingRequestCollection $requestCollection
98
+ * @return Request\TrackingRequestCollection|void
99
+ * @throws Exception\EndpointServerException
100
+ */
101
+ public function send($url, Request\TrackingRequestCollection $requestCollection)
102
+ {
103
+ // get endpoint
104
+ $endpoint = parse_url($url);
105
+
106
+ $this->createConenction($endpoint);
107
+
108
+ /** @var Request\TrackingRequest $request */
109
+ while ($requestCollection->valid()) {
110
+ $request = $requestCollection->current();
111
+ $requestCollection->next();
112
+
113
+ $this->writeHeader($endpoint, $request, !$requestCollection->valid());
114
+ $responseHeader = $this->readConnection($request);
115
+
116
+ $request->setResponseHeader($responseHeader);
117
+ }
118
+ // connection close
119
+ socket_close($this->connection);
120
+
121
+ return $requestCollection;
122
+ }
123
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Client/ClientAdapterInterface.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Racecore\GATracking\Client;
4
+
5
+ use Racecore\GATracking\Request;
6
+
7
+ interface ClientAdapterInterface
8
+ {
9
+ public function __construct($options = array());
10
+ public function setOptions($options);
11
+ public function send($url, Request\TrackingRequestCollection $collection);
12
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Exception.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking;
3
 
4
  /**
@@ -17,6 +18,6 @@ namespace Racecore\GATracking;
17
  * @url http://www.racecore.de
18
  * @package Racecore\GATracking
19
  */
20
- class Exception extends \UnexpectedValueException
21
  {
22
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking;
4
 
5
  /**
18
  * @url http://www.racecore.de
19
  * @package Racecore\GATracking
20
  */
21
+ class Exception extends \Exception
22
  {
23
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Exception/EndpointServerException.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Exception;
3
 
4
  use Racecore\GATracking\Exception;
@@ -21,4 +22,4 @@ use Racecore\GATracking\Exception;
21
  */
22
  class EndpointServerException extends Exception
23
  {
24
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Exception;
4
 
5
  use Racecore\GATracking\Exception;
22
  */
23
  class EndpointServerException extends Exception
24
  {
25
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Exception/InvalidArgumentException.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Racecore\GATracking\Exception;
4
+
5
+ use Racecore\GATracking\Exception;
6
+
7
+ /**
8
+ * Google Analytics Measurement PHP Class
9
+ * Licensed under the 3-clause BSD License.
10
+ * This source file is subject to the 3-clause BSD License that is
11
+ * bundled with this package in the LICENSE file. It is also available at
12
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
13
+ *
14
+ * Google Documentation
15
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
16
+ *
17
+ * @author Marco Rieger
18
+ * @email Rieger(at)racecore.de
19
+ * @git https://github.com/ins0
20
+ * @url http://www.racecore.de
21
+ * @package Racecore\GATracking\Exception
22
+ */
23
+ class InvalidArgumentException extends Exception
24
+ {
25
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Exception/InvalidOptionException.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Racecore\GATracking\Exception;
4
+
5
+ use Racecore\GATracking\Exception;
6
+
7
+ /**
8
+ * Google Analytics Measurement PHP Class
9
+ * Licensed under the 3-clause BSD License.
10
+ * This source file is subject to the 3-clause BSD License that is
11
+ * bundled with this package in the LICENSE file. It is also available at
12
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
13
+ *
14
+ * Google Documentation
15
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
16
+ *
17
+ * @author Marco Rieger
18
+ * @email Rieger(at)racecore.de
19
+ * @git https://github.com/ins0
20
+ * @url http://www.racecore.de
21
+ * @package Racecore\GATracking\Exception
22
+ */
23
+ class InvalidOptionException extends Exception
24
+ {
25
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Exception/MissingConfigurationException.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Exception;
3
 
4
  use Racecore\GATracking\Exception;
@@ -21,4 +22,4 @@ use Racecore\GATracking\Exception;
21
  */
22
  class MissingConfigurationException extends Exception
23
  {
24
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Exception;
4
 
5
  use Racecore\GATracking\Exception;
22
  */
23
  class MissingConfigurationException extends Exception
24
  {
25
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Exception/MissingTrackingParameterException.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Exception;
3
 
4
  use Racecore\GATracking\Exception;
@@ -21,4 +22,4 @@ use Racecore\GATracking\Exception;
21
  */
22
  class MissingTrackingParameterException extends Exception
23
  {
24
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Exception;
4
 
5
  use Racecore\GATracking\Exception;
22
  */
23
  class MissingTrackingParameterException extends Exception
24
  {
25
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/GATracking.php CHANGED
@@ -1,9 +1,11 @@
1
  <?php
 
2
  namespace Racecore\GATracking;
3
 
4
- use Racecore\GATracking\Exception\EndpointServerException;
5
- use Racecore\GATracking\Exception\MissingConfigurationException;
6
- use Racecore\GATracking\Tracking\AbstractTracking;
 
7
 
8
  /**
9
  * Google Analytics Measurement PHP Class
@@ -23,211 +25,213 @@ use Racecore\GATracking\Tracking\AbstractTracking;
23
  */
24
  class GATracking
25
  {
26
- /**
27
- * Google Analytics Account ID UA-...
28
- *
29
- * @var
30
- */
31
- private $accountID;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  /**
34
- * Current User Client ID
35
- *
36
- * @var string
37
- */
38
- private $clientID;
39
-
40
- /**
41
- * Current User ID
42
- *
43
- * @var string
44
  */
45
- private $userID = null;
 
 
 
 
46
 
47
- /**
48
- * Protocol Version
49
- *
50
- * @var string
51
- */
52
- private $protocol = '1';
53
 
54
- /**
55
- * Analytics Endpoint URL
56
- *
57
- * @var string
58
- */
59
- private $analytics_endpoint = 'http://www.google-analytics.com/collect';
60
 
61
- /**
62
- * Tacking Holder
63
- *
64
- * @var array
65
- */
66
- private $tracking_holder = array();
67
 
68
- /**
69
- * Holds the last Response from Google Analytics Server
70
- *
71
- * @var string
72
- */
73
- private $last_response = null;
74
 
75
  /**
76
- * Holds all Responses from GA Server
77
- *
78
- * @var array
79
- */
80
- private $last_response_stack = array();
81
-
82
- /**
83
- * Send Proxy Variables
84
  *
85
- * @var boolean
86
  */
87
- private $use_proxy;
88
-
89
- /**
90
- * Sets the Use Proxy variable
91
- *
92
- * @param $proxy
93
- */
94
- public function setProxy($proxy)
95
  {
96
- $this->use_proxy = $proxy;
97
  }
98
-
99
  /**
100
- * Returns the Use Proxy variable
101
  *
102
- * @return boolean
103
  */
104
- public function getProxy()
105
  {
106
- return $this->use_proxy;
107
  }
108
 
109
  /**
110
- * Sets the Analytics Account ID
111
  *
112
- * @param $account
113
  */
114
- public function setAccountID($account)
115
  {
116
-
117
- $this->accountID = $account;
118
  }
119
 
120
  /**
121
- * Set the current Client ID
122
  *
123
- * @param $clientID
124
- * @return $this
125
  */
126
- public function setClientID($clientID)
127
  {
128
- $this->clientID = $clientID;
129
- return $this;
130
  }
131
 
132
  /**
133
- * Returns the current Client ID
134
  *
135
- * @return string
 
136
  */
137
- public function getClientID()
138
  {
139
- if (!$this->clientID) {
140
- $this->clientID = $this->createClientID();
 
 
 
 
141
  }
142
 
143
- return $this->clientID;
144
- }
145
-
146
- /**
147
- * Set the current User ID
148
- *
149
- * @param $clientID
150
- * @return $this
151
- */
152
- public function setUserID($userID)
153
- {
154
- $this->userID = $userID;
155
- return $this;
156
  }
157
 
158
  /**
159
- * Returns the current User ID
160
  *
161
- * @return string
 
162
  */
163
- public function getUserID()
164
  {
165
- return $this->userID;
 
 
 
 
 
166
  }
167
 
168
  /**
169
- * Return all registered Events
170
  *
171
  * @return array
172
  */
173
- public function getEvents()
174
  {
175
- return $this->tracking_holder;
176
  }
177
 
178
  /**
179
- * Returns current Google Account ID
180
  *
181
- * @return mixed
 
182
  */
183
- public function getAccountID()
184
  {
185
- return $this->accountID;
 
 
 
 
186
  }
187
 
188
  /**
189
- * Constructor
190
  *
191
- * @param string $accountID
192
- * @param boolean $proxy (default: false)
193
  */
194
- public function __construct( $accountID = null, $proxy = false )
195
  {
196
- $this->setAccountID( $accountID );
197
- $this->setProxy($proxy);
198
-
199
- return $this;
200
  }
201
 
202
  /**
203
- * Create a GUID on Client specific values
204
  *
205
  * @return string
206
  */
207
- private function createClientID()
208
  {
 
 
 
 
 
209
  // collect user specific data
210
  if (isset($_COOKIE['_ga'])) {
211
-
212
  $gaCookie = explode('.', $_COOKIE['_ga']);
213
- if( isset($gaCookie[2] ) )
214
- {
215
  // check if uuid
216
- if( $this->checkUUID( $gaCookie[2] ) )
217
- {
218
  // uuid set in cookie
219
  return $gaCookie[2];
220
- }
221
- elseif( isset($gaCookie[2]) && isset($gaCookie[3]) )
222
- {
223
- // google default client id
224
  return $gaCookie[2] . '.' . $gaCookie[3];
225
  }
226
  }
227
  }
228
 
229
- // nothing found - return random uuid client id
230
- return $this->generateUUID();
 
 
 
 
 
231
  }
232
 
233
  /**
@@ -236,9 +240,12 @@ class GATracking
236
  * @param $uuid
237
  * @return int
238
  */
239
- private function checkUUID( $uuid )
240
  {
241
- return preg_match('#^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$#i', $uuid );
 
 
 
242
  }
243
 
244
  /**
@@ -247,231 +254,132 @@ class GATracking
247
  * @author Andrew Moore http://www.php.net/manual/en/function.uniqid.php#94959
248
  * @return string
249
  */
250
- private function generateUUID() {
251
- return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
 
 
252
  // 32 bits for "time_low"
253
- mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
254
-
255
  // 16 bits for "time_mid"
256
- mt_rand( 0, 0xffff ),
257
-
258
  // 16 bits for "time_hi_and_version",
259
  // four most significant bits holds version number 4
260
- mt_rand( 0, 0x0fff ) | 0x4000,
261
-
262
  // 16 bits, 8 bits for "clk_seq_hi_res",
263
  // 8 bits for "clk_seq_low",
264
  // two most significant bits holds zero and one for variant DCE1.1
265
- mt_rand( 0, 0x3fff ) | 0x8000,
266
-
267
  // 48 bits for "node"
268
- mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
 
 
269
  );
270
  }
271
 
272
  /**
273
- * Send all captured Trackings to Analytics Server
274
- * Flush all prev. captured tracking responses
275
  *
276
- * @return bool
277
- */
278
- public function send()
279
- {
280
- // clear response logs
281
- $this->last_response_stack = array();
282
- $this->last_response = null;
283
-
284
- /** @var AbstractTracking $event */
285
- foreach ($this->tracking_holder as $tracking) {
286
- $this->sendTracking($tracking);
287
- }
288
-
289
- return true;
290
- }
291
-
292
- /**
293
- * Returns the Client IP
294
- * The last octect of the IP address is removed to anonymize the user
295
- *
296
- * @param string $address
297
- * @return string
298
  */
299
- function getClientIP($address = '')
300
  {
 
 
 
 
 
 
 
 
 
 
 
301
 
302
- if (!$address) {
303
- $address = $_SERVER['REMOTE_ADDR'];
304
- }
305
-
306
- if (!$address) {
307
- return '';
308
- }
309
 
310
- // Capture the first three octects of the IP address and replace the forth
311
- // with 0, e.g. 124.455.3.123 becomes 124.455.3.0
312
- $regex = "/^([^.]+\.[^.]+\.[^.]+\.).*/";
313
- if (preg_match($regex, $address, $matches)) {
314
- return $matches[1] . '0';
315
  }
316
 
317
- return '';
318
  }
319
 
320
  /**
321
- * Build the POST Packet
322
  *
323
- * @param AbstractTracking $event
324
- * @return string
325
  * @throws Exception\MissingConfigurationException
 
326
  */
327
- private function buildPacket( AbstractTracking $event )
328
  {
329
- // get packet
330
- $eventPacket = $event->getPaket();
331
 
332
- if( ! $this->getAccountID() )
333
- {
334
- throw new MissingConfigurationException('Google Account ID is missing');
335
- }
336
 
337
- // Add Protocol
338
- $eventPacket['v'] = $this->protocol; // protocol version
339
- $eventPacket['tid'] = $this->getAccountID(); // account id
340
- $eventPacket['cid'] = $this->getClientID(); // client id
341
-
342
- if($this->getUserID() != null){
343
- $eventPacket['uid'] = $this->getUserID();
344
- }
345
-
346
- //Proxy Variables
347
- if($this->getProxy()){
348
- $eventPacket['uip'] = $_SERVER['REMOTE_ADDR']; // IP Override
349
- $eventPacket['ua'] = $_SERVER['HTTP_USER_AGENT']; // UA Override
350
- }
351
 
352
- $eventPacket = array_reverse($eventPacket);
 
 
353
 
354
- // build query
355
- return http_build_query($eventPacket);
356
- }
357
 
358
- /**
359
- * Send an Event to Google Analytics
360
- * Will be removed
361
- *
362
- * @param AbstractTracking $tracking
363
- * @return bool
364
- * @throws Exception\EndpointServerException
365
- * @deprecated Use sendTracking
366
- */
367
- public function sendEvent(AbstractTracking $tracking)
368
- {
369
- return $this->sendTracking($tracking);
370
  }
371
 
372
  /**
373
- * Send an Event to Google Analytics
374
  *
375
- * @param AbstractTracking $event
 
376
  * @return bool
377
- * @throws Exception\EndpointServerException
378
  */
379
- public function sendTracking(AbstractTracking $event)
380
  {
381
- // get packet
382
- $eventPacket = $this->buildPacket( $event );
383
-
384
- // get endpoint
385
- $endpoint = parse_url($this->analytics_endpoint);
386
-
387
- // port
388
- $port = ($endpoint['scheme'] == 'https' ? 443 : 80);
389
-
390
- // connect
391
- $connection = @fsockopen($endpoint['scheme'] == 'https' ? 'ssl://' : $endpoint['host'], $port, $error, $errorstr, 10);
392
-
393
- if (!$connection) {
394
- throw new EndpointServerException('Analytics Host not reachable!');
395
  }
396
 
397
- $header = 'POST ' . $endpoint['path'] . ' HTTP/1.1' . "\r\n" .
398
- 'Host: ' . $endpoint['host'] . "\r\n" .
399
- 'User-Agent: Google-Measurement-PHP-Client' . "\r\n" .
400
- 'Content-Type: application/x-www-form-urlencoded' . "\r\n" .
401
- 'Content-Length: ' . strlen($eventPacket) . "\r\n" .
402
- 'Connection: Close' . "\r\n\r\n";
403
-
404
- $this->last_response = '';
405
-
406
- // frwite data
407
- fwrite($connection, $header);
408
- fwrite($connection, $eventPacket);
409
-
410
- // response
411
- $response = '';
412
-
413
- // receive response
414
- while (!feof($connection)) {
415
- $response .= fgets($connection, 1024);
416
  }
417
-
418
- // response
419
- $responseContainer = explode("\r\n\r\n", $response, 2);
420
- $responseContainer[0] = explode("\r\n", $responseContainer[0]);
421
-
422
- // save last response
423
- $this->addResponse( $responseContainer );
424
-
425
- // connection close
426
- fclose($connection);
427
-
428
- return true;
429
- }
430
-
431
- /**
432
- * Add a Response to the Stack
433
- *
434
- * @param $response
435
- * @return bool
436
- */
437
- public function addResponse( $response )
438
- {
439
- $this->last_response_stack[] = $response;
440
- $this->last_response = $response;
441
- return true;
442
- }
443
-
444
- /**
445
- * Returns the last Response from Google Analytics Server
446
- *
447
- * @author Marco Rieger
448
- * @return string
449
- */
450
- public function getLastResponse()
451
- {
452
- return $this->last_response;
453
  }
454
 
455
  /**
456
- * Returns all Responses since the last Send Method Call
457
  *
458
- * @return array
 
459
  */
460
- public function getLastResponseStack()
461
  {
462
- return $this->last_response_stack;
 
 
463
  }
464
 
465
  /**
466
- * Add Tracking Event
467
  *
468
- * @param AbstractTracking $tracking
469
- * @return $this
470
  */
471
- public function addTracking(AbstractTracking $tracking)
472
  {
473
- $this->tracking_holder[] = $tracking;
474
-
475
- return $this;
476
  }
477
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking;
4
 
5
+ use Racecore\GATracking\Request;
6
+ use Racecore\GATracking\Client;
7
+ use Racecore\GATracking\Exception;
8
+ use Racecore\GATracking\Tracking;
9
 
10
  /**
11
  * Google Analytics Measurement PHP Class
25
  */
26
  class GATracking
27
  {
28
+ /** @var null */
29
+ private $analyticsAccountUid = null;
30
+
31
+ /** @var array */
32
+ private $options = array(
33
+ 'client_create_random_id' => true, // create a random client id when the class can't fetch the current client id or none is provided by "client_id"
34
+ 'client_fallback_id' => 555, // fallback client id when cid was not found and random client id is off
35
+ 'client_id' => null, // override client id
36
+ 'user_id' => null, // determine current user id
37
+
38
+ // adapter options
39
+ 'adapter' => array(
40
+ 'async' => true, // requests to google are async - don't wait for google server response
41
+ 'ssl' => false // use ssl connection to google server
42
+ )
43
+
44
+ // use proxy
45
+ /**
46
+ 'proxy' => array(
47
+ 'ip' => '127.0.0.1', // override the proxy ip with this one
48
+ 'user_agent' => 'override agent' // override the proxy user agent
49
+ ),
50
+ **/
51
+ );
52
+
53
+ /** @var Client\AbstractClientAdapter */
54
+ private $clientAdapter = null;
55
+
56
+ /** @var string */
57
+ private $apiProtocolVersion = '1';
58
+ private $apiEndpointUrl = 'http://www.google-analytics.com/collect';
59
 
60
  /**
61
+ * @param $analyticsAccountUid
62
+ * @param array $options
63
+ * @param Client\AbstractClientAdapter $clientAdapter
64
+ * @throws Exception\InvalidArgumentException
 
 
 
 
 
 
65
  */
66
+ public function __construct($analyticsAccountUid, $options = array(), Client\AbstractClientAdapter $clientAdapter = null)
67
+ {
68
+ if (empty($analyticsAccountUid)) {
69
+ throw new Exception\InvalidArgumentException('Google Account/Tracking ID not provided');
70
+ }
71
 
72
+ $this->analyticsAccountUid = $analyticsAccountUid;
 
 
 
 
 
73
 
74
+ if (!class_exists('Racecore\GATracking\Client\Adapter\Socket')) {
75
+ require_once( dirname(__FILE__) . '/Autoloader.php');
76
+ Autoloader::register(dirname(__FILE__).'/../../../src/');
77
+ }
 
 
78
 
79
+ if (!$clientAdapter) {
80
+ $clientAdapter = new Client\Adapter\Socket();
81
+ }
82
+ $this->setClientAdapter($clientAdapter);
 
 
83
 
84
+ if (!empty($options)) {
85
+ $this->setOptions(
86
+ array_merge($this->options, $options)
87
+ );
88
+ }
89
+ }
90
 
91
  /**
92
+ * Return Analytics Account ID
 
 
 
 
 
 
 
93
  *
94
+ * @return null
95
  */
96
+ public function getAnalyticsAccountUid()
 
 
 
 
 
 
 
97
  {
98
+ return $this->analyticsAccountUid;
99
  }
100
+
101
  /**
102
+ * Set the Analytics Account ID
103
  *
104
+ * @param null $analyticsAccountUid
105
  */
106
+ public function setAnalyticsAccountUid($analyticsAccountUid)
107
  {
108
+ $this->analyticsAccountUid = $analyticsAccountUid;
109
  }
110
 
111
  /**
112
+ * Get the current Client Adapter
113
  *
114
+ * @return Client\AbstractClientAdapter
115
  */
116
+ public function getClientAdapter()
117
  {
118
+ return $this->clientAdapter;
 
119
  }
120
 
121
  /**
122
+ * Set the current Client Adapter
123
  *
124
+ * @param Client\AbstractClientAdapter $adapter
 
125
  */
126
+ public function setClientAdapter(Client\AbstractClientAdapter $adapter)
127
  {
128
+ $this->clientAdapter = $adapter;
 
129
  }
130
 
131
  /**
132
+ * Set Options
133
  *
134
+ * @param $options
135
+ * @throws Exception\InvalidArgumentException
136
  */
137
+ public function setOptions($options)
138
  {
139
+ if (!is_array($options)) {
140
+ throw new Exception\InvalidArgumentException(sprintf(
141
+ '[%s] expects array; received [%s]',
142
+ __METHOD__,
143
+ gettype($options)
144
+ ));
145
  }
146
 
147
+ $this->options = $options;
 
 
 
 
 
 
 
 
 
 
 
 
148
  }
149
 
150
  /**
151
+ * Set single Option
152
  *
153
+ * @param $key
154
+ * @param $value
155
  */
156
+ public function setOption($key, $value)
157
  {
158
+ if (isset($this->options[$key]) && is_array($this->options[$key]) && is_array($value)) {
159
+ $oldValues = $this->options[$key];
160
+ $value = array_merge($oldValues, $value);
161
+ }
162
+
163
+ $this->options[$key] = $value;
164
  }
165
 
166
  /**
167
+ * Return Options
168
  *
169
  * @return array
170
  */
171
+ public function getOptions()
172
  {
173
+ return $this->options;
174
  }
175
 
176
  /**
177
+ * Return Single Option
178
  *
179
+ * @param $key
180
+ * @return null|mixed
181
  */
182
+ public function getOption($key)
183
  {
184
+ if (!isset($this->options[$key])) {
185
+ return null;
186
+ }
187
+
188
+ return $this->options[$key];
189
  }
190
 
191
  /**
192
+ * Sets the used clientId
193
  *
194
+ * @param $clientId
 
195
  */
196
+ public function setClientId($clientId)
197
  {
198
+ $this->setOption('client_id', $clientId);
 
 
 
199
  }
200
 
201
  /**
202
+ * Return the Current Client Id
203
  *
204
  * @return string
205
  */
206
+ public function getClientId()
207
  {
208
+ $clientId = $this->getOption('client_id');
209
+ if ($clientId) {
210
+ return $clientId;
211
+ }
212
+
213
  // collect user specific data
214
  if (isset($_COOKIE['_ga'])) {
 
215
  $gaCookie = explode('.', $_COOKIE['_ga']);
216
+ if (isset($gaCookie[2])) {
 
217
  // check if uuid
218
+ if ($this->checkUuid($gaCookie[2])) {
 
219
  // uuid set in cookie
220
  return $gaCookie[2];
221
+ } elseif (isset($gaCookie[2]) && isset($gaCookie[3])) {
222
+ // google old client id
 
 
223
  return $gaCookie[2] . '.' . $gaCookie[3];
224
  }
225
  }
226
  }
227
 
228
+ // nothing found - fallback
229
+ $generateClientId = $this->getOption('client_create_random_id');
230
+ if ($generateClientId) {
231
+ return $this->generateUuid();
232
+ }
233
+
234
+ return $this->getOption('client_fallback_id');
235
  }
236
 
237
  /**
240
  * @param $uuid
241
  * @return int
242
  */
243
+ final private function checkUuid($uuid)
244
  {
245
+ return preg_match(
246
+ '#^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$#i',
247
+ $uuid
248
+ );
249
  }
250
 
251
  /**
254
  * @author Andrew Moore http://www.php.net/manual/en/function.uniqid.php#94959
255
  * @return string
256
  */
257
+ final private function generateUuid()
258
+ {
259
+ return sprintf(
260
+ '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
261
  // 32 bits for "time_low"
262
+ mt_rand(0, 0xffff),
263
+ mt_rand(0, 0xffff),
264
  // 16 bits for "time_mid"
265
+ mt_rand(0, 0xffff),
 
266
  // 16 bits for "time_hi_and_version",
267
  // four most significant bits holds version number 4
268
+ mt_rand(0, 0x0fff) | 0x4000,
 
269
  // 16 bits, 8 bits for "clk_seq_hi_res",
270
  // 8 bits for "clk_seq_low",
271
  // two most significant bits holds zero and one for variant DCE1.1
272
+ mt_rand(0, 0x3fff) | 0x8000,
 
273
  // 48 bits for "node"
274
+ mt_rand(0, 0xffff),
275
+ mt_rand(0, 0xffff),
276
+ mt_rand(0, 0xffff)
277
  );
278
  }
279
 
280
  /**
281
+ * Build the Tracking Payload Data
 
282
  *
283
+ * @param Tracking\AbstractTracking $event
284
+ * @return array
285
+ * @throws Exception\MissingConfigurationException
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  */
287
+ protected function getTrackingPayloadData(Tracking\AbstractTracking $event)
288
  {
289
+ $payloadData = $event->getPackage();
290
+ $payloadData['v'] = $this->apiProtocolVersion; // protocol version
291
+ $payloadData['tid'] = $this->analyticsAccountUid; // account id
292
+ $payloadData['uid'] = $this->getOption('user_id');
293
+ $payloadData['cid'] = $this->getClientId();
294
+
295
+ $proxy = $this->getOption('proxy');
296
+ if ($proxy) {
297
+ if (!isset($proxy['ip'])) {
298
+ throw new Exception\MissingConfigurationException('proxy options need "ip" key/value');
299
+ }
300
 
301
+ if (isset($proxy['user_agent'])) {
302
+ $payloadData['ua'] = $proxy['user_agent'];
303
+ }
 
 
 
 
304
 
305
+ $payloadData['uip'] = $proxy['ip'];
 
 
 
 
306
  }
307
 
308
+ return array_filter($payloadData);
309
  }
310
 
311
  /**
312
+ * Call the client adapter
313
  *
314
+ * @param $tracking
315
+ * @throws Exception\InvalidArgumentException
316
  * @throws Exception\MissingConfigurationException
317
+ * @return Request\TrackingRequestCollection
318
  */
319
+ private function callEndpoint($tracking)
320
  {
321
+ $trackingHolder = is_array($tracking) ? $tracking : array($tracking);
322
+ $trackingCollection = new Request\TrackingRequestCollection();
323
 
324
+ foreach ($trackingHolder as $tracking) {
325
+ if (!$tracking instanceof Tracking\AbstractTracking) {
326
+ continue;
327
+ }
328
 
329
+ $payloadData = $this->getTrackingPayloadData($tracking);
 
 
 
 
 
 
 
 
 
 
 
 
 
330
 
331
+ $trackingRequest = new Request\TrackingRequest($payloadData);
332
+ $trackingCollection->add($trackingRequest);
333
+ }
334
 
335
+ $adapterOptions = $this->getOption('adapter');
336
+ $clientAdapter = $this->clientAdapter;
337
+ $clientAdapter->setOptions($adapterOptions);
338
 
339
+ return $clientAdapter->send($this->apiEndpointUrl, $trackingCollection);
 
 
 
 
 
 
 
 
 
 
 
340
  }
341
 
342
  /**
343
+ * Create a Tracking Class Instance - eg. "Event" or "Ecommerce\Transaction"
344
  *
345
+ * @param $className
346
+ * @param null $options
347
  * @return bool
 
348
  */
349
+ public function createTracking($className, $options = null)
350
  {
351
+ if (strstr(strtolower($className), 'abstracttracking')) {
352
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
353
  }
354
 
355
+ $class = 'Racecore\GATracking\Tracking\\' . $className;
356
+ if ($options) {
357
+ return new $class($options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  }
359
+ return new $class;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  }
361
 
362
  /**
363
+ * Send single tracking request
364
  *
365
+ * @param Tracking\AbstractTracking $tracking
366
+ * @return Tracking\AbstractTracking
367
  */
368
+ public function sendTracking(Tracking\AbstractTracking $tracking)
369
  {
370
+ $responseCollection = $this->callEndpoint($tracking);
371
+ $responseCollection->rewind();
372
+ return $responseCollection->current();
373
  }
374
 
375
  /**
376
+ * Send multiple tracking request
377
  *
378
+ * @param $array
379
+ * @return Request\TrackingRequestCollection
380
  */
381
+ public function sendMultipleTracking($array)
382
  {
383
+ return $this->callEndpoint($array);
 
 
384
  }
385
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Request/TrackingRequest.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Racecore\GATracking\Request;
4
+
5
+ use Racecore\GATracking\Tracking;
6
+
7
+ class TrackingRequest
8
+ {
9
+ private $payload = array();
10
+ private $responseHeader = array();
11
+
12
+ public function __construct(array $payload = array())
13
+ {
14
+ $this->payload = $payload;
15
+ }
16
+
17
+ /**
18
+ * @return array
19
+ */
20
+ public function getPayload()
21
+ {
22
+ return $this->payload;
23
+ }
24
+
25
+ /**
26
+ * @param array $payload
27
+ */
28
+ public function setPayload($payload)
29
+ {
30
+ $this->payload = $payload;
31
+ }
32
+
33
+ /**
34
+ * @return mixed
35
+ */
36
+ public function getResponseHeader()
37
+ {
38
+ return $this->responseHeader;
39
+ }
40
+
41
+ /**
42
+ * @param mixed $responseHeader
43
+ */
44
+ public function setResponseHeader($responseHeader)
45
+ {
46
+ $this->responseHeader = $responseHeader;
47
+ }
48
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Request/TrackingRequestCollection.php ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Racecore\GATracking\Request;
4
+
5
+ use Racecore\GATracking\Tracking;
6
+
7
+ class TrackingRequestCollection implements \Iterator
8
+ {
9
+ private $requestHolder = array();
10
+
11
+ public function add(TrackingRequest $request)
12
+ {
13
+ $this->requestHolder[] = $request;
14
+ }
15
+
16
+ public function addElements($array)
17
+ {
18
+ foreach ($array as $element) {
19
+ $this->add($element);
20
+ }
21
+ }
22
+
23
+ public function rewind()
24
+ {
25
+ reset($this->requestHolder);
26
+ }
27
+
28
+ /**
29
+ * {@inheritdoc}
30
+ */
31
+ public function current()
32
+ {
33
+ return current($this->requestHolder);
34
+ }
35
+
36
+ /**
37
+ * {@inheritdoc}
38
+ */
39
+ public function key()
40
+ {
41
+ return key($this->requestHolder);
42
+ }
43
+
44
+ /**
45
+ * {@inheritdoc}
46
+ */
47
+ public function next()
48
+ {
49
+ return next($this->requestHolder);
50
+ }
51
+
52
+ public function prev()
53
+ {
54
+ return prev($this->requestHolder);
55
+ }
56
+
57
+ public function getIterator()
58
+ {
59
+ $this->rewind();
60
+ return $this;
61
+ }
62
+
63
+ public function valid()
64
+ {
65
+ return (bool) $this->current();
66
+ }
67
+
68
+ public function count()
69
+ {
70
+ return count($this->requestHolder);
71
+ }
72
+
73
+ public function indexOf($element)
74
+ {
75
+ return array_search($element, $this->requestHolder);
76
+ }
77
+
78
+ public function removeElement($element)
79
+ {
80
+ $key = $this->indexOf($element);
81
+ if ($key) {
82
+ unset($this->requestHolder[$key]);
83
+ return true;
84
+ }
85
+ return false;
86
+ }
87
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/AbstractTracking.php CHANGED
@@ -1,685 +1,508 @@
1
- <?php
2
- namespace Racecore\GATracking\Tracking;
3
-
4
- /**
5
- * Google Analytics Measurement PHP Class
6
- * Licensed under the 3-clause BSD License.
7
- * This source file is subject to the 3-clause BSD License that is
8
- * bundled with this package in the LICENSE file. It is also available at
9
- * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
10
- *
11
- * Google Documentation
12
- * https://developers.google.com/analytics/devguides/collection/protocol/v1/
13
- *
14
- * @author Marco Rieger
15
- * @email Rieger(at)racecore.de
16
- * @git https://github.com/ins0
17
- * @url http://www.racecore.de
18
- * @package Racecore\GATracking\Tracking
19
- */
20
- abstract class AbstractTracking
21
- {
22
- // document referrer
23
- /** @var String */
24
- private $documentReferrer;
25
-
26
- // campaign
27
- /** @var String */
28
- private $campaignName, $campaignSource, $campaignMedium, $campaignContent, $campaignID, $campaignKeyword;
29
-
30
- // adwords id
31
- /** @var String */
32
- private $adwordsID;
33
-
34
- // display ads id
35
- /** @var String */
36
- private $displayAdsID;
37
-
38
- // screen resolution
39
- /** @var String */
40
- private $screenResolution;
41
-
42
- // viewport size
43
- /** @var String */
44
- private $viewportSize;
45
-
46
- // document encoding
47
- /** @var String */
48
- private $documentEncoding;
49
-
50
- // screen colors
51
- /** @var String */
52
- private $screenColors;
53
-
54
- // user language
55
- /** @var String */
56
- private $userLanguage;
57
-
58
- // java enabled
59
- /** @var boolean|string */
60
- private $javaEnabled = null;
61
-
62
- // flash version
63
- /** @var String */
64
- private $flashVersion;
65
-
66
- // document location
67
- /** @var String */
68
- private $documentLocation;
69
-
70
- // document host
71
- /** @var String */
72
- private $documentHost;
73
-
74
- // document path
75
- /** @var String */
76
- private $documentPath;
77
-
78
- // document title
79
- /** @var String */
80
- private $documentTitle;
81
-
82
- // app name
83
- /** @var String */
84
- private $appName;
85
-
86
- // app version
87
- /** @var String */
88
- private $appVersion;
89
-
90
- // experiment id
91
- /** @var String */
92
- private $experimentID;
93
-
94
- // experiment variant
95
- /** @var String */
96
- private $experimentVariant;
97
-
98
- // content description
99
- /** @var String */
100
- private $contentDescription;
101
-
102
- // link id
103
- /** @var String */
104
- private $linkID;
105
-
106
- // custom dimensions
107
- /** @var Array */
108
- private $customDimension = array();
109
-
110
- // custom metric
111
- /** @var Array */
112
- private $customMetric = array();
113
-
114
- // productId
115
- /** @var string */
116
- private $productId;
117
-
118
- /**
119
- * Get the transfer Paket from current Event
120
- *
121
- * @return array
122
- */
123
- abstract public function createPackage();
124
-
125
- /**
126
- * Returns the Paket for Event Tracking
127
- *
128
- * @return array
129
- * @throws \Racecore\GATracking\Exception\MissingTrackingParameterException
130
- * @deprecated
131
- */
132
- public function getPaket()
133
- {
134
- return $this->createPackage();
135
- }
136
-
137
- /**
138
- * @return array
139
- */
140
- public function getPackage()
141
- {
142
- $package = array_merge($this->createPackage(), array(
143
- // campaign
144
- 'cn' => $this->getCampaignName(),
145
- 'cs' => $this->getCampaignSource(),
146
- 'cm' => $this->getCampaignMedium(),
147
- 'ck' => $this->getCampaignKeyword(),
148
- 'cc' => $this->getCampaignContent(),
149
- 'ci' => $this->getCampaignID(),
150
-
151
- // other
152
- 'dr' => $this->getDocumentReferrer(),
153
- 'gclid' => $this->getAdwordsID(),
154
- 'dclid' => $this->getDisplayAdsID(),
155
-
156
- // system info
157
- 'sr' => $this->getScreenResolution(),
158
- 'sd' => $this->getScreenColors(),
159
- 'vp' => $this->getViewportSize(),
160
- 'de' => $this->getDocumentEncoding(),
161
- 'ul' => $this->getUserLanguage(),
162
- 'je' => $this->getJavaEnabled(),
163
- 'fl' => $this->getFlashVersion(),
164
-
165
- // Content Information
166
- 'dl' => $this->getDocumentLocation(),
167
- 'dh' => $this->getDocumentHost(),
168
- 'dp' => $this->getDocumentPath(),
169
- 'dt' => $this->getDocumentTitle(),
170
- 'cd' => $this->getContentDescription(),
171
- 'linkid' => $this->getLinkID(),
172
-
173
- // app tracking
174
- 'an' => $this->getAppName(),
175
- 'av' => $this->getAppVersion(),
176
-
177
- // enhanced e-commerce
178
-
179
-
180
-
181
- // content experiments
182
- 'xid' => $this->getExperimentID(),
183
- 'xvar' => $this->getExperimentVariant(),
184
- ));
185
-
186
- $package = $this->addCustomParameters($package);
187
-
188
- // remove all unused
189
- $package = array_filter($package, 'strlen');
190
-
191
- return $package;
192
- }
193
-
194
- /**
195
- * @param array $package
196
- * @return array
197
- */
198
- private function addCustomParameters( Array $package )
199
- {
200
- // add custom metric params
201
- foreach( $this->customMetric as $id => $value )
202
- {
203
- $package['cm' . (int) $id ] = $value;
204
- }
205
-
206
- // add custom dimension params
207
- foreach( $this->customDimension as $id => $value )
208
- {
209
- $package['cd' . (int) $id ] = $value;
210
- }
211
-
212
- return $package;
213
- }
214
-
215
- /**
216
- * @param null $id
217
- * @param $value
218
- */
219
- public function setCustomDimension($id = null, $value)
220
- {
221
- $this->customDimension[$id] = $value;
222
- }
223
-
224
- /**
225
- * @param null $id
226
- * @param $value
227
- */
228
- public function setCustomMetric($id = null, $value)
229
- {
230
- $this->customMetric[$id] = $value;
231
- }
232
-
233
- /**
234
- * @param String $contentDescription
235
- */
236
- public function setContentDescription($contentDescription)
237
- {
238
- $this->contentDescription = $contentDescription;
239
- }
240
-
241
- /**
242
- * @return String
243
- */
244
- public function getContentDescription()
245
- {
246
- return $this->contentDescription;
247
- }
248
-
249
- /**
250
- * @param String $linkID
251
- */
252
- public function setLinkID($linkID)
253
- {
254
- $this->linkID = $linkID;
255
- }
256
-
257
- /**
258
- * @return String
259
- */
260
- public function getLinkID()
261
- {
262
- return $this->linkID;
263
- }
264
-
265
- /**
266
- * @param String $adwordsID
267
- */
268
- public function setAdwordsID($adwordsID)
269
- {
270
- $this->adwordsID = $adwordsID;
271
- }
272
-
273
- /**
274
- * @return String
275
- */
276
- public function getAdwordsID()
277
- {
278
- return $this->adwordsID;
279
- }
280
-
281
- /**
282
- * @param String $appName
283
- */
284
- public function setAppName($appName)
285
- {
286
- $this->appName = $appName;
287
- }
288
-
289
- /**
290
- * @return String
291
- */
292
- public function getAppName()
293
- {
294
- return $this->appName;
295
- }
296
-
297
- /**
298
- * @param String $appVersion
299
- */
300
- public function setAppVersion($appVersion)
301
- {
302
- $this->appVersion = $appVersion;
303
- }
304
-
305
- /**
306
- * @return String
307
- */
308
- public function getAppVersion()
309
- {
310
- return $this->appVersion;
311
- }
312
-
313
- /**
314
- * @param String $campaignContent
315
- */
316
- public function setCampaignContent($campaignContent)
317
- {
318
- $this->campaignContent = $campaignContent;
319
- }
320
-
321
- /**
322
- * @return String
323
- */
324
- public function getCampaignContent()
325
- {
326
- return $this->campaignContent;
327
- }
328
-
329
- /**
330
- * @param String $campaignID
331
- */
332
- public function setCampaignID($campaignID)
333
- {
334
- $this->campaignID = $campaignID;
335
- }
336
-
337
- /**
338
- * @return String
339
- */
340
- public function getCampaignID()
341
- {
342
- return $this->campaignID;
343
- }
344
-
345
- /**
346
- * @param String $campaignKeyword
347
- */
348
- public function setCampaignKeyword($campaignKeyword)
349
- {
350
- $this->campaignKeyword = $campaignKeyword;
351
- }
352
-
353
- /**
354
- * @deprecated Use setCampaignKeyword
355
- * @param $campaignKeyword
356
- */
357
- public function setCampaignKeywords($campaignKeyword)
358
- {
359
- if( is_array($campaignKeyword) )
360
- {
361
- return $this->setCampaignKeyword(implode(',', $campaignKeyword));
362
- }
363
-
364
- $this->setCampaignKeyword($campaignKeyword);
365
- }
366
-
367
- /**
368
- * @return Array
369
- */
370
- public function getCampaignKeyword()
371
- {
372
- return $this->campaignKeyword;
373
- }
374
-
375
- /**
376
- * @param String $campaignMedium
377
- */
378
- public function setCampaignMedium($campaignMedium)
379
- {
380
- $this->campaignMedium = $campaignMedium;
381
- }
382
-
383
- /**
384
- * @return String
385
- */
386
- public function getCampaignMedium()
387
- {
388
- return $this->campaignMedium;
389
- }
390
-
391
- /**
392
- * @param String $campaignName
393
- */
394
- public function setCampaignName($campaignName)
395
- {
396
- $this->campaignName = $campaignName;
397
- }
398
-
399
- /**
400
- * @return String
401
- */
402
- public function getCampaignName()
403
- {
404
- return $this->campaignName;
405
- }
406
-
407
- /**
408
- * @param String $campaignSource
409
- */
410
- public function setCampaignSource($campaignSource)
411
- {
412
- $this->campaignSource = $campaignSource;
413
- }
414
-
415
- /**
416
- * @return String
417
- */
418
- public function getCampaignSource()
419
- {
420
- return $this->campaignSource;
421
- }
422
-
423
- /**
424
- * @param String $displayAdsID
425
- */
426
- public function setDisplayAdsID($displayAdsID)
427
- {
428
- $this->displayAdsID = $displayAdsID;
429
- }
430
-
431
- /**
432
- * @return String
433
- */
434
- public function getDisplayAdsID()
435
- {
436
- return $this->displayAdsID;
437
- }
438
-
439
- /**
440
- * @param String $documentEncoding
441
- */
442
- public function setDocumentEncoding($documentEncoding)
443
- {
444
- $this->documentEncoding = $documentEncoding;
445
- }
446
-
447
- /**
448
- * @return String
449
- */
450
- public function getDocumentEncoding()
451
- {
452
- return $this->documentEncoding;
453
- }
454
-
455
- /**
456
- * @param String $documentHost
457
- */
458
- public function setDocumentHost($documentHost)
459
- {
460
- $this->documentHost = $documentHost;
461
- }
462
-
463
- /**
464
- * @return String
465
- */
466
- public function getDocumentHost()
467
- {
468
- return $this->documentHost;
469
- }
470
-
471
- /**
472
- * @param String $documentLocation
473
- */
474
- public function setDocumentLocation($documentLocation)
475
- {
476
- $this->documentLocation = $documentLocation;
477
- }
478
-
479
- /**
480
- * @return String
481
- */
482
- public function getDocumentLocation()
483
- {
484
- return $this->documentLocation;
485
- }
486
-
487
- /**
488
- * @param String $documentPath
489
- */
490
- public function setDocumentPath($documentPath)
491
- {
492
- $this->documentPath = $documentPath;
493
- }
494
-
495
- /**
496
- * @return String
497
- */
498
- public function getDocumentPath()
499
- {
500
- return $this->documentPath;
501
- }
502
-
503
- /**
504
- * @param String $documentReferrer
505
- */
506
- public function setDocumentReferrer($documentReferrer)
507
- {
508
- $this->documentReferrer = $documentReferrer;
509
- }
510
-
511
- /**
512
- * @return String
513
- */
514
- public function getDocumentReferrer()
515
- {
516
- return $this->documentReferrer;
517
- }
518
-
519
- /**
520
- * @param String $documentTitle
521
- */
522
- public function setDocumentTitle($documentTitle)
523
- {
524
- $this->documentTitle = $documentTitle;
525
- }
526
-
527
- /**
528
- * @return String
529
- */
530
- public function getDocumentTitle()
531
- {
532
- return $this->documentTitle;
533
- }
534
-
535
- /**
536
- * @param String $experimentID
537
- */
538
- public function setExperimentID($experimentID)
539
- {
540
- $this->experimentID = $experimentID;
541
- }
542
-
543
- /**
544
- * @return String
545
- */
546
- public function getExperimentID()
547
- {
548
- return $this->experimentID;
549
- }
550
-
551
- /**
552
- * @param String $experimentVariant
553
- */
554
- public function setExperimentVariant($experimentVariant)
555
- {
556
- $this->experimentVariant = $experimentVariant;
557
- }
558
-
559
- /**
560
- * @return String
561
- */
562
- public function getExperimentVariant()
563
- {
564
- return $this->experimentVariant;
565
- }
566
-
567
- /**
568
- * @param String $flashVersion
569
- */
570
- public function setFlashVersion($flashVersion)
571
- {
572
- $this->flashVersion = $flashVersion;
573
- }
574
-
575
- /**
576
- * @return String
577
- */
578
- public function getFlashVersion()
579
- {
580
- return $this->flashVersion;
581
- }
582
-
583
- /**
584
- * @param boolean $javaEnabled
585
- */
586
- public function setJavaEnabled($javaEnabled)
587
- {
588
- $this->javaEnabled = (bool) $javaEnabled;
589
- }
590
-
591
- /**
592
- * @return boolean
593
- */
594
- public function getJavaEnabled()
595
- {
596
- if( $this->javaEnabled === null ){
597
- return null;
598
- }
599
-
600
- return $this->javaEnabled ? '1' : '0';
601
- }
602
-
603
- /**
604
- * @param String $screenColors
605
- */
606
- public function setScreenColors($screenColors)
607
- {
608
- $this->screenColors = $screenColors;
609
- }
610
-
611
- /**
612
- * @return String
613
- */
614
- public function getScreenColors()
615
- {
616
- return $this->screenColors;
617
- }
618
-
619
- /**
620
- * @param $width
621
- * @param $height
622
- */
623
- public function setScreenResolution($width, $height)
624
- {
625
- $this->screenResolution = $width . 'x' . $height;
626
- }
627
-
628
- /**
629
- * @return String
630
- */
631
- public function getScreenResolution()
632
- {
633
- return $this->screenResolution;
634
- }
635
-
636
- /**
637
- * @param String $userLanguage
638
- */
639
- public function setUserLanguage($userLanguage)
640
- {
641
- $this->userLanguage = $userLanguage;
642
- }
643
-
644
- /**
645
- * @return String
646
- */
647
- public function getUserLanguage()
648
- {
649
- return $this->userLanguage;
650
- }
651
-
652
- /**
653
- * @param $width
654
- * @param $height
655
- */
656
- public function setViewportSize($width, $height)
657
- {
658
- $this->viewportSize = $width . 'x' . $height;
659
- }
660
-
661
- /**
662
- * @return String
663
- */
664
- public function getViewportSize()
665
- {
666
- return $this->viewportSize;
667
- }
668
-
669
- /**
670
- * @param string $productId
671
- */
672
- public function setProductId($productId)
673
- {
674
- $this->productId = $productId;
675
- }
676
-
677
- /**
678
- * @return string
679
- */
680
- public function getProductId()
681
- {
682
- return $this->productId;
683
- }
684
-
685
- }
1
+ <?php
2
+
3
+ namespace Racecore\GATracking\Tracking;
4
+
5
+ use Racecore\GATracking\Exception;
6
+
7
+ /**
8
+ * Google Analytics Measurement PHP Class
9
+ * Licensed under the 3-clause BSD License.
10
+ * This source file is subject to the 3-clause BSD License that is
11
+ * bundled with this package in the LICENSE file. It is also available at
12
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
13
+ *
14
+ * Google Documentation
15
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
16
+ *
17
+ * @author Marco Rieger
18
+ * @email Rieger(at)racecore.de
19
+ * @git https://github.com/ins0
20
+ * @url http://www.racecore.de
21
+ * @package Racecore\GATracking\Tracking
22
+ */
23
+ abstract class AbstractTracking
24
+ {
25
+ // document referrer
26
+ /** @var String */
27
+ private $documentReferrer;
28
+
29
+ // campaign
30
+ /** @var String */
31
+ private $campaignName;
32
+ private $campaignSource;
33
+ private $campaignMedium;
34
+ private $campaignContent;
35
+ private $campaignID;
36
+ private $campaignKeyword;
37
+
38
+ // adwords id
39
+ /** @var String */
40
+ private $adwordsID;
41
+
42
+ // display ads id
43
+ /** @var String */
44
+ private $displayAdsID;
45
+
46
+ // screen resolution
47
+ /** @var String */
48
+ private $screenResolution;
49
+
50
+ // viewport size
51
+ /** @var String */
52
+ private $viewportSize;
53
+
54
+ // document encoding
55
+ /** @var String */
56
+ private $documentEncoding;
57
+
58
+ // screen colors
59
+ /** @var String */
60
+ private $screenColors;
61
+
62
+ // user language
63
+ /** @var String */
64
+ private $userLanguage;
65
+
66
+ // java enabled
67
+ /** @var boolean|string */
68
+ private $javaEnabled = null;
69
+
70
+ // flash version
71
+ /** @var String */
72
+ private $flashVersion;
73
+
74
+ // document location
75
+ /** @var String */
76
+ private $documentLocation;
77
+
78
+ // document host
79
+ /** @var String */
80
+ private $documentHost;
81
+
82
+ // document path
83
+ /** @var String */
84
+ private $documentPath;
85
+
86
+ // document title
87
+ /** @var String */
88
+ private $documentTitle;
89
+
90
+ // app name
91
+ /** @var String */
92
+ private $appName;
93
+
94
+ // app version
95
+ /** @var String */
96
+ private $appVersion;
97
+
98
+ // experiment id
99
+ /** @var String */
100
+ private $experimentID;
101
+
102
+ // experiment variant
103
+ /** @var String */
104
+ private $experimentVariant;
105
+
106
+ // content description
107
+ /** @var String */
108
+ private $contentDescription;
109
+
110
+ // link id
111
+ /** @var String */
112
+ private $linkID;
113
+
114
+ // custom dimensions
115
+ /** @var Array */
116
+ private $customDimension = array();
117
+
118
+ // custom metric
119
+ /** @var Array */
120
+ private $customMetric = array();
121
+
122
+ // productId
123
+ /** @var string */
124
+ private $productId;
125
+
126
+ // non interactive hit
127
+ private $nonInteractionHit = false;
128
+
129
+ private $customPayload = array();
130
+
131
+ // event queue time difference
132
+ private $queueTime;
133
+
134
+ /**
135
+ * Add Custom Tracking Payload Data send to Google
136
+ * @param $key
137
+ * @param $value
138
+ * @throws Exception\InvalidArgumentException
139
+ */
140
+ public function addCustomPayloadData($key, $value)
141
+ {
142
+ if (!is_string($value)) {
143
+ throw new Exception\InvalidArgumentException('Custom payload data value must be a string');
144
+ }
145
+
146
+ $this->customPayload[$key] = $value;
147
+ }
148
+
149
+ /**
150
+ * Get the transfer Paket from current Event
151
+ *
152
+ * @return array
153
+ */
154
+ abstract public function createPackage();
155
+
156
+ /**
157
+ * @return array
158
+ */
159
+ public function getPackage()
160
+ {
161
+ $package = array_merge($this->createPackage(), array(
162
+ // campaign
163
+ 'cn' => $this->campaignName,
164
+ 'cs' => $this->campaignSource,
165
+ 'cm' => $this->campaignMedium,
166
+ 'ck' => $this->campaignKeyword,
167
+ 'cc' => $this->campaignContent,
168
+ 'ci' => $this->campaignID,
169
+
170
+ // other
171
+ 'dr' => $this->documentReferrer,
172
+ 'gclid' => $this->adwordsID,
173
+ 'dclid' => $this->displayAdsID,
174
+
175
+ // system info
176
+ 'sr' => $this->screenResolution,
177
+ 'sd' => $this->screenColors,
178
+ 'vp' => $this->viewportSize,
179
+ 'de' => $this->documentEncoding,
180
+ 'ul' => $this->userLanguage,
181
+ 'je' => $this->javaEnabled,
182
+ 'fl' => $this->flashVersion,
183
+
184
+ // Content Information
185
+ 'dl' => $this->documentLocation,
186
+ 'dh' => $this->documentHost,
187
+ 'dp' => $this->documentPath,
188
+ 'dt' => $this->documentTitle,
189
+ 'cd' => $this->contentDescription,
190
+ 'linkid' => $this->linkID,
191
+
192
+ // app tracking
193
+ 'an' => $this->appName,
194
+ 'av' => $this->appVersion,
195
+
196
+ // non interactive hit
197
+ 'ni' => $this->nonInteractionHit,
198
+
199
+ // content experiments
200
+ 'xid' => $this->experimentID,
201
+ 'xvar' => $this->experimentVariant,
202
+
203
+ // optional
204
+ 'qt' => $this->queueTime,
205
+ ));
206
+
207
+ $package = $this->addCustomParameters($package);
208
+
209
+ // custom payload data
210
+ $package = array_merge($package, $this->customPayload);
211
+
212
+ // remove all unused
213
+ $package = array_filter($package, 'strlen');
214
+
215
+ return $package;
216
+ }
217
+
218
+ /**
219
+ * Set the Tracking Processing Time to pass the qt param within this tracking request
220
+ * ATTENTION!: Values greater than four hours may lead to hits not being processed.
221
+ *
222
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#qt
223
+ *
224
+ * @param $milliseconds
225
+ */
226
+ public function setQueueTime($milliseconds)
227
+ {
228
+ $this->queueTime = $milliseconds;
229
+ }
230
+
231
+ /**
232
+ * Mark the Hit as Non Interactive
233
+ *
234
+ * @param $bool
235
+ */
236
+ public function setAsNonInteractionHit($bool)
237
+ {
238
+ $this->nonInteractionHit = (bool) $bool;
239
+ }
240
+
241
+ /**
242
+ * @param array $package
243
+ * @return array
244
+ */
245
+ private function addCustomParameters($package)
246
+ {
247
+ // add custom metric params
248
+ foreach ($this->customMetric as $id => $value) {
249
+ $package['cm' . (int) $id ] = $value;
250
+ }
251
+
252
+ // add custom dimension params
253
+ foreach ($this->customDimension as $id => $value) {
254
+ $package['cd' . (int) $id ] = $value;
255
+ }
256
+
257
+ return $package;
258
+ }
259
+
260
+ /**
261
+ * @param null $identifier
262
+ * @param $value
263
+ */
264
+ public function setCustomDimension($value, $identifier = null)
265
+ {
266
+ $this->customDimension[$identifier] = $value;
267
+ }
268
+
269
+ /**
270
+ * @param null $identifier
271
+ * @param $value
272
+ */
273
+ public function setCustomMetric($value, $identifier = null)
274
+ {
275
+ $this->customMetric[$identifier] = $value;
276
+ }
277
+
278
+ /**
279
+ * @param String $contentDescription
280
+ */
281
+ public function setContentDescription($contentDescription)
282
+ {
283
+ $this->contentDescription = $contentDescription;
284
+ }
285
+
286
+ /**
287
+ * @param String $linkID
288
+ */
289
+ public function setLinkID($linkID)
290
+ {
291
+ $this->linkID = $linkID;
292
+ }
293
+
294
+ /**
295
+ * @param String $adwordsID
296
+ */
297
+ public function setAdwordsID($adwordsID)
298
+ {
299
+ $this->adwordsID = $adwordsID;
300
+ }
301
+
302
+ /**
303
+ * @param String $appName
304
+ */
305
+ public function setAppName($appName)
306
+ {
307
+ $this->appName = $appName;
308
+ }
309
+
310
+ /**
311
+ * @param String $appVersion
312
+ */
313
+ public function setAppVersion($appVersion)
314
+ {
315
+ $this->appVersion = $appVersion;
316
+ }
317
+
318
+ /**
319
+ * @param String $campaignContent
320
+ */
321
+ public function setCampaignContent($campaignContent)
322
+ {
323
+ $this->campaignContent = $campaignContent;
324
+ }
325
+
326
+ /**
327
+ * @param String $campaignID
328
+ */
329
+ public function setCampaignID($campaignID)
330
+ {
331
+ $this->campaignID = $campaignID;
332
+ }
333
+
334
+ /**
335
+ * @param String $campaignKeyword
336
+ */
337
+ public function setCampaignKeyword($campaignKeyword)
338
+ {
339
+ $this->campaignKeyword = $campaignKeyword;
340
+ }
341
+
342
+ /**
343
+ * @deprecated Use setCampaignKeyword
344
+ * @param $campaignKeyword
345
+ */
346
+ public function setCampaignKeywords($campaignKeyword)
347
+ {
348
+ if (is_array($campaignKeyword)) {
349
+ $campaignKeyword = implode(',', $campaignKeyword);
350
+ }
351
+
352
+ $this->setCampaignKeyword($campaignKeyword);
353
+ }
354
+
355
+ /**
356
+ * @param String $campaignMedium
357
+ */
358
+ public function setCampaignMedium($campaignMedium)
359
+ {
360
+ $this->campaignMedium = $campaignMedium;
361
+ }
362
+
363
+ /**
364
+ * @param String $campaignName
365
+ */
366
+ public function setCampaignName($campaignName)
367
+ {
368
+ $this->campaignName = $campaignName;
369
+ }
370
+
371
+ /**
372
+ * @param String $campaignSource
373
+ */
374
+ public function setCampaignSource($campaignSource)
375
+ {
376
+ $this->campaignSource = $campaignSource;
377
+ }
378
+
379
+ /**
380
+ * @param String $displayAdsID
381
+ */
382
+ public function setDisplayAdsID($displayAdsID)
383
+ {
384
+ $this->displayAdsID = $displayAdsID;
385
+ }
386
+
387
+ /**
388
+ * @param String $documentEncoding
389
+ */
390
+ public function setDocumentEncoding($documentEncoding)
391
+ {
392
+ $this->documentEncoding = $documentEncoding;
393
+ }
394
+
395
+ /**
396
+ * @param String $documentHost
397
+ */
398
+ public function setDocumentHost($documentHost)
399
+ {
400
+ $this->documentHost = $documentHost;
401
+ }
402
+
403
+ /**
404
+ * @param String $documentLocation
405
+ */
406
+ public function setDocumentLocation($documentLocation)
407
+ {
408
+ $this->documentLocation = $documentLocation;
409
+ }
410
+
411
+ /**
412
+ * @param String $documentPath
413
+ */
414
+ public function setDocumentPath($documentPath)
415
+ {
416
+ $this->documentPath = $documentPath;
417
+ }
418
+
419
+ /**
420
+ * @param String $documentReferrer
421
+ */
422
+ public function setDocumentReferrer($documentReferrer)
423
+ {
424
+ $this->documentReferrer = $documentReferrer;
425
+ }
426
+
427
+ /**
428
+ * @param String $documentTitle
429
+ */
430
+ public function setDocumentTitle($documentTitle)
431
+ {
432
+ $this->documentTitle = $documentTitle;
433
+ }
434
+
435
+ /**
436
+ * @param String $experimentID
437
+ */
438
+ public function setExperimentID($experimentID)
439
+ {
440
+ $this->experimentID = $experimentID;
441
+ }
442
+
443
+ /**
444
+ * @param String $experimentVariant
445
+ */
446
+ public function setExperimentVariant($experimentVariant)
447
+ {
448
+ $this->experimentVariant = $experimentVariant;
449
+ }
450
+
451
+ /**
452
+ * @param String $flashVersion
453
+ */
454
+ public function setFlashVersion($flashVersion)
455
+ {
456
+ $this->flashVersion = $flashVersion;
457
+ }
458
+
459
+ /**
460
+ * @param boolean $javaEnabled
461
+ */
462
+ public function setJavaEnabled($javaEnabled)
463
+ {
464
+ $this->javaEnabled = (bool) $javaEnabled;
465
+ }
466
+
467
+ /**
468
+ * @param String $screenColors
469
+ */
470
+ public function setScreenColors($screenColors)
471
+ {
472
+ $this->screenColors = $screenColors;
473
+ }
474
+
475
+ /**
476
+ * @param $width
477
+ * @param $height
478
+ */
479
+ public function setScreenResolution($width, $height)
480
+ {
481
+ $this->screenResolution = $width . 'x' . $height;
482
+ }
483
+
484
+ /**
485
+ * @param String $userLanguage
486
+ */
487
+ public function setUserLanguage($userLanguage)
488
+ {
489
+ $this->userLanguage = $userLanguage;
490
+ }
491
+
492
+ /**
493
+ * @param $width
494
+ * @param $height
495
+ */
496
+ public function setViewportSize($width, $height)
497
+ {
498
+ $this->viewportSize = $width . 'x' . $height;
499
+ }
500
+
501
+ /**
502
+ * @param string $productId
503
+ */
504
+ public function setProductId($productId)
505
+ {
506
+ $this->productId = $productId;
507
+ }
508
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/App/Event.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Tracking\App;
3
 
4
  use Racecore\GATracking\Tracking\Event as DefaultEvent;
@@ -21,4 +22,4 @@ use Racecore\GATracking\Tracking\Event as DefaultEvent;
21
  */
22
  class Event extends DefaultEvent
23
  {
24
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Tracking\App;
4
 
5
  use Racecore\GATracking\Tracking\Event as DefaultEvent;
22
  */
23
  class Event extends DefaultEvent
24
  {
25
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/App/Screen.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Tracking\App;
3
 
4
  use Racecore\GATracking\Tracking\AbstractTracking;
@@ -32,4 +33,4 @@ class Screen extends AbstractTracking
32
  't' => 'appview',
33
  );
34
  }
35
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Tracking\App;
4
 
5
  use Racecore\GATracking\Tracking\AbstractTracking;
33
  't' => 'appview',
34
  );
35
  }
36
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Ecommerce/Item.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Tracking\Ecommerce;
3
 
4
  use Racecore\GATracking\Exception\MissingTrackingParameterException;
@@ -31,15 +32,6 @@ class Item extends AbstractTracking
31
  private $category = '';
32
  private $currency = '';
33
 
34
- /**
35
- * @param $host
36
- * @deprecated
37
- */
38
- public function setTransactionHost( $host )
39
- {
40
- return $this->setDocumentHost( $host );
41
- }
42
-
43
  /**
44
  * Set the Transaction ID
45
  *
@@ -200,13 +192,11 @@ class Item extends AbstractTracking
200
  */
201
  public function createPackage()
202
  {
203
- if( !$this->getTransactionID() )
204
- {
205
  throw new MissingTrackingParameterException('transaction id is missing');
206
  }
207
 
208
- if( !$this->getName() )
209
- {
210
  throw new MissingTrackingParameterException('item name is missing');
211
  }
212
 
@@ -221,5 +211,4 @@ class Item extends AbstractTracking
221
  'cu' => $this->getCurrency()
222
  );
223
  }
224
-
225
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Tracking\Ecommerce;
4
 
5
  use Racecore\GATracking\Exception\MissingTrackingParameterException;
32
  private $category = '';
33
  private $currency = '';
34
 
 
 
 
 
 
 
 
 
 
35
  /**
36
  * Set the Transaction ID
37
  *
192
  */
193
  public function createPackage()
194
  {
195
+ if (!$this->getTransactionID()) {
 
196
  throw new MissingTrackingParameterException('transaction id is missing');
197
  }
198
 
199
+ if (!$this->getName()) {
 
200
  throw new MissingTrackingParameterException('item name is missing');
201
  }
202
 
211
  'cu' => $this->getCurrency()
212
  );
213
  }
214
+ }
 
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Ecommerce/Transaction.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Tracking\Ecommerce;
3
 
4
  use Racecore\GATracking\Exception\MissingTrackingParameterException;
@@ -34,9 +35,9 @@ class Transaction extends AbstractTracking
34
  * @param $host
35
  * @deprecated
36
  */
37
- public function setTransactionHost( $host )
38
  {
39
- return $this->setDocumentHost( $host );
40
  }
41
 
42
  /**
@@ -46,7 +47,6 @@ class Transaction extends AbstractTracking
46
  */
47
  public function setID($id)
48
  {
49
-
50
  $this->id = $id;
51
  }
52
 
@@ -175,8 +175,7 @@ class Transaction extends AbstractTracking
175
  */
176
  public function createPackage()
177
  {
178
- if( !$this->getID() )
179
- {
180
  throw new MissingTrackingParameterException('transaction id is missing');
181
  }
182
 
@@ -190,5 +189,4 @@ class Transaction extends AbstractTracking
190
  'cu' => $this->getCurrency()
191
  );
192
  }
193
-
194
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Tracking\Ecommerce;
4
 
5
  use Racecore\GATracking\Exception\MissingTrackingParameterException;
35
  * @param $host
36
  * @deprecated
37
  */
38
+ public function setTransactionHost($host)
39
  {
40
+ return $this->setDocumentHost($host);
41
  }
42
 
43
  /**
47
  */
48
  public function setID($id)
49
  {
 
50
  $this->id = $id;
51
  }
52
 
175
  */
176
  public function createPackage()
177
  {
178
+ if (!$this->getID()) {
 
179
  throw new MissingTrackingParameterException('transaction id is missing');
180
  }
181
 
189
  'cu' => $this->getCurrency()
190
  );
191
  }
192
+ }
 
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Event.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Tracking;
3
 
4
  use Racecore\GATracking\Exception\MissingTrackingParameterException;
@@ -145,4 +146,4 @@ class Event extends AbstractTracking
145
  'ev' => $this->getEventValue()
146
  );
147
  }
148
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Tracking;
4
 
5
  use Racecore\GATracking\Exception\MissingTrackingParameterException;
146
  'ev' => $this->getEventValue()
147
  );
148
  }
149
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Exception.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Tracking;
3
 
4
  /**
@@ -82,4 +83,4 @@ class Exception extends AbstractTracking
82
  'exf' => ( $this->getExceptionFatal() ? '1' : '0' )
83
  );
84
  }
85
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Tracking;
4
 
5
  /**
83
  'exf' => ( $this->getExceptionFatal() ? '1' : '0' )
84
  );
85
  }
86
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Factory.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace Racecore\GATracking\Tracking;
4
+
5
+ /**
6
+ * Google Analytics Measurement PHP Class
7
+ * Licensed under the 3-clause BSD License.
8
+ * This source file is subject to the 3-clause BSD License that is
9
+ * bundled with this package in the LICENSE file. It is also available at
10
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
11
+ *
12
+ * Google Documentation
13
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
14
+ *
15
+ * @author Marco Rieger
16
+ * @email Rieger(at)racecore.de
17
+ * @git https://github.com/ins0
18
+ * @url http://www.racecore.de
19
+ * @package Racecore\GATracking\Tracking
20
+ */
21
+ class Factory extends AbstractTracking
22
+ {
23
+ private $payload = array();
24
+
25
+ public function __construct($payload)
26
+ {
27
+ $this->payload = $payload;
28
+ }
29
+
30
+ public function createPackage()
31
+ {
32
+ // nothing
33
+ }
34
+
35
+ /**
36
+ * Returns the payload for a custom tracking package
37
+ * @return array
38
+ */
39
+ public function getPackage()
40
+ {
41
+ return $this->payload;
42
+ }
43
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Page.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Tracking;
3
 
4
  /**
@@ -30,4 +31,4 @@ class Page extends AbstractTracking
30
  't' => 'pageview',
31
  );
32
  }
33
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Tracking;
4
 
5
  /**
31
  't' => 'pageview',
32
  );
33
  }
34
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/Social.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Tracking;
 
3
  use Racecore\GATracking\Exception\MissingTrackingParameterException;
4
 
5
  /**
@@ -122,4 +124,4 @@ class Social extends AbstractTracking
122
  'st' => $this->getSocialTarget()
123
  );
124
  }
125
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Tracking;
4
+
5
  use Racecore\GATracking\Exception\MissingTrackingParameterException;
6
 
7
  /**
124
  'st' => $this->getSocialTarget()
125
  );
126
  }
127
+ }
includes/vendor/ga-mp/src/Racecore/GATracking/Tracking/User/Timing.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  namespace Racecore\GATracking\Tracking\User;
3
 
4
  use Racecore\GATracking\Tracking\AbstractTracking;
@@ -247,4 +248,4 @@ class Timing extends AbstractTracking
247
  'srt' => $this->getBrowserServerResponseTime()
248
  );
249
  }
250
- }
1
  <?php
2
+
3
  namespace Racecore\GATracking\Tracking\User;
4
 
5
  use Racecore\GATracking\Tracking\AbstractTracking;
248
  'srt' => $this->getBrowserServerResponseTime()
249
  );
250
  }
251
+ }