Event Tracking for Gravity Forms - Version 1.4.0

Version Description

Download this release

Release Info

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

Version 1.4.0

Files changed (25) hide show
  1. LICENSE.txt +339 -0
  2. README.txt +82 -0
  3. admin/class-gravity-forms-event-tracking-addon.php +68 -0
  4. admin/class-gravity-forms-event-tracking-admin.php +208 -0
  5. gravity-forms-event-tracking.php +51 -0
  6. index.php +1 -0
  7. public/class-gravity-forms-event-tracking.php +288 -0
  8. public/includes/ga-mp/src/Racecore/GATracking/Autoloader.php +74 -0
  9. public/includes/ga-mp/src/Racecore/GATracking/Exception.php +22 -0
  10. public/includes/ga-mp/src/Racecore/GATracking/Exception/EndpointServerException.php +24 -0
  11. public/includes/ga-mp/src/Racecore/GATracking/Exception/MissingConfigurationException.php +24 -0
  12. public/includes/ga-mp/src/Racecore/GATracking/Exception/MissingTrackingParameterException.php +24 -0
  13. public/includes/ga-mp/src/Racecore/GATracking/GATracking.php +477 -0
  14. public/includes/ga-mp/src/Racecore/GATracking/Tracking/AbstractTracking.php +31 -0
  15. public/includes/ga-mp/src/Racecore/GATracking/Tracking/App/Event.php +107 -0
  16. public/includes/ga-mp/src/Racecore/GATracking/Tracking/App/Screen.php +107 -0
  17. public/includes/ga-mp/src/Racecore/GATracking/Tracking/Campaign.php +233 -0
  18. public/includes/ga-mp/src/Racecore/GATracking/Tracking/Ecommerce/Item.php +230 -0
  19. public/includes/ga-mp/src/Racecore/GATracking/Tracking/Ecommerce/Transaction.php +209 -0
  20. public/includes/ga-mp/src/Racecore/GATracking/Tracking/Event.php +148 -0
  21. public/includes/ga-mp/src/Racecore/GATracking/Tracking/Exception.php +85 -0
  22. public/includes/ga-mp/src/Racecore/GATracking/Tracking/Page.php +112 -0
  23. public/includes/ga-mp/src/Racecore/GATracking/Tracking/Social.php +125 -0
  24. public/includes/ga-mp/src/Racecore/GATracking/Tracking/User/Timing.php +250 -0
  25. uninstall.php +76 -0
LICENSE.txt ADDED
@@ -0,0 +1,339 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
README.txt ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Gravity Forms Google Analytics Event Tracking ===
2
+ Contributors: nmarks, ronalfy
3
+ Tags: gravity forms, google analytics, event tracking
4
+ Requires at least: 3.5.2
5
+ Tested up to: 4.1
6
+ Stable tag: 1.4.0
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Add Google Analytics Event Tracking to your Gravity Forms in less than 5 minutes!
11
+
12
+ == Description ==
13
+
14
+ This plugin provides an easy way to add Google Analytics event tracking to your Gravity Forms, allowing you to properly track form submissions as events/conversions within Google Analytics.
15
+
16
+ = Features =
17
+ - Automatically send form submission events to Google Analytics
18
+ - Custom event categories, actions, labels and even values
19
+ - Dynamic event value on payment forms (integration with the payment add-ons including Paypal Standard)
20
+ - Awesomeness
21
+
22
+ = Configuration =
23
+ 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 settings page (see screenshots for more information).
24
+
25
+ For payment based forms, you can leave the value blank to convert using the total payment amount.
26
+
27
+ = Hooks/Filters =
28
+ Check out the documentation on [github](https://github.com/nathanmarks/wordpress-gravity-forms-event-tracking)
29
+
30
+ == Installation ==
31
+
32
+ = Minimum Requirements =
33
+ - PHP 5.3+
34
+ - Gravity Forms 1.7+
35
+
36
+ = Using The WordPress Dashboard =
37
+
38
+ 1. Navigate to the 'Add New' in the plugins dashboard
39
+ 2. Search for gravity-forms-google-analytics-event-tracking
40
+ 3. Click 'Install Now'
41
+ 4. Activate the plugin on the Plugin dashboard
42
+
43
+ = Uploading in WordPress Dashboard =
44
+
45
+ 1. Navigate to the 'Add New' in the plugins dashboard
46
+ 2. Navigate to the 'Upload' area
47
+ 3. Select `gravity-forms-event-tracking.zip` from your computer
48
+ 4. Click 'Install Now'
49
+ 5. Activate the plugin in the Plugin dashboard
50
+
51
+ = Using FTP =
52
+
53
+ 1. Download `gravity-forms-event-tracking.zip`
54
+ 2. Extract the `gravity-forms-event-tracking` directory to your computer
55
+ 3. Upload the `gravity-forms-event-tracking` directory to the `/wp-content/plugins/` directory
56
+ 4. Activate the plugin in the Plugin dashboard
57
+
58
+
59
+ == Frequently Asked Questions ==
60
+
61
+ = How do I configure the event category, action and label for the form? =
62
+
63
+ An answer to that question.
64
+
65
+ = Are there any filters/hooks? =
66
+
67
+ Check out the documentation on [github](https://github.com/nathanmarks/wordpress-gravity-forms-event-tracking)
68
+
69
+ == Screenshots ==
70
+
71
+ 1. The Gravity Forms setting screen where you setup your UA ID.
72
+ 2. The form settings where you set your category, action and label.
73
+
74
+ == Changelog ==
75
+
76
+ = 1.4 =
77
+ * Added value for events
78
+ * Properly integrated with payment based forms
79
+
80
+ = 1.3 =
81
+ * Properly integrated with Gravity Forms settings API (thanks ronalfy!)
82
+ * Enabled custom category/action/label on a per form basis.
admin/class-gravity-forms-event-tracking-addon.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Gravity forms event tracking
4
+ *
5
+ * @package Gravity_Forms_Event_Tracking_Admin
6
+ * @author Nathan Marks <nmarks@nvisionsolutions.ca>
7
+ * @author Ronald Huereca <ronalfy@gmail.com>
8
+ * @license GPL-2.0+
9
+ * @link http://www.nvisionsolutions.ca
10
+ * @copyright 2014 Nathan Marks
11
+ */
12
+
13
+ /**
14
+ *
15
+ * @package Gravity_Forms_Event_Tracking_Addon
16
+ * @author Ronald Huereca <ronalfy@gmail.com>
17
+ */
18
+ if ( class_exists( "GFForms" ) ) {
19
+
20
+ GFForms::include_addon_framework();
21
+
22
+ class Gravity_Forms_Event_Tracking_Addon extends GFAddOn {
23
+ protected $_version = "1.0";
24
+ protected $_min_gravityforms_version = "1.7.9";
25
+ protected $_slug = "gravity-forms-event-tracking";
26
+ protected $_path = "gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php";
27
+ protected $_full_path = __FILE__;
28
+ protected $_url = "https://wordpress.org/plugins/gravity-forms-google-analytics-event-tracking";
29
+ protected $_title = "Gravity Forms Google Analytics Event Tracking";
30
+ protected $_short_title = "Event Tracking";
31
+
32
+ // ------- Plugin settings -------
33
+
34
+ public function plugin_settings_fields() {
35
+ return array(
36
+ array(
37
+ 'title' => __( 'Google Analytics', 'gravity-forms-google-analytics-event-tracking' ),
38
+ 'description' => __( 'Enter your UA code (UA-XXXX-Y) here.', 'gravity-forms-google-analytics-event-tracking' ),
39
+ 'fields' => array(
40
+ array(
41
+ 'name' => 'gravity_forms_event_tracking_ua',
42
+ 'label' => __( 'UA Tracking ID', 'gravity-forms-google-analytics-event-tracking' ),
43
+ 'type' => 'text',
44
+ 'class' => 'medium',
45
+ 'tooltip' => 'UA-XXXX-Y',
46
+ 'feedback_callback' => array( $this, 'ua_validation' )
47
+ ),
48
+ )
49
+ ),
50
+ );
51
+ }
52
+ /**
53
+ * Basic Validation
54
+ */
55
+ public function ua_validation($input ) {
56
+ $input = strip_tags( stripslashes( $input ) );
57
+ $ua_regex = "/^UA-[0-9]{5,}-[0-9]{1,}$/";
58
+ if (preg_match($ua_regex, $input)) {
59
+ return true;
60
+ } else {
61
+ $this->log_error( __( 'Invalid UA ID', 'gravity-forms-google-analytics-event-tracking' ) );
62
+ return false;
63
+ }
64
+ }
65
+ }
66
+
67
+ new Gravity_Forms_Event_Tracking_Addon();
68
+ }
admin/class-gravity-forms-event-tracking-admin.php ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Gravity forms event tracking
4
+ *
5
+ * @package Gravity_Forms_Event_Tracking_Admin
6
+ * @author Nathan Marks <nmarks@nvisionsolutions.ca>
7
+ * @license GPL-2.0+
8
+ * @link http://www.nvisionsolutions.ca
9
+ * @copyright 2014 Nathan Marks
10
+ */
11
+
12
+ /**
13
+ *
14
+ * @package Gravity_Forms_Event_Tracking_Admin
15
+ * @author Nathan Marks <nmarks@nvisionsolutions.ca>
16
+ */
17
+ class Gravity_Forms_Event_Tracking_Admin {
18
+
19
+ /**
20
+ * Instance of this class.
21
+ *
22
+ * @since 1.0.0
23
+ *
24
+ * @var object
25
+ */
26
+ protected static $instance = null;
27
+
28
+ /**
29
+ * Slug of the plugin screen.
30
+ *
31
+ * @since 1.0.0
32
+ *
33
+ * @var string
34
+ */
35
+ protected $plugin_screen_hook_suffix = null;
36
+
37
+ /**
38
+ * Initialize the plugin by loading admin scripts & styles and adding a
39
+ * settings page and menu.
40
+ *
41
+ * @since 1.0.0
42
+ */
43
+ private function __construct() {
44
+
45
+ $plugin = Gravity_Forms_Event_Tracking::get_instance();
46
+ $this->plugin_slug = $plugin->get_plugin_slug();
47
+
48
+ // Add an action link pointing to the options page.
49
+ $plugin_basename = plugin_basename( plugin_dir_path( realpath( dirname( __FILE__ ) ) ) . $this->plugin_slug . '.php' );
50
+ add_filter( 'plugin_action_links_' . $plugin_basename, array( $this, 'add_action_links' ) );
51
+
52
+ //Add items to Gravity Forms settings
53
+ add_filter( 'gform_form_settings', array( $this, 'form_settings' ), 10, 2 );
54
+ add_filter( 'gform_tooltips', array( $this, 'add_gforms_tooltips' ) );
55
+ add_filter( 'gform_pre_form_settings_save', array( $this, 'save_gforms_data' ), 10, 1 );
56
+ }
57
+
58
+ /**
59
+ * Save Gravity Forms Data
60
+ *
61
+ * @since 1.0.0
62
+ *
63
+ * @return array sanitized gravity form settings
64
+ */
65
+ public function save_gforms_data( $form_data ) {
66
+
67
+ $form_data[ 'gaEventCategory' ] = rgpost( 'ga_event_category' );
68
+ $form_data[ 'gaEventLabel' ] = rgpost( 'ga_event_label' );
69
+ $form_data[ 'gaEventAction' ] = rgpost( 'ga_event_action' );
70
+ $form_data[ 'gaEventValue' ] = rgpost( 'ga_event_value' );
71
+
72
+ return $form_data;
73
+ }
74
+
75
+
76
+ /**
77
+ * Add Gravity Forms Tooltips
78
+ *
79
+ * @since 1.0.0
80
+ *
81
+ * @return array Gravity Form tooltips
82
+ */
83
+ public function add_gforms_tooltips( $tooltips ) {
84
+ $tooltips[ 'ga_event_category' ] = sprintf( '<h6>%s</h6>%s', __( 'Event Category', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics goal event category', 'gravity-forms-google-analytics-event-tracking' ) );
85
+ $tooltips[ 'ga_event_label' ] = sprintf( '<h6>%s</h6>%s', __( 'Event Label', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics goal event label', 'gravity-forms-google-analytics-event-tracking' ) );
86
+ $tooltips[ 'ga_event_action' ] = sprintf( '<h6>%s</h6>%s', __( 'Event Action', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics goal event action', 'gravity-forms-google-analytics-event-tracking' ) );
87
+ $tooltips[ 'ga_event_value' ] = sprintf( '<h6>%s</h6>%s', __( 'Event Value', 'gravity-forms-google-analytics-event-tracking' ), __( 'Enter your Google Analytics goal event value. Leave blank to omit pushing a value to Google Analytics.', 'gravity-forms-google-analytics-event-tracking' ) );
88
+ return $tooltips;
89
+ }
90
+
91
+ /**
92
+ * Add settings to the form settings page
93
+ *
94
+ * @since 1.0.0
95
+ *
96
+ * @return array Gravity Form settings
97
+ */
98
+ public function form_settings( $form_settings, $form ) {
99
+ $event_category = '
100
+ <tr>
101
+ <th>
102
+ <label for="ga_event_category" style="display:block;">' .
103
+ __("Event Category", "gravity-forms-google-analytics-event-tracking") . ' ' .
104
+ gform_tooltip("ga_event_category", "", true) .
105
+ '</label>
106
+ </th>
107
+ <td>
108
+ <input type="text" id="ga_event_category" name="ga_event_category" class="fieldwidth-3" value="' . esc_attr(rgar($form, 'gaEventCategory')) . '" />
109
+ </td>
110
+ </tr>';
111
+ $event_label = '
112
+ <tr>
113
+ <th>
114
+ <label for="ga_event_label" style="display:block;">' .
115
+ __("Event Label", "gravity-forms-google-analytics-event-tracking") . ' ' .
116
+ gform_tooltip("ga_event_label", "", true) .
117
+ '</label>
118
+ </th>
119
+ <td>
120
+ <input type="text" id="ga_event_label" name="ga_event_label" class="fieldwidth-3" value="' . esc_attr(rgar($form, 'gaEventLabel')) . '" />
121
+ </td>
122
+ </tr>';
123
+ $event_action = '
124
+ <tr>
125
+ <th>
126
+ <label for="ga_event_action" style="display:block;">' .
127
+ __("Event Action", "gravity-forms-google-analytics-event-tracking") . ' ' .
128
+ gform_tooltip("ga_event_action", "", true) .
129
+ '</label>
130
+ </th>
131
+ <td>
132
+ <input type="text" id="ga_event_action" name="ga_event_action" class="fieldwidth-3" value="' . esc_attr(rgar($form, 'gaEventAction')) . '" />
133
+ </td>
134
+ </tr>';
135
+ $event_value = '
136
+ <tr>
137
+ <th>
138
+ <label for="ga_event_value" style="display:block;">' .
139
+ __("Event Value", "gravity-forms-google-analytics-event-tracking") . ' ' .
140
+ gform_tooltip("ga_event_value", "", true) .
141
+ '</label>
142
+ </th>
143
+ <td>
144
+ <input type="number" id="ga_event_value" name="ga_event_value" class="fieldwidth-3" value="' . esc_attr(rgar($form, 'gaEventValue')) . '" />
145
+ <p><strong>Notice:</strong> You can leave this field blank to use the payment amount on forms taking payment.</p>
146
+ </td>
147
+ </tr>';
148
+ $event_instructions = '
149
+ <tr>
150
+ <th></th>
151
+ <td>
152
+ <p>If you leave these <strong>blank</strong>, the following defaults will be used when the event is tracked:</p>
153
+ <p>
154
+ <strong>'.__("Event Category", "gravity-forms-google-analytics-event-tracking").':</strong> Forms<br>
155
+ <strong>'.__("Event Action", "gravity-forms-google-analytics-event-tracking").':</strong> Submission<br>
156
+ <strong>'.__("Event Label", "gravity-forms-google-analytics-event-tracking").':</strong> Form: Form Name ID: X
157
+ </p>
158
+ </td>
159
+ </tr>';
160
+ $event_settings = array(
161
+ //'instructions' => $event_instructions,
162
+ 'cat' => $event_category,
163
+ 'action' => $event_action,
164
+ 'label' => $event_label,
165
+ 'value' => $event_value,
166
+ );
167
+ $event_tracking = array( __( 'Event Tracking', 'gravity-forms-google-analytics-event-tracking' ) => $event_settings );
168
+ $form_settings = $form_settings + $event_tracking;
169
+ return $form_settings;
170
+ }
171
+
172
+ /**
173
+ * Return an instance of this class.
174
+ *
175
+ * @since 1.0.0
176
+ *
177
+ * @return object A single instance of this class.
178
+ */
179
+ public static function get_instance() {
180
+
181
+ // If the single instance hasn't been set, set it now.
182
+ if ( null == self::$instance ) {
183
+ self::$instance = new self;
184
+ }
185
+
186
+ return self::$instance;
187
+ }
188
+
189
+ /**
190
+ * Add settings action link to the plugins page.
191
+ *
192
+ * @since 1.0.0
193
+ */
194
+ public function add_action_links( $links ) {
195
+
196
+ return array_merge(
197
+ array(
198
+ 'settings' => '<a href="' . esc_url( admin_url( 'admin.php?page=gf_settings&subview=gravity-forms-event-tracking' ) ) . '">' . __( 'Settings', $this->plugin_slug ) . '</a>'
199
+ ),
200
+ $links
201
+ );
202
+
203
+ }
204
+
205
+
206
+
207
+
208
+ }
gravity-forms-event-tracking.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Gravity_Forms_Event_Tracking
4
+ * @author Nathan Marks <nmarks@nvisionsolutions.ca>
5
+ * @license GPL-2.0+
6
+ * @link http://www.nvisionsolutions.ca
7
+ * @copyright 2014 Nathan Marks
8
+ *
9
+ * @wordpress-plugin
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.4.0
14
+ * Author: Nathan Marks
15
+ * Author URI: http://www.nvisionsolutions.ca
16
+ * Text Domain: gravity-forms-google-analytics-event-tracking
17
+ * License: GPL-2.0+
18
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
19
+ * Domain Path: /languages
20
+ * GitHub Plugin URI: https://github.com/nathanmarks/wordpress-gravity-forms-event-tracking
21
+ */
22
+
23
+ // If this file is called directly, abort.
24
+ if ( ! defined( 'WPINC' ) ) {
25
+ die;
26
+ }
27
+
28
+ /*----------------------------------------------------------------------------*
29
+ * Public-Facing Functionality
30
+ *----------------------------------------------------------------------------*/
31
+
32
+ require_once( plugin_dir_path( __FILE__ ) . 'public/class-gravity-forms-event-tracking.php' );
33
+
34
+ add_action( 'plugins_loaded', array( 'Gravity_Forms_Event_Tracking', 'get_instance' ) );
35
+
36
+
37
+ /*----------------------------------------------------------------------------*
38
+ * Dashboard and Administrative Functionality
39
+ *----------------------------------------------------------------------------*/
40
+
41
+ /*
42
+ *
43
+ * The code below is intended to to give the lightest footprint possible.
44
+ */
45
+ if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
46
+
47
+ require_once( plugin_dir_path( __FILE__ ) . 'admin/class-gravity-forms-event-tracking-admin.php' );
48
+ require_once( plugin_dir_path( __FILE__ ) . 'admin/class-gravity-forms-event-tracking-addon.php' );
49
+ add_action( 'plugins_loaded', array( 'Gravity_Forms_Event_Tracking_Admin', 'get_instance' ) );
50
+
51
+ }
index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // Silence is golden
public/class-gravity-forms-event-tracking.php ADDED
@@ -0,0 +1,288 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Gravity_Forms_Event_Tracking
4
+ * @author Nathan Marks <nmarks@nvisionsolutions.ca>
5
+ * @license GPL-2.0+
6
+ * @link http://www.nvisionsolutions.ca
7
+ * @copyright 2014 Nathan Marks
8
+ */
9
+
10
+ /**
11
+ *
12
+ * @package Gravity_Forms_Event_Tracking
13
+ * @author Nathan Marks <nmarks@nvisionsolutions.ca>
14
+ */
15
+ class Gravity_Forms_Event_Tracking {
16
+
17
+ /**
18
+ * Plugin version, used for cache-busting of style and script file references.
19
+ *
20
+ * @since 1.0.0
21
+ *
22
+ * @var string
23
+ */
24
+ const VERSION = '1.0.0';
25
+
26
+ /**
27
+ *
28
+ * Unique identifier for your plugin.
29
+ *
30
+ *
31
+ * The variable name is used as the text domain when internationalizing strings
32
+ * of text. Its value should match the Text Domain file header in the main
33
+ * plugin file.
34
+ *
35
+ * @since 1.0.0
36
+ *
37
+ * @var string
38
+ */
39
+ protected $plugin_slug = 'gravity-forms-google-analytics-event-tracking';
40
+
41
+ /**
42
+ * Instance of this class.
43
+ *
44
+ * @since 1.0.0
45
+ *
46
+ * @var object
47
+ */
48
+ protected static $instance = null;
49
+
50
+ /**
51
+ * Constructor
52
+ *
53
+ * @since 1.0.0
54
+ */
55
+ private function __construct() {
56
+
57
+ add_action( 'init', array( $this, 'init' ) );
58
+
59
+ }
60
+
61
+ /**
62
+ * Return the plugin slug.
63
+ *
64
+ * @since 1.0.0
65
+ *
66
+ * @return Plugin slug variable.
67
+ */
68
+ public function get_plugin_slug() {
69
+ return $this->plugin_slug;
70
+ }
71
+
72
+ /**
73
+ * Return an instance of this class.
74
+ *
75
+ * @since 1.0.0
76
+ *
77
+ * @return object A single instance of this class.
78
+ */
79
+ public static function get_instance() {
80
+
81
+ // If the single instance hasn't been set, set it now.
82
+ if ( null == self::$instance ) {
83
+ self::$instance = new self;
84
+ }
85
+
86
+ return self::$instance;
87
+ }
88
+
89
+ /**
90
+ * Load the UA settings and add the tracking action if successful
91
+ *
92
+ * @since 1.4.0
93
+ */
94
+ public function init() {
95
+
96
+ if ( ! is_admin() && $this->load_ua_settings() ) {
97
+ $this->load_measurement_client();
98
+
99
+ // Tracking hooks
100
+ add_action( 'gform_after_submission', array( $this, 'track_form_after_submission' ), 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
+
108
+ }
109
+
110
+ /**
111
+ * Load UA Settings
112
+ *
113
+ * @since 1.4.0
114
+ * @return bool Returns true if UA ID is loaded, false otherwise
115
+ */
116
+ private function load_ua_settings() {
117
+ $gravity_forms_add_on_settings = get_option( 'gravityformsaddon_gravity-forms-event-tracking_settings', array() );
118
+
119
+ $this->ua_id = $ua_id = false;
120
+
121
+ if ( !isset( $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_ua' ] ) ) {
122
+ $ua_id = get_option('gravity_forms_event_tracking_ua', false ); //Backwards compat
123
+ }
124
+ else {
125
+ $ua_id = $gravity_forms_add_on_settings[ 'gravity_forms_event_tracking_ua' ];
126
+ }
127
+
128
+ $ua_regex = "/^UA-[0-9]{5,}-[0-9]{1,}$/";
129
+
130
+ if ( preg_match( $ua_regex, $ua_id ) ) {
131
+ $this->ua_id = $ua_id;
132
+ return true;
133
+ }
134
+
135
+ if (!$this->ua_id)
136
+ return false;
137
+ }
138
+
139
+ /**
140
+ * Load the google measurement protocol PHP client.
141
+ *
142
+ * @since 1.4.0
143
+ */
144
+ private function load_measurement_client() {
145
+
146
+ require_once( 'includes/ga-mp/src/Racecore/GATracking/Autoloader.php');
147
+ Racecore\GATracking\Autoloader::register(dirname(__FILE__).'/includes/ga-mp/src/');
148
+
149
+ }
150
+
151
+ /**
152
+ * Handle the form after submission before sending to the event push
153
+ *
154
+ * @since 1.4.0
155
+ * @param array $entry Gravity Forms entry object
156
+ * @param array $form Gravity Forms form object
157
+ */
158
+ public function track_form_after_submission( $entry, $form ) {
159
+
160
+ // Temporary until Gravity fix a bug
161
+ $entry = GFAPI::get_entry( $entry['id'] );
162
+
163
+ // We need to check if this form is using paypal standard before we push a conversion.
164
+ if ( class_exists( 'GFPayPal' ) ) {
165
+ $paypal = GFPayPal::get_instance();
166
+
167
+ // See if a PayPal standard feed exists for this form and the condition is met.
168
+ // If it is we need to save the GA cookie to the entry instead for return from the IPN
169
+ if ( $feed = $paypal->get_payment_feed( $entry ) && $paypal->is_feed_condition_met( $feed, $form, $entry ) ) {
170
+ gform_update_meta( $entry['id'], 'ga_cookie', $_COOKIE['_ga'] );
171
+ return;
172
+ }
173
+ }
174
+
175
+ // Push the event to google
176
+ $this->push_event( $entry, $form );
177
+ }
178
+
179
+ /**
180
+ * Handle the IPN response for pushing the event
181
+ *
182
+ * @since 1.4.0
183
+ * @param array $post_object global post array from the IPN
184
+ * @param array $entry Gravity Forms entry object
185
+ */
186
+ public function paypal_track_form_post_ipn( $post_object, $entry ) {
187
+ // Check if the payment was completed before continuing
188
+ if ( strtolower( $entry['payment_status'] ) != 'paid' ) {
189
+ return;
190
+ }
191
+
192
+ // Fetch the cookie we saved previously and set it into the cookie global
193
+ // The php analytics library looks for this
194
+ $_COOKIE['_ga'] = gform_get_meta( $entry['ID'], 'ga_cookie' );
195
+
196
+ $form = GFFormsModel::get_form_meta( $entry['form_id'] );
197
+
198
+ // Push the event to google
199
+ $this->push_event( $entry, $form );
200
+ }
201
+
202
+ /**
203
+ * Push the Google Analytics Event!
204
+ *
205
+ * @since 1.4.0
206
+ * @param array $event Gravity Forms event object
207
+ * @param array $form Gravity Forms form object
208
+ */
209
+ private function push_event( $entry, $form ) {
210
+
211
+ // Init tracking object
212
+ $this->tracking = new \Racecore\GATracking\GATracking( apply_filters( 'gform_ua_id', $this->ua_id, $form ), false );
213
+ $event = new \Racecore\GATracking\Tracking\Event();
214
+
215
+ // Get event defaults
216
+ $event_category = 'Forms';
217
+ $event_label = sprintf( "Form: %s ID: %s", $form['title'], $form['id'] );
218
+ $event_action = 'Submission';
219
+
220
+ // IF this form has payment, we should use that for the value
221
+ // as long a custom value hasn't been set
222
+ $event_value = $this->get_event_value( $entry, $form );
223
+
224
+ // Overwrite with Gravity Form Settings if necessary
225
+ if ( function_exists( 'rgar' ) ) {
226
+ // Event category
227
+ $gf_event_category = rgar( $form, 'gaEventCategory' );
228
+ if ( !empty( $gf_event_category ) ) {
229
+ $event_category = $gf_event_category;
230
+ }
231
+
232
+ // Event label
233
+ $gf_event_label = rgar( $form, 'gaEventLabel' );
234
+ if ( !empty( $gf_event_label ) ) {
235
+ $event_label = $gf_event_label;
236
+ }
237
+
238
+ // Event action
239
+ $gf_event_action = rgar( $form, 'gaEventAction' );
240
+ if ( !empty( $gf_event_action ) ) {
241
+ $event_action = $gf_event_action;
242
+ }
243
+
244
+ // Event value
245
+ $gf_event_value = rgar( $form, 'gaEventValue' );
246
+ if ( !empty( $gf_event_value ) ) {
247
+ $event_value = $gf_event_value;
248
+ }
249
+ }
250
+
251
+ // Set our event object variables
252
+ $event->setEventCategory( apply_filters( 'gform_event_category', $event_category, $form ) );
253
+ $event->setEventAction( apply_filters( 'gform_event_action', $event_action, $form ) );
254
+ $event->setEventLabel( apply_filters( 'gform_event_label', $event_label, $form ) );
255
+
256
+ if ( $event_value = apply_filters( 'gform_event_value', $event_value, $form ) ) {
257
+ $event->setEventValue( $event_value );
258
+ }
259
+
260
+ // Pppp Push it!
261
+ $this->tracking->addTracking( $event );
262
+
263
+ try {
264
+ $this->tracking->send();
265
+ } catch (Exception $e) {
266
+ echo 'Error: ' . $e->getMessage() . '<br />' . "\r\n";
267
+ echo 'Type: ' . get_class($e);
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Get the event value for payment entries
273
+ *
274
+ * @since 1.4.0
275
+ * @param array $event Gravity Forms event object
276
+ * @return string/boolean Event value or false if not a payment form
277
+ */
278
+ private function get_event_value( $entry ) {
279
+ $value = rgar( $entry, 'payment_amount' );
280
+
281
+ if ( ! empty( $value ) && intval( $value ) ) {
282
+ return intval( $value );
283
+ }
284
+
285
+ return false;
286
+ }
287
+
288
+ }
public/includes/ga-mp/src/Racecore/GATracking/Autoloader.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
public/includes/ga-mp/src/Racecore/GATracking/Exception.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Exception extends \UnexpectedValueException
21
+ {
22
+ }
public/includes/ga-mp/src/Racecore/GATracking/Exception/EndpointServerException.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Exception;
3
+
4
+ use Racecore\GATracking\Exception;
5
+
6
+ /**
7
+ * Google Analytics Measurement PHP Class
8
+ * Licensed under the 3-clause BSD License.
9
+ * This source file is subject to the 3-clause BSD License that is
10
+ * bundled with this package in the LICENSE file. It is also available at
11
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
12
+ *
13
+ * Google Documentation
14
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
15
+ *
16
+ * @author Marco Rieger
17
+ * @email Rieger(at)racecore.de
18
+ * @git https://github.com/ins0
19
+ * @url http://www.racecore.de
20
+ * @package Racecore\GATracking\Exception
21
+ */
22
+ class EndpointServerException extends Exception
23
+ {
24
+ }
public/includes/ga-mp/src/Racecore/GATracking/Exception/MissingConfigurationException.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Exception;
3
+
4
+ use Racecore\GATracking\Exception;
5
+
6
+ /**
7
+ * Google Analytics Measurement PHP Class
8
+ * Licensed under the 3-clause BSD License.
9
+ * This source file is subject to the 3-clause BSD License that is
10
+ * bundled with this package in the LICENSE file. It is also available at
11
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
12
+ *
13
+ * Google Documentation
14
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
15
+ *
16
+ * @author Marco Rieger
17
+ * @email Rieger(at)racecore.de
18
+ * @git https://github.com/ins0
19
+ * @url http://www.racecore.de
20
+ * @package Racecore\GATracking\Exception
21
+ */
22
+ class MissingConfigurationException extends Exception
23
+ {
24
+ }
public/includes/ga-mp/src/Racecore/GATracking/Exception/MissingTrackingParameterException.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Exception;
3
+
4
+ use Racecore\GATracking\Exception;
5
+
6
+ /**
7
+ * Google Analytics Measurement PHP Class
8
+ * Licensed under the 3-clause BSD License.
9
+ * This source file is subject to the 3-clause BSD License that is
10
+ * bundled with this package in the LICENSE file. It is also available at
11
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
12
+ *
13
+ * Google Documentation
14
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
15
+ *
16
+ * @author Marco Rieger
17
+ * @email Rieger(at)racecore.de
18
+ * @git https://github.com/ins0
19
+ * @url http://www.racecore.de
20
+ * @package Racecore\GATracking\Exception
21
+ */
22
+ class MissingTrackingParameterException extends Exception
23
+ {
24
+ }
public/includes/ga-mp/src/Racecore/GATracking/GATracking.php ADDED
@@ -0,0 +1,477 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
10
+ * Licensed under the 3-clause BSD License.
11
+ * This source file is subject to the 3-clause BSD License that is
12
+ * bundled with this package in the LICENSE file. It is also available at
13
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
14
+ *
15
+ * Google Documentation
16
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
17
+ *
18
+ * @author Marco Rieger
19
+ * @email Rieger(at)racecore.de
20
+ * @git https://github.com/ins0
21
+ * @url http://www.racecore.de
22
+ * @package Racecore\GATracking\Tracking
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
+ /**
234
+ * Check if is a valid UUID v4
235
+ *
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
+ /**
245
+ * Generate UUID v4 function - needed to generate a CID when one isn't available
246
+ *
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
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/AbstractTracking.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
23
+ /**
24
+ * Get the transfer Paket from current Event
25
+ *
26
+ * @return array
27
+ */
28
+ abstract public function getPaket();
29
+
30
+
31
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/App/Event.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Tracking\App;
3
+
4
+ use Racecore\GATracking\Tracking\AbstractTracking;
5
+
6
+ /**
7
+ * Google Analytics Measurement PHP Class
8
+ * Licensed under the 3-clause BSD License.
9
+ * This source file is subject to the 3-clause BSD License that is
10
+ * bundled with this package in the LICENSE file. It is also available at
11
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
12
+ *
13
+ * Google Documentation
14
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
15
+ *
16
+ * @author Marco Rieger
17
+ * @email Rieger(at)racecore.de
18
+ * @git https://github.com/ins0
19
+ * @url http://www.racecore.de
20
+ * @package Racecore\GATracking\Tracking\App
21
+ */
22
+ class Event extends AbstractTracking
23
+ {
24
+ /** @var string */
25
+ private $appName;
26
+
27
+ /** @var string */
28
+ private $eventCategory;
29
+
30
+ /** @var string */
31
+ private $eventAction;
32
+
33
+ /**
34
+ * Set the Application Name
35
+ *
36
+ * @param string $appName
37
+ */
38
+ public function setAppName($appName)
39
+ {
40
+ $this->appName = $appName;
41
+ }
42
+
43
+ /**
44
+ * Get the Application Name
45
+ *
46
+ * @return string
47
+ */
48
+ public function getAppName()
49
+ {
50
+ return $this->appName;
51
+ }
52
+
53
+ /**
54
+ * Set the Event Action
55
+ *
56
+ * @param string $eventAction
57
+ */
58
+ public function setEventAction($eventAction)
59
+ {
60
+ $this->eventAction = $eventAction;
61
+ }
62
+
63
+ /**
64
+ * Get the Event Action
65
+ *
66
+ * @return string
67
+ */
68
+ public function getEventAction()
69
+ {
70
+ return $this->eventAction;
71
+ }
72
+
73
+ /**
74
+ * Set the Event Category
75
+ *
76
+ * @param string $eventCategory
77
+ */
78
+ public function setEventCategory($eventCategory)
79
+ {
80
+ $this->eventCategory = $eventCategory;
81
+ }
82
+
83
+ /**
84
+ * Get the Event Category
85
+ *
86
+ * @return string
87
+ */
88
+ public function getEventCategory()
89
+ {
90
+ return $this->eventCategory;
91
+ }
92
+
93
+ /**
94
+ * Returns the Paket for App Event Tracking
95
+ *
96
+ * @return array
97
+ */
98
+ public function getPaket()
99
+ {
100
+ return array(
101
+ 't' => 'event',
102
+ 'an' => $this->getAppName(),
103
+ 'ec' => $this->getEventCategory(),
104
+ 'ea' => $this->getEventAction()
105
+ );
106
+ }
107
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/App/Screen.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Tracking\App;
3
+
4
+ use Racecore\GATracking\Tracking\AbstractTracking;
5
+
6
+ /**
7
+ * Google Analytics Measurement PHP Class
8
+ * Licensed under the 3-clause BSD License.
9
+ * This source file is subject to the 3-clause BSD License that is
10
+ * bundled with this package in the LICENSE file. It is also available at
11
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
12
+ *
13
+ * Google Documentation
14
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
15
+ *
16
+ * @author Marco Rieger
17
+ * @email Rieger(at)racecore.de
18
+ * @git https://github.com/ins0
19
+ * @url http://www.racecore.de
20
+ * @package Racecore\GATracking\Tracking\App
21
+ */
22
+ class Screen extends AbstractTracking
23
+ {
24
+ /** @var string */
25
+ private $appName;
26
+
27
+ /** @var string */
28
+ private $appVersion;
29
+
30
+ /** @var string */
31
+ private $contentDescription;
32
+
33
+ /**
34
+ * Set the Application Name
35
+ *
36
+ * @param string $appName
37
+ */
38
+ public function setAppName($appName)
39
+ {
40
+ $this->appName = $appName;
41
+ }
42
+
43
+ /**
44
+ * Get the Application Name
45
+ *
46
+ * @return string
47
+ */
48
+ public function getAppName()
49
+ {
50
+ return $this->appName;
51
+ }
52
+
53
+ /**
54
+ * Set the Application Version
55
+ *
56
+ * @param string $appVersion
57
+ */
58
+ public function setAppVersion($appVersion)
59
+ {
60
+ $this->appVersion = $appVersion;
61
+ }
62
+
63
+ /**
64
+ * Get the Application Version
65
+ *
66
+ * @return string
67
+ */
68
+ public function getAppVersion()
69
+ {
70
+ return $this->appVersion;
71
+ }
72
+
73
+ /**
74
+ * Set the Content Description/Screen Name
75
+ *
76
+ * @param string $contentDescription
77
+ */
78
+ public function setContentDescription($contentDescription)
79
+ {
80
+ $this->contentDescription = $contentDescription;
81
+ }
82
+
83
+ /**
84
+ * Get the Content Description/Screen Name
85
+ *
86
+ * @return string
87
+ */
88
+ public function getContentDescription()
89
+ {
90
+ return $this->contentDescription;
91
+ }
92
+
93
+ /**
94
+ * Returns the Paket for App Screen Tracking
95
+ *
96
+ * @return array
97
+ */
98
+ public function getPaket()
99
+ {
100
+ return array(
101
+ 't' => 'appview',
102
+ 'an' => $this->getAppName(),
103
+ 'av' => $this->getAppVersion(),
104
+ 'cd' => $this->getContentDescription()
105
+ );
106
+ }
107
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/Campaign.php ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Tracking;
3
+
4
+ use Racecore\GATracking\Exception\MissingTrackingParameterException;
5
+
6
+ /**
7
+ * Google Analytics Measurement PHP Class
8
+ * Licensed under the 3-clause BSD License.
9
+ * This source file is subject to the 3-clause BSD License that is
10
+ * bundled with this package in the LICENSE file. It is also available at
11
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
12
+ *
13
+ * Google Documentation
14
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
15
+ *
16
+ * @author Marco Rieger
17
+ * @email Rieger(at)racecore.de
18
+ * @git https://github.com/ins0
19
+ * @url http://www.racecore.de
20
+ * @package Racecore\GATracking\Tracking
21
+ */
22
+ class Campaign extends Page
23
+ {
24
+
25
+ /**
26
+ * Campaign Name
27
+ *
28
+ * @var string
29
+ */
30
+ private $name;
31
+
32
+ /**
33
+ * Campaign Source
34
+ *
35
+ * @var string
36
+ */
37
+ private $source;
38
+
39
+ /**
40
+ * Campaign Medium
41
+ *
42
+ * @var string
43
+ */
44
+ private $medium;
45
+
46
+ /**
47
+ * Campaign Keywords
48
+ *
49
+ * @var array
50
+ */
51
+ private $keywords = array();
52
+
53
+ /**
54
+ * Campaign Content
55
+ *
56
+ * @var string
57
+ */
58
+ private $content;
59
+
60
+ /**
61
+ * Campaign ID
62
+ *
63
+ * @var integer
64
+ */
65
+ private $cid;
66
+
67
+ /**
68
+ * Sets the Campaign ID
69
+ *
70
+ * @param $cid
71
+ * @return $this
72
+ */
73
+ public function setCampaignID($cid)
74
+ {
75
+ $this->cid = $cid;
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * Returns the Campaign ID
81
+ *
82
+ * @return int
83
+ */
84
+ public function getCampaignID()
85
+ {
86
+ return $this->cid;
87
+ }
88
+
89
+ /**
90
+ * Sets the Campaign Content Description
91
+ *
92
+ * @param $content
93
+ * @return $this
94
+ */
95
+ public function setCampaignContent($content)
96
+ {
97
+ $this->content = $content;
98
+ return $this;
99
+ }
100
+
101
+ /**
102
+ * Gets the Campaign Content Description
103
+ *
104
+ * @return string
105
+ */
106
+ public function getCampaignContent()
107
+ {
108
+ return $this->content;
109
+ }
110
+
111
+ /**
112
+ * Sets the Campaign Keywords
113
+ *
114
+ * @param $keywords
115
+ * @return $this
116
+ */
117
+ public function setCampaignKeywords($keywords)
118
+ {
119
+ $this->keywords = $keywords;
120
+ return $this;
121
+ }
122
+
123
+ /**
124
+ * Return the Campaign Keywords
125
+ *
126
+ * @return array
127
+ */
128
+ public function getCampaignKeywords()
129
+ {
130
+ return $this->keywords;
131
+ }
132
+
133
+ /**
134
+ * Sets the Campaign Medium
135
+ *
136
+ * @param $medium
137
+ * @return $this
138
+ */
139
+ public function setCampaignMedium($medium)
140
+ {
141
+ $this->medium = $medium;
142
+ return $this;
143
+ }
144
+
145
+ /**
146
+ * Gets the Campaign Medium
147
+ *
148
+ * @return string
149
+ */
150
+ public function getCampaignMedium()
151
+ {
152
+ return $this->medium;
153
+ }
154
+
155
+ /**
156
+ * Sets the Campaign Name
157
+ *
158
+ * @param $name
159
+ * @return $this
160
+ */
161
+ public function setCampaignName($name)
162
+ {
163
+ $this->name = $name;
164
+ return $this;
165
+ }
166
+
167
+ /**
168
+ * Get the Campaign Name
169
+ *
170
+ * @return string
171
+ */
172
+ public function getCampaignName()
173
+ {
174
+ return $this->name;
175
+ }
176
+
177
+ /**
178
+ * Sets the Campaign Source
179
+ *
180
+ * @param $source
181
+ * @return $this
182
+ */
183
+ public function setCampaignSource($source)
184
+ {
185
+ $this->source = $source;
186
+ return $this;
187
+ }
188
+
189
+ /**
190
+ * Get the Campaign Source
191
+ *
192
+ * @return string
193
+ */
194
+ public function getCampaignSource()
195
+ {
196
+ return $this->source;
197
+ }
198
+
199
+ /**
200
+ * Returns the Paket for Campaign Tracking
201
+ *
202
+ * @return array
203
+ * @throws \Racecore\GATracking\Exception\MissingTrackingParameterException
204
+ */
205
+ public function getPaket()
206
+ {
207
+
208
+ $packet = parent::getPaket();
209
+
210
+ if (!$this->getCampaignName()) {
211
+ throw new MissingTrackingParameterException('Campaign Name musst be set');
212
+ }
213
+
214
+ if (!$this->getCampaignMedium()) {
215
+ throw new MissingTrackingParameterException('Campaign Medium musst be set');
216
+ }
217
+
218
+ if (!$this->getCampaignSource()) {
219
+ throw new MissingTrackingParameterException('Campaign Source musst be set');
220
+ }
221
+
222
+ return array_merge($packet, array(
223
+ 'cn' => $this->getCampaignName(),
224
+ 'cs' => $this->getCampaignSource(),
225
+ 'cm' => $this->getCampaignMedium(),
226
+ 'ck' => implode(';', $this->getCampaignKeywords()),
227
+ 'cc' => $this->getCampaignContent(),
228
+ 'ci' => $this->getCampaignID()
229
+ ));
230
+ }
231
+
232
+
233
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/Ecommerce/Item.php ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Tracking\Ecommerce;
3
+
4
+ use Racecore\GATracking\Exception\MissingTrackingParameterException;
5
+ use Racecore\GATracking\Tracking\AbstractTracking;
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 Enea Berti
18
+ * @email reysharks(at)gmail.com
19
+ * @git https://github.com/reysharks
20
+ * @url http://www.adacto.it
21
+ * @package Racecore\GATracking\Tracking
22
+ */
23
+ class Item extends AbstractTracking
24
+ {
25
+
26
+ private $tid = 0;
27
+ private $name = '';
28
+ private $price = 0;
29
+ private $quantity = 0;
30
+ private $sku = '';
31
+ private $category = '';
32
+ private $currency = '';
33
+
34
+ /**
35
+ * Set the Transaction ID
36
+ *
37
+ * @param $id
38
+ */
39
+ public function setTransactionID($tid)
40
+ {
41
+
42
+ $this->tid = $tid;
43
+ }
44
+
45
+ /**
46
+ * Returns the Transaction ID
47
+ *
48
+ * @return integer
49
+ */
50
+ public function getTransactionID()
51
+ {
52
+
53
+ if (!$this->tid) {
54
+ return '/';
55
+ }
56
+
57
+ return $this->tid;
58
+ }
59
+
60
+ /**
61
+ * Sets the Item Name
62
+ *
63
+ * @param $name
64
+ */
65
+ public function setName($name)
66
+ {
67
+
68
+ $this->name = $name;
69
+ }
70
+
71
+ /**
72
+ * Return Name
73
+ *
74
+ * @return string
75
+ */
76
+ public function getName()
77
+ {
78
+
79
+ if (!$this->name) {
80
+ return $this->sku;
81
+ }
82
+
83
+ return $this->name;
84
+ }
85
+
86
+ /**
87
+ * Sets the Item Price
88
+ *
89
+ * @param $price
90
+ */
91
+ public function setPrice($price)
92
+ {
93
+ $this->price = $price;
94
+ }
95
+
96
+ /**
97
+ * Return the Price
98
+ *
99
+ * @return float
100
+ */
101
+ public function getPrice()
102
+ {
103
+ return $this->price;
104
+ }
105
+
106
+ /**
107
+ * Sets the Quantity
108
+ *
109
+ * @param $quantity
110
+ */
111
+ public function setQuantity($quantity)
112
+ {
113
+ $this->quantity = $quantity;
114
+ }
115
+
116
+ /**
117
+ * Return Quantity
118
+ *
119
+ * @return integer
120
+ */
121
+ public function getQuantity()
122
+ {
123
+ return $this->quantity;
124
+ }
125
+
126
+ /**
127
+ * Sets the Sku
128
+ *
129
+ * @param $sku
130
+ */
131
+ public function setSku($sku)
132
+ {
133
+ $this->sku = $sku;
134
+ }
135
+
136
+ /**
137
+ * Return the Sku
138
+ *
139
+ * @return float
140
+ */
141
+ public function getSku()
142
+ {
143
+ return $this->sku;
144
+ }
145
+
146
+ /**
147
+ * Sets the Category
148
+ *
149
+ * @param $category
150
+ */
151
+ public function setCategory($category)
152
+ {
153
+ $this->category = $category;
154
+ }
155
+
156
+ /**
157
+ * Return the Category
158
+ *
159
+ * @return float
160
+ */
161
+ public function getCategory()
162
+ {
163
+ return $this->category;
164
+ }
165
+
166
+ /**
167
+ * Sets the Currency
168
+ *
169
+ * @param $currency
170
+ */
171
+ public function setCurrency($currency)
172
+ {
173
+ $this->currency = $currency;
174
+ }
175
+
176
+ /**
177
+ * Return the Currency
178
+ *
179
+ * @return string
180
+ */
181
+ public function getCurrency()
182
+ {
183
+ return $this->currency;
184
+ }
185
+
186
+ public function setTransactionHost($host)
187
+ {
188
+ $this->host = $host;
189
+ return $this;
190
+ }
191
+
192
+ /**
193
+ * @return string
194
+ */
195
+ public function getTransactionHost()
196
+ {
197
+ return $this->host;
198
+ }
199
+
200
+ /**
201
+ * Returns the Google Paket for Item Tracking
202
+ *
203
+ * @return array
204
+ */
205
+ public function getPaket()
206
+ {
207
+ if( !$this->getTransactionID() )
208
+ {
209
+ throw new MissingTrackingParameterException('transaction id is missing');
210
+ }
211
+
212
+ if( !$this->getName() )
213
+ {
214
+ throw new MissingTrackingParameterException('item name is missing');
215
+ }
216
+
217
+ return array(
218
+ 't' => 'item',
219
+ 'ti' => $this->getTransactionID(),
220
+ 'in' => $this->getName(),
221
+ 'ip' => $this->getPrice(),
222
+ 'iq' => $this->getQuantity(),
223
+ 'ic' => $this->getSku(),
224
+ 'iv' => $this->getCategory(),
225
+ 'dh' => $this->getTransactionHost(),
226
+ 'cu' => $this->getCurrency()
227
+ );
228
+ }
229
+
230
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/Ecommerce/Transaction.php ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Tracking\Ecommerce;
3
+
4
+ use Racecore\GATracking\Exception\MissingTrackingParameterException;
5
+ use Racecore\GATracking\Tracking\AbstractTracking;
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 Enea Berti
18
+ * @email reysharks(at)gmail.com
19
+ * @git https://github.com/reysharks
20
+ * @url http://www.adacto.it
21
+ * @package Racecore\GATracking\Tracking
22
+ */
23
+ class Transaction extends AbstractTracking
24
+ {
25
+
26
+ private $id = 0;
27
+ private $affiliation = '';
28
+ private $revenue = 0;
29
+ private $shipping = 0;
30
+ private $tax = 0;
31
+ private $currency = '';
32
+ private $host = '';
33
+
34
+ /**
35
+ * Set the Transaction ID
36
+ *
37
+ * @param $id
38
+ */
39
+ public function setID($id)
40
+ {
41
+
42
+ $this->id = $id;
43
+ }
44
+
45
+ /**
46
+ * Returns the Transaction ID
47
+ *
48
+ * @return integer
49
+ */
50
+ public function getID()
51
+ {
52
+
53
+ if (!$this->id) {
54
+ return '/';
55
+ }
56
+
57
+ return $this->id;
58
+ }
59
+
60
+ /**
61
+ * Sets the Affiliation
62
+ *
63
+ * @param $affiliation
64
+ */
65
+ public function setAffiliation($affiliation)
66
+ {
67
+
68
+ $this->affiliation = $affiliation;
69
+ }
70
+
71
+ /**
72
+ * Return Affiliation
73
+ *
74
+ * @return string
75
+ */
76
+ public function getAffiliation()
77
+ {
78
+
79
+ return $this->affiliation;
80
+ }
81
+
82
+ /**
83
+ * Sets the Revenue
84
+ *
85
+ * @param $revenue
86
+ */
87
+ public function setRevenue($revenue)
88
+ {
89
+ $this->revenue = $revenue;
90
+ }
91
+
92
+ /**
93
+ * Return the Revenue
94
+ *
95
+ * @return float
96
+ */
97
+ public function getRevenue()
98
+ {
99
+ return $this->revenue;
100
+ }
101
+
102
+ /**
103
+ * Sets the Shipping
104
+ *
105
+ * @param $shipping
106
+ */
107
+ public function setShipping($shipping)
108
+ {
109
+ $this->shipping = $shipping;
110
+ }
111
+
112
+ /**
113
+ * Return Shipping
114
+ *
115
+ * @return float
116
+ */
117
+ public function getShipping()
118
+ {
119
+ return $this->shipping;
120
+ }
121
+
122
+ /**
123
+ * Sets the Tax
124
+ *
125
+ * @param $tax
126
+ */
127
+ public function setTax($tax)
128
+ {
129
+ $this->tax = $tax;
130
+ }
131
+
132
+ /**
133
+ * Return the Tax
134
+ *
135
+ * @return float
136
+ */
137
+ public function getTax()
138
+ {
139
+ return $this->tax;
140
+ }
141
+
142
+ /**
143
+ * Sets the Currency
144
+ *
145
+ * @param $currency
146
+ */
147
+ public function setCurrency($currency)
148
+ {
149
+ $this->currency = $currency;
150
+ }
151
+
152
+ /**
153
+ * Return the Currency
154
+ *
155
+ * @return string
156
+ */
157
+ public function getCurrency()
158
+ {
159
+ return $this->currency;
160
+ }
161
+
162
+ /**
163
+ * Return the Transaction Host Address
164
+ *
165
+ * @param $host
166
+ * @return $this
167
+ */
168
+ public function setTransactionHost($host)
169
+ {
170
+ $this->host = $host;
171
+ return $this;
172
+ }
173
+
174
+ /**
175
+ * Returns the Transaction Host
176
+ *
177
+ * @return string
178
+ */
179
+ public function getTransactionHost()
180
+ {
181
+ return $this->host;
182
+ }
183
+
184
+ /**
185
+ * Returns the Google Paket for Transaction Tracking
186
+ *
187
+ * @return array
188
+ * @throws \Racecore\GATracking\Exception\MissingTrackingParameterException
189
+ */
190
+ public function getPaket()
191
+ {
192
+ if( !$this->getID() )
193
+ {
194
+ throw new MissingTrackingParameterException('transaction id is missing');
195
+ }
196
+
197
+ return array(
198
+ 't' => 'transaction',
199
+ 'ti' => $this->getID(),
200
+ 'ta' => $this->getAffiliation(),
201
+ 'tr' => $this->getRevenue(),
202
+ 'ts' => $this->getShipping(),
203
+ 'tt' => $this->getTax(),
204
+ 'dh' => $this->getTransactionHost(),
205
+ 'cu' => $this->getCurrency()
206
+ );
207
+ }
208
+
209
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/Event.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Tracking;
3
+
4
+ use Racecore\GATracking\Exception\MissingTrackingParameterException;
5
+
6
+ /**
7
+ * Google Analytics Measurement PHP Class
8
+ * Licensed under the 3-clause BSD License.
9
+ * This source file is subject to the 3-clause BSD License that is
10
+ * bundled with this package in the LICENSE file. It is also available at
11
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
12
+ *
13
+ * Google Documentation
14
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
15
+ *
16
+ * @author Marco Rieger
17
+ * @email Rieger(at)racecore.de
18
+ * @git https://github.com/ins0
19
+ * @url http://www.racecore.de
20
+ * @package Racecore\GATracking\Tracking
21
+ */
22
+ class Event extends AbstractTracking
23
+ {
24
+ /** @var String */
25
+ private $eventCategory;
26
+
27
+ /** @var String */
28
+ private $eventAction;
29
+
30
+ /** @var String */
31
+ private $eventLabel;
32
+
33
+ /** @var String */
34
+ private $eventValue;
35
+
36
+ /**
37
+ * Set the Event Action (Required)
38
+ *
39
+ * @param $eventAction
40
+ * @return $this
41
+ */
42
+ public function setEventAction($eventAction)
43
+ {
44
+ $this->eventAction = $eventAction;
45
+ return $this;
46
+ }
47
+
48
+ /**
49
+ * Get the Event Action
50
+ *
51
+ * @return $this
52
+ */
53
+ public function getEventAction()
54
+ {
55
+ return $this->eventAction;
56
+ }
57
+
58
+ /**
59
+ * Set the Event Category (Required)
60
+ *
61
+ * @param $eventCategory
62
+ * @return $this
63
+ */
64
+ public function setEventCategory($eventCategory)
65
+ {
66
+ $this->eventCategory = $eventCategory;
67
+ return $this;
68
+ }
69
+
70
+ /**
71
+ * Get the Event Category
72
+ *
73
+ * @return $this
74
+ */
75
+ public function getEventCategory()
76
+ {
77
+ return $this->eventCategory;
78
+ }
79
+
80
+ /**
81
+ * Set the Event Label
82
+ *
83
+ * @param $eventLabel
84
+ * @return $this
85
+ */
86
+ public function setEventLabel($eventLabel)
87
+ {
88
+ $this->eventLabel = $eventLabel;
89
+ return $this;
90
+ }
91
+
92
+ /**
93
+ * Get the Event Label
94
+ *
95
+ * @return $this
96
+ */
97
+ public function getEventLabel()
98
+ {
99
+ return $this->eventLabel;
100
+ }
101
+
102
+ /**
103
+ * Set the Event Value
104
+ *
105
+ * @param $eventValue
106
+ * @return $this
107
+ */
108
+ public function setEventValue($eventValue)
109
+ {
110
+ $this->eventValue = $eventValue;
111
+ return $this;
112
+ }
113
+
114
+ /**
115
+ * Get the Event Value
116
+ *
117
+ * @return $this
118
+ */
119
+ public function getEventValue()
120
+ {
121
+ return $this->eventValue;
122
+ }
123
+
124
+ /**
125
+ * Returns the Paket for Event Tracking
126
+ *
127
+ * @return array
128
+ * @throws \Racecore\GATracking\Exception\MissingTrackingParameterException
129
+ */
130
+ public function getPaket()
131
+ {
132
+ if (!$this->getEventCategory()) {
133
+ throw new MissingTrackingParameterException('event category musst be set');
134
+ }
135
+
136
+ if (!$this->getEventAction()) {
137
+ throw new MissingTrackingParameterException('event action musst be set');
138
+ }
139
+
140
+ return array(
141
+ 't' => 'event',
142
+ 'ec' => $this->getEventCategory(),
143
+ 'ea' => $this->getEventAction(),
144
+ 'el' => $this->getEventLabel(),
145
+ 'ev' => $this->getEventValue()
146
+ );
147
+ }
148
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/Exception.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ class Exception extends AbstractTracking
21
+ {
22
+ /** @var string */
23
+ private $exceptionDescription;
24
+
25
+ /** @var bool */
26
+ private $exceptionFatal;
27
+
28
+ /**
29
+ * Set the Exception Description
30
+ *
31
+ * @param $exceptionDescription
32
+ * @return $this
33
+ */
34
+ public function setExceptionDescription($exceptionDescription)
35
+ {
36
+ $this->exceptionDescription = $exceptionDescription;
37
+ return $this;
38
+ }
39
+
40
+ /**
41
+ * Get the Exception Description
42
+ *
43
+ * @return String
44
+ */
45
+ public function getExceptionDescription()
46
+ {
47
+ return $this->exceptionDescription;
48
+ }
49
+
50
+ /**
51
+ * Set if Exception is fatal
52
+ *
53
+ * @param $exceptionFatal
54
+ * @return $this
55
+ */
56
+ public function setExceptionFatal($exceptionFatal)
57
+ {
58
+ $this->exceptionFatal = (bool) $exceptionFatal;
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * Get Exception is fatal
64
+ *
65
+ * @return bool
66
+ */
67
+ public function getExceptionFatal()
68
+ {
69
+ return $this->exceptionFatal;
70
+ }
71
+
72
+ /**
73
+ * Returns the Paket for Exception Tracking
74
+ *
75
+ * @return array
76
+ */
77
+ public function getPaket()
78
+ {
79
+ return array(
80
+ 't' => 'exception',
81
+ 'exd' => $this->getExceptionDescription(),
82
+ 'exf' => ( $this->getExceptionFatal() ? '1' : '0' )
83
+ );
84
+ }
85
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/Page.php ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ class Page extends AbstractTracking
21
+ {
22
+
23
+ private $documentPath = '';
24
+ private $host = '';
25
+ private $title = '';
26
+
27
+ /**
28
+ * Set the Request Document Path
29
+ *
30
+ * @param $path
31
+ */
32
+ public function setDocumentPath($path)
33
+ {
34
+
35
+ $this->documentPath = $path;
36
+ }
37
+
38
+ /**
39
+ * Returns the Request Document Path
40
+ *
41
+ * @return string
42
+ */
43
+ public function getDocumentPath()
44
+ {
45
+
46
+ if (!$this->documentPath) {
47
+ return '/';
48
+ }
49
+
50
+ return $this->documentPath;
51
+ }
52
+
53
+ /**
54
+ * Sets the Document Title in Analytics Report
55
+ *
56
+ * @param $title
57
+ */
58
+ public function setDocumentTitle($title)
59
+ {
60
+
61
+ $this->title = $title;
62
+ }
63
+
64
+ /**
65
+ * Return Document Title
66
+ *
67
+ * @return string
68
+ */
69
+ public function getDocumentTitle()
70
+ {
71
+
72
+ return $this->title;
73
+ }
74
+
75
+ /**
76
+ * Return the Document Host Adress
77
+ *
78
+ * @param $host
79
+ * @return $this
80
+ */
81
+ public function setDocumentHost($host)
82
+ {
83
+ $this->host = $host;
84
+ return $this;
85
+ }
86
+
87
+ /**
88
+ * Return Document Host
89
+ *
90
+ * @return string
91
+ */
92
+ public function getDocumentHost()
93
+ {
94
+ return $this->host;
95
+ }
96
+
97
+ /**
98
+ * Returns the Google Paket for Campaign Tracking
99
+ *
100
+ * @return array
101
+ */
102
+ public function getPaket()
103
+ {
104
+ return array(
105
+ 't' => 'pageview',
106
+ 'dh' => $this->getDocumentHost(),
107
+ 'dp' => $this->getDocumentPath(),
108
+ 'dt' => $this->getDocumentTitle()
109
+ );
110
+ }
111
+
112
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/Social.php ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Tracking;
3
+ use Racecore\GATracking\Exception\MissingTrackingParameterException;
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 Social extends AbstractTracking
22
+ {
23
+ /** @var String */
24
+ private $socialAction;
25
+
26
+ /** @var String */
27
+ private $socialNetwork;
28
+
29
+ /** @var String */
30
+ private $socialTarget;
31
+
32
+ /**
33
+ * Set the Social Action (Required)
34
+ *
35
+ * @param $socialAction
36
+ * @return $this
37
+ */
38
+ public function setSocialAction($socialAction)
39
+ {
40
+ $this->socialAction = $socialAction;
41
+ return $this;
42
+ }
43
+
44
+ /**
45
+ * Get the Social Action
46
+ *
47
+ * @return String
48
+ */
49
+ public function getSocialAction()
50
+ {
51
+ return $this->socialAction;
52
+ }
53
+
54
+ /**
55
+ * Set the Social Network (Required)
56
+ *
57
+ * @param $socialNetwork
58
+ * @return $this
59
+ */
60
+ public function setSocialNetwork($socialNetwork)
61
+ {
62
+ $this->socialNetwork = $socialNetwork;
63
+ return $this;
64
+ }
65
+
66
+ /**
67
+ * Get the Social Network
68
+ *
69
+ * @return String
70
+ */
71
+ public function getSocialNetwork()
72
+ {
73
+ return $this->socialNetwork;
74
+ }
75
+
76
+ /**
77
+ * Set the Social Target (Required)
78
+ *
79
+ * @param $socialTarget
80
+ * @return $this
81
+ */
82
+ public function setSocialTarget($socialTarget)
83
+ {
84
+ $this->socialTarget = $socialTarget;
85
+ return $this;
86
+ }
87
+
88
+ /**
89
+ * Get the Social Target
90
+ *
91
+ * @return String
92
+ */
93
+ public function getSocialTarget()
94
+ {
95
+ return $this->socialTarget;
96
+ }
97
+
98
+ /**
99
+ * Returns the Google Paket for Social Tracking
100
+ *
101
+ * @return array
102
+ * @throws \Racecore\GATracking\Exception\MissingTrackingParameterException
103
+ */
104
+ public function getPaket()
105
+ {
106
+ if (!$this->getSocialAction()) {
107
+ throw new MissingTrackingParameterException('social action musst be set');
108
+ }
109
+
110
+ if (!$this->getSocialNetwork()) {
111
+ throw new MissingTrackingParameterException('social network musst be set');
112
+ }
113
+
114
+ if (!$this->getSocialTarget()) {
115
+ throw new MissingTrackingParameterException('social target musst be set');
116
+ }
117
+
118
+ return array(
119
+ 't' => 'social',
120
+ 'sa' => $this->getSocialAction(),
121
+ 'sn' => $this->getSocialNetwork(),
122
+ 'st' => $this->getSocialTarget()
123
+ );
124
+ }
125
+ }
public/includes/ga-mp/src/Racecore/GATracking/Tracking/User/Timing.php ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ namespace Racecore\GATracking\Tracking\User;
3
+
4
+ use Racecore\GATracking\Tracking\AbstractTracking;
5
+
6
+ /**
7
+ * Google Analytics Measurement PHP Class
8
+ * Licensed under the 3-clause BSD License.
9
+ * This source file is subject to the 3-clause BSD License that is
10
+ * bundled with this package in the LICENSE file. It is also available at
11
+ * the following URL: http://www.opensource.org/licenses/BSD-3-Clause
12
+ *
13
+ * Google Documentation
14
+ * https://developers.google.com/analytics/devguides/collection/protocol/v1/
15
+ *
16
+ * @author Marco Rieger
17
+ * @email Rieger(at)racecore.de
18
+ * @git https://github.com/ins0
19
+ * @url http://www.racecore.de
20
+ * @package Racecore\GATracking\Tracking\User
21
+ */
22
+ class Timing extends AbstractTracking
23
+ {
24
+ /** @var string */
25
+ private $timingCategory;
26
+
27
+ /** @var string */
28
+ private $timingVariable;
29
+
30
+ /** @var integer */
31
+ private $timingTime;
32
+
33
+ /** @var string */
34
+ private $timingLabel;
35
+
36
+ /** @var integer */
37
+ private $browserDnsLoadTime;
38
+
39
+ /** @var integer */
40
+ private $browserPageDownloadTime;
41
+
42
+ /** @var integer */
43
+ private $browserRedirectTime;
44
+
45
+ /** @var integer */
46
+ private $browserTcpConnectTime;
47
+
48
+ /** @var integer */
49
+ private $browserServerResponseTime;
50
+
51
+ /**
52
+ * Set the browser dns load time
53
+ *
54
+ * @param int $browserDnsLoadTime
55
+ */
56
+ public function setBrowserDnsLoadTime($browserDnsLoadTime)
57
+ {
58
+ $this->browserDnsLoadTime = $browserDnsLoadTime;
59
+ }
60
+
61
+ /**
62
+ * Get the browser dns load time
63
+ *
64
+ * @return int
65
+ */
66
+ public function getBrowserDnsLoadTime()
67
+ {
68
+ return $this->browserDnsLoadTime;
69
+ }
70
+
71
+ /**
72
+ * Set the browser page download time
73
+ *
74
+ * @param int $browserPageDownloadTime
75
+ */
76
+ public function setBrowserPageDownloadTime($browserPageDownloadTime)
77
+ {
78
+ $this->browserPageDownloadTime = $browserPageDownloadTime;
79
+ }
80
+
81
+ /**
82
+ * Get the browser page download time
83
+ * @return int
84
+ */
85
+ public function getBrowserPageDownloadTime()
86
+ {
87
+ return $this->browserPageDownloadTime;
88
+ }
89
+
90
+ /**
91
+ * Set the browser redirect time
92
+ *
93
+ * @param int $browserRedirectTime
94
+ */
95
+ public function setBrowserRedirectTime($browserRedirectTime)
96
+ {
97
+ $this->browserRedirectTime = $browserRedirectTime;
98
+ }
99
+
100
+ /**
101
+ * Get the browser redirect time
102
+ *
103
+ * @return int
104
+ */
105
+ public function getBrowserRedirectTime()
106
+ {
107
+ return $this->browserRedirectTime;
108
+ }
109
+
110
+ /**
111
+ * Set the browser server response time
112
+ *
113
+ * @param int $browserServerResponseTime
114
+ */
115
+ public function setBrowserServerResponseTime($browserServerResponseTime)
116
+ {
117
+ $this->browserServerResponseTime = $browserServerResponseTime;
118
+ }
119
+
120
+ /**
121
+ * Get the browser server response time
122
+ *
123
+ * @return int
124
+ */
125
+ public function getBrowserServerResponseTime()
126
+ {
127
+ return $this->browserServerResponseTime;
128
+ }
129
+
130
+ /**
131
+ * Set the browser tcp conenct time
132
+ *
133
+ * @param int $browserTcpConnectTime
134
+ */
135
+ public function setBrowserTcpConnectTime($browserTcpConnectTime)
136
+ {
137
+ $this->browserTcpConnectTime = $browserTcpConnectTime;
138
+ }
139
+
140
+ /**
141
+ * Get the browser tcp conenct time
142
+ *
143
+ * @return int
144
+ */
145
+ public function getBrowserTcpConnectTime()
146
+ {
147
+ return $this->browserTcpConnectTime;
148
+ }
149
+
150
+ /**
151
+ * Set the timing category
152
+ *
153
+ * @param string $timingCategory
154
+ */
155
+ public function setTimingCategory($timingCategory)
156
+ {
157
+ $this->timingCategory = $timingCategory;
158
+ }
159
+
160
+ /**
161
+ * Get the timing category
162
+ *
163
+ * @return string
164
+ */
165
+ public function getTimingCategory()
166
+ {
167
+ return $this->timingCategory;
168
+ }
169
+
170
+ /**
171
+ * Set the timing label
172
+ *
173
+ * @param string $timingLabel
174
+ */
175
+ public function setTimingLabel($timingLabel)
176
+ {
177
+ $this->timingLabel = $timingLabel;
178
+ }
179
+
180
+ /**
181
+ * Get the timing label
182
+ *
183
+ * @return string
184
+ */
185
+ public function getTimingLabel()
186
+ {
187
+ return $this->timingLabel;
188
+ }
189
+
190
+ /**
191
+ * Set the timing time
192
+ *
193
+ * @param int $timingTime
194
+ */
195
+ public function setTimingTime($timingTime)
196
+ {
197
+ $this->timingTime = $timingTime;
198
+ }
199
+
200
+ /**
201
+ * Get the timing time
202
+ *
203
+ * @return int
204
+ */
205
+ public function getTimingTime()
206
+ {
207
+ return $this->timingTime;
208
+ }
209
+
210
+ /**
211
+ * Set the timing variable
212
+ *
213
+ * @param string $timingVariable
214
+ */
215
+ public function setTimingVariable($timingVariable)
216
+ {
217
+ $this->timingVariable = $timingVariable;
218
+ }
219
+
220
+ /**
221
+ * Get the timing time
222
+ *
223
+ * @return string
224
+ */
225
+ public function getTimingVariable()
226
+ {
227
+ return $this->timingVariable;
228
+ }
229
+
230
+ /**
231
+ * Returns the Paket for User Timing Tracking
232
+ *
233
+ * @return array
234
+ */
235
+ public function getPaket()
236
+ {
237
+ return array(
238
+ 't' => 'timing',
239
+ 'utc' => $this->getTimingCategory(),
240
+ 'utv' => $this->getTimingVariable(),
241
+ 'utt' => $this->getTimingTime(),
242
+ 'utl' => $this->getTimingLabel(),
243
+ 'dns' => $this->getBrowserDnsLoadTime(),
244
+ 'pdt' => $this->getBrowserPageDownloadTime(),
245
+ 'rrt' => $this->getBrowserRedirectTime(),
246
+ 'tcp' => $this->getBrowserTcpConnectTime(),
247
+ 'srt' => $this->getBrowserServerResponseTime()
248
+ );
249
+ }
250
+ }
uninstall.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Fired when the plugin is uninstalled.
4
+ *
5
+ * @package Plugin_Name
6
+ * @author Your Name <email@example.com>
7
+ * @license GPL-2.0+
8
+ * @link http://example.com
9
+ * @copyright 2014 Your Name or Company Name
10
+ */
11
+
12
+ // If uninstall not called from WordPress, then exit
13
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
14
+ exit;
15
+ }
16
+
17
+ global $wpdb;
18
+
19
+ if ( is_multisite() ) {
20
+
21
+ $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A );
22
+ /* @TODO: delete all transient, options and files you may have added
23
+ delete_transient( 'TRANSIENT_NAME' );
24
+ delete_option('OPTION_NAME');
25
+ //info: remove custom file directory for main site
26
+ $upload_dir = wp_upload_dir();
27
+ $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR;
28
+ if (is_dir($directory)) {
29
+ foreach(glob($directory.'*.*') as $v){
30
+ unlink($v);
31
+ }
32
+ rmdir($directory);
33
+ }
34
+ */
35
+ if ( $blogs ) {
36
+
37
+ foreach ( $blogs as $blog ) {
38
+ switch_to_blog( $blog['blog_id'] );
39
+ /* @TODO: delete all transient, options and files you may have added
40
+ delete_transient( 'TRANSIENT_NAME' );
41
+ delete_option('OPTION_NAME');
42
+ //info: remove custom file directory for main site
43
+ $upload_dir = wp_upload_dir();
44
+ $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR;
45
+ if (is_dir($directory)) {
46
+ foreach(glob($directory.'*.*') as $v){
47
+ unlink($v);
48
+ }
49
+ rmdir($directory);
50
+ }
51
+ //info: remove and optimize tables
52
+ $GLOBALS['wpdb']->query("DROP TABLE `".$GLOBALS['wpdb']->prefix."TABLE_NAME`");
53
+ $GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->prefix."options`");
54
+ */
55
+ restore_current_blog();
56
+ }
57
+ }
58
+
59
+ } else {
60
+ /* @TODO: delete all transient, options and files you may have added
61
+ delete_transient( 'TRANSIENT_NAME' );
62
+ delete_option('OPTION_NAME');
63
+ //info: remove custom file directory for main site
64
+ $upload_dir = wp_upload_dir();
65
+ $directory = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . "CUSTOM_DIRECTORY_NAME" . DIRECTORY_SEPARATOR;
66
+ if (is_dir($directory)) {
67
+ foreach(glob($directory.'*.*') as $v){
68
+ unlink($v);
69
+ }
70
+ rmdir($directory);
71
+ }
72
+ //info: remove and optimize tables
73
+ $GLOBALS['wpdb']->query("DROP TABLE `".$GLOBALS['wpdb']->prefix."TABLE_NAME`");
74
+ $GLOBALS['wpdb']->query("OPTIMIZE TABLE `" .$GLOBALS['wpdb']->prefix."options`");
75
+ */
76
+ }