├── .gitignore
├── Haxe-ga.hxml
├── Haxe-ga.hxproj
├── LICENSE.md
├── README.md
└── src
├── Main.hx
├── buildPackage.sh
├── googleAnalytics
├── Campaign.hx
├── Config.hx
├── CustomVariable.hx
├── DateTime.hx
├── Event.hx
├── Item.hx
├── Page.hx
├── Session.hx
├── SocialInteraction.hx
├── Stats.hx
├── ThreadedSocketRequest.hx
├── Tracker.hx
├── Transaction.hx
├── URLParser.hx
├── Visitor.hx
└── internals
│ ├── ParameterHolder.hx
│ ├── Util.hx
│ ├── X10.hx
│ └── request
│ ├── EventRequest.hx
│ ├── ItemRequest.hx
│ ├── PageviewRequest.hx
│ ├── Request.hx
│ ├── SocialInteractionRequest.hx
│ └── TransactionRequest.hx
├── haxelib.json
├── include.xml
└── installPackage.sh
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | /bin
3 | /src/haxe-ga.zip
--------------------------------------------------------------------------------
/Haxe-ga.hxml:
--------------------------------------------------------------------------------
1 | #-swf bin/Haxega.swf
2 | -js bin/Haxega.js
3 | #-php bin/php
4 | #-cpp bin/cpp
5 | #-lib haxe-ga
6 | -cp src
7 | -main Main
8 | -swf-version 10
9 | -swf-header 329:21:12:cccccc
10 |
--------------------------------------------------------------------------------
/Haxe-ga.hxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | haxe Haxe-ga.hxml
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | License
2 | =======
3 |
4 | The MIT License (MIT)
5 |
6 | Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
7 |
8 | Permission is hereby granted, free of charge, to any person obtaining a copy
9 | of this software and associated documentation files (the "Software"), to deal
10 | in the Software without restriction, including without limitation the rights
11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | copies of the Software, and to permit persons to whom the Software is
13 | furnished to do so, subject to the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | THE SOFTWARE.
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #haxe-ga
2 |
3 | GoogleAnalytics Client API port to Haxe
4 |
5 | Implementation of a generic server-side Google Analytics client in Haxe that implements nearly every parameter and tracking feature of the original GA Javascript client.
6 |
7 | This project is a port of php-ga (http://code.google.com/p/php-ga/downloads/list), developed by Thomas Bachem.
8 |
9 | *Note that until Android and iOS native SDK gets integrated on this package, this project needs you to provide an ID of a Website to work propperly.*
10 |
11 | ###Simple use Example:
12 |
13 | ```haxe
14 | // This example uses the Stats class. This class automatically creates and persists for
15 | // you all google analytics required objects so users will keep their statistics identities
16 | // through different sessions.
17 | // It also creates a queue on native platforms (CPP) so tracking will goes on a separate
18 | // thread to avoid slowing down the main Thread while tracking.
19 |
20 | import googleAnalytics.Stats;
21 |
22 | class SimpleExample {
23 | function new(){
24 | Stats.init('UA-27265081-3', 'testing.sempaigames.com');
25 | // Stats.init('UA-27265081-3', 'testing.sempaigames.com', true); /* in case you want to use SSL connections */
26 | }
27 |
28 | function trackStuff(){
29 | // track some page views
30 | Stats.trackPageview('/page.html','Page Title!');
31 | Stats.trackPageview('/untitled.html');
32 |
33 | // track some events
34 | Stats.trackEvent('play','stage-1/level-3','begin');
35 | Stats.trackEvent('play','stage-2/level-4','win');
36 | }
37 | }
38 |
39 | ```
40 |
41 | ###Advanced use Example:
42 |
43 | ```haxe
44 | // This example uses the original GoogleAnalytics classes.
45 |
46 | import googleAnalytics.Visitor;
47 | import googleAnalytics.Tracker;
48 | import googleAnalytics.Session;
49 | import googleAnalytics.Page;
50 |
51 | class AdvancedExample {
52 |
53 | private var tracker:Tracker;
54 | private var visitor:Visitor;
55 | private var session:Session;
56 |
57 | function new(){
58 | tracker = new Tracker('UA-27265081-3', 'testing.sempaigames.com');
59 |
60 | // (could also get unserialized from somewhere)
61 | visitor = new Visitor();
62 | visitor.setUserAgent('haXe-ga');
63 | visitor.setScreenResolution('1024x768');
64 | visitor.setLocale('es_AR');
65 |
66 | session = new Session();
67 | }
68 |
69 | function trackPageview(){
70 | // Assemble Page information
71 | var page = new googleAnalytics.Page('/page.html');
72 | page.setTitle('My Page');
73 |
74 | // Track page view
75 | tracker.trackPageview(page, session, visitor);
76 | }
77 | }
78 |
79 | ```
80 |
81 | ###How to Install:
82 |
83 | ```bash
84 | haxelib install haxe-ga
85 | ```
86 |
87 | ###Disclaimer
88 |
89 | Google is a registered trademark of Google Inc.
90 | http://unibrander.com/united-states/140279US/google.html
91 |
92 | ###License
93 |
94 | The MIT License (MIT) - [LICENSE.md](LICENSE.md)
95 |
96 | Copyright © 2012 SempaiGames (http://www.sempaigames.com)
97 |
98 | Author: Federico Bricker
99 |
--------------------------------------------------------------------------------
/src/Main.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package ;
28 |
29 | class Main {
30 |
31 | public static function main() {
32 | trace('Creating Tracker');
33 | var tracker = new googleAnalytics.Tracker('UA-27265081-3', 'testing.sempaigames.com');
34 | trace(tracker);
35 |
36 | trace('Creating Visitor');
37 | // (could also get unserialized from database)
38 | var visitor = new googleAnalytics.Visitor();
39 | visitor.setUserAgent('haXe-ga');
40 | visitor.setScreenResolution('1024x768');
41 | visitor.setLocale('es_AR');
42 | trace(visitor);
43 |
44 | trace('Creating Session');
45 | var session = new googleAnalytics.Session();
46 | trace(session);
47 |
48 | trace('Creating Page');
49 | // Assemble Page information
50 | var page = new googleAnalytics.Page('/page.html');
51 | page.setTitle('My Page');
52 | trace(page);
53 |
54 | trace('Tracking PageView');
55 | // Track page view
56 | tracker.trackPageview(page, session, visitor);
57 | trace(tracker);
58 |
59 | #if (cpp || neko)
60 | Sys.sleep(10);
61 | #end
62 | }
63 |
64 | }
--------------------------------------------------------------------------------
/src/buildPackage.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | dir=`dirname "$0"`
3 | cd "$dir"
4 | rm -f haxe-ga.zip
5 | zip -r haxe-ga haxelib.json include.xml googleAnalytics
6 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Campaign.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 | import googleAnalytics.internals.ParameterHolder;
30 | import googleAnalytics.internals.Util;
31 |
32 | /**
33 | * You should serialize this object and store it in e.g. the user database to keep it
34 | * persistent for the same user permanently (similar to the "__umtz" cookie of
35 | * the GA Javascript client).
36 | */
37 | class Campaign {
38 |
39 | /**
40 | * See self::TYPE_* constants, will be mapped to "__utmz" parameter.
41 | * @see internals.ParameterHolder::$__utmz
42 | */
43 | private var type : String;
44 |
45 | /**
46 | * Time of the creation of this campaign, will be mapped to "__utmz" parameter.
47 | * @see internals.ParameterHolder::$__utmz
48 | */
49 | private var creationTime : DateTime;
50 |
51 | /**
52 | * Response Count, will be mapped to "__utmz" parameter.
53 | * Is also used to determine whether the campaign is new or repeated,
54 | * which will be mapped to "utmcn" and "utmcr" parameters.
55 | * @see internals.ParameterHolder::$__utmz
56 | * @see internals.ParameterHolder::$utmcn
57 | * @see internals.ParameterHolder::$utmcr
58 | */
59 | private var responseCount : Int = 0;
60 |
61 | /**
62 | * Campaign ID, a.k.a. "utm_id" query parameter for ga.js
63 | * Will be mapped to "__utmz" parameter.
64 | * @see internals.ParameterHolder::$__utmz
65 | */
66 | private var id : Int;
67 |
68 | /**
69 | * Source, a.k.a. "utm_source" query parameter for ga.js.
70 | * Will be mapped to "utmcsr" key in "__utmz" parameter.
71 | * @see internals.ParameterHolder::$__utmz
72 | */
73 | private var source : String;
74 |
75 | /**
76 | * Google AdWords Click ID, a.k.a. "gclid" query parameter for ga.js.
77 | * Will be mapped to "utmgclid" key in "__utmz" parameter.
78 | * @see internals.ParameterHolder::$__utmz
79 | */
80 | private var gClickId : String;
81 |
82 | /**
83 | * DoubleClick (?) Click ID. Will be mapped to "utmdclid" key in "__utmz" parameter.
84 | * @see internals.ParameterHolder::$__utmz
85 | */
86 | private var dClickId : String;
87 |
88 | /**
89 | * Name, a.k.a. "utm_campaign" query parameter for ga.js.
90 | * Will be mapped to "utmccn" key in "__utmz" parameter.
91 | * @see internals.ParameterHolder::$__utmz
92 | */
93 | private var name : String;
94 |
95 | /**
96 | * Medium, a.k.a. "utm_medium" query parameter for ga.js.
97 | * Will be mapped to "utmcmd" key in "__utmz" parameter.
98 | * @see internals.ParameterHolder::$__utmz
99 | */
100 | private var medium : String;
101 |
102 | /**
103 | * Terms/Keywords, a.k.a. "utm_term" query parameter for ga.js.
104 | * Will be mapped to "utmctr" key in "__utmz" parameter.
105 | * @see internals.ParameterHolder::$__utmz
106 | */
107 | private var term : String;
108 |
109 | /**
110 | * Ad Content Description, a.k.a. "utm_content" query parameter for ga.js.
111 | * Will be mapped to "utmcct" key in "__utmz" parameter.
112 | * @see internals.ParameterHolder::$__utmz
113 | */
114 | private var content : String;
115 |
116 |
117 | /**
118 | * @const string
119 | */
120 | static inline public var TYPE_DIRECT = 'direct';
121 | /**
122 | * @const string
123 | */
124 | static inline public var TYPE_ORGANIC = 'organic';
125 | /**
126 | * @const string
127 | */
128 | static inline public var TYPE_REFERRAL = 'referral';
129 |
130 |
131 | /**
132 | * @see createFromReferrer
133 | * @param type See TYPE_* constants
134 | */
135 | public function new(type:String) {
136 |
137 | if( type != TYPE_DIRECT && type != TYPE_ORGANIC && type != TYPE_REFERRAL ) {
138 | Tracker._raiseError('Campaign type has to be one of the Campaign::TYPE_* constant values.', 'Campaign.new');
139 | }
140 |
141 | this.type = type;
142 |
143 | switch(type) {
144 | // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignManager.as#375
145 | case /*self.*/TYPE_DIRECT:
146 | this.name = '(direct)';
147 | this.source = '(direct)';
148 | this.medium = '(none)';
149 | // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignManager.as#340
150 | case /*self.*/TYPE_REFERRAL:
151 | this.name = '(referral)';
152 | this.medium = 'referral';
153 | // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignManager.as#280
154 | case /*self.*/TYPE_ORGANIC:
155 | this.name = '(organic)';
156 | this.medium = 'organic';
157 | }
158 |
159 | this.creationTime = new DateTime();
160 | }
161 |
162 | /**
163 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignManager.as#333
164 | * @return googleAnalytics.Campaign
165 | */
166 | public static function createFromReferrer(url:String) {
167 | var instance = new Campaign(TYPE_REFERRAL);
168 |
169 | var urlInfo = new URLParser(url);
170 | instance.source = urlInfo.host;
171 | instance.content = urlInfo.path;
172 | return instance;
173 | }
174 |
175 | /**
176 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignTracker.as#153
177 | */
178 | public function validate() {
179 | // NOTE: gaforflash states that id and gClickId must also be specified,
180 | // but that doesn't seem to be correct
181 | if(this.source == null) {
182 | Tracker._raiseError('Campaigns need to have at least the "source" attribute defined.', 'Campaign.validate');
183 | }
184 | }
185 |
186 | public function setType(type:String) {
187 | this.type = type;
188 | }
189 |
190 | public function getType() : String {
191 | return this.type;
192 | }
193 |
194 | public function setCreationTime(creationTime:DateTime) {
195 | this.creationTime = creationTime;
196 | }
197 |
198 | public function getCreationTime() : DateTime {
199 | return this.creationTime;
200 | }
201 |
202 | public function setResponseCount(responseCount:Int) {
203 | this.responseCount = responseCount;
204 | }
205 |
206 | public function getResponseCount() : Int {
207 | return this.responseCount;
208 | }
209 |
210 | public function increaseResponseCount(byAmount:Int=1) {
211 | this.responseCount += byAmount;
212 | }
213 |
214 | public function setId(id:Int) {
215 | this.id = id;
216 | }
217 |
218 | public function getId() : Int {
219 | return this.id;
220 | }
221 |
222 | public function setSource(source:String) {
223 | this.source = source;
224 | }
225 |
226 | public function getSource() : String {
227 | return this.source;
228 | }
229 |
230 | public function setGClickId(gClickId:String) {
231 | this.gClickId = gClickId;
232 | }
233 |
234 | public function getGClickId() : String {
235 | return this.gClickId;
236 | }
237 |
238 | public function setDClickId(dClickId:String) {
239 | this.dClickId = dClickId;
240 | }
241 |
242 | public function getDClickId() : String {
243 | return this.dClickId;
244 | }
245 |
246 | public function setName(name:String) {
247 | this.name = name;
248 | }
249 |
250 | public function getName() : String {
251 | return this.name;
252 | }
253 |
254 | public function setMedium(medium:String) {
255 | this.medium = medium;
256 | }
257 |
258 | public function getMedium() : String {
259 | return this.medium;
260 | }
261 |
262 | public function setTerm(term:String) {
263 | this.term = term;
264 | }
265 |
266 | public function getTerm() : String {
267 | return this.term;
268 | }
269 |
270 | public function setContent(content:String) {
271 | this.content = content;
272 | }
273 |
274 | public function getContent() : String {
275 | return this.content;
276 | }
277 |
278 | }
279 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Config.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 | /**
30 | * Note: Doesn't necessarily have to be consistent across requests, as it doesn't
31 | * alter the actual tracking result.
32 | *
33 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/GIFRequest.as
34 | */
35 | class Config {
36 |
37 | /**
38 | * How strict should errors get handled? After all, we do just do some
39 | * tracking stuff here, and errors shouldn't break an application's
40 | * functionality in production.
41 | * RECOMMENDATION: Exceptions during deveopment, warnings in production.
42 | * Assign any value of the self::ERROR_SEVERITY_* constants.
43 | * @see Tracker::_raiseError()
44 | */
45 | private var errorSeverity : Int = /*self.*/ERROR_SEVERITY_EXCEPTIONS;
46 |
47 | /**
48 | * Ignore all errors completely.
49 | */
50 | static inline public var ERROR_SEVERITY_SILENCE = 0;
51 | /**
52 | * Trigger PHP errors with a E_USER_TRACE error level.
53 | */
54 | static inline public var ERROR_SEVERITY_TRACE = 1;
55 | /**
56 | * Throw googleAnalytics.Exception exceptions.
57 | */
58 | static inline public var ERROR_SEVERITY_EXCEPTIONS = 2;
59 |
60 | /**
61 | * Whether to just queue all requests on HttpRequest::fire() and actually send
62 | * them on PHP script shutdown after all other tasks are done.
63 | * This has two advantages:
64 | * 1) It effectively doesn't affect app performance
65 | * 2) It can e.g. handle custom variables that were set after scheduling a request
66 | * @see internals.request.HttpRequest::fire()
67 | */
68 | private var sendOnShutdown : Bool = false;
69 |
70 | /**
71 | * Whether to make asynchronous requests to GA without waiting for any
72 | * response (speeds up doing requests).
73 | * @see internals.request.HttpRequest::send()
74 | */
75 | private var fireAndForget : Bool = false;
76 |
77 | /**
78 | * Logging callback, registered via setLoggingCallback(). Will be fired
79 | * whenever a request gets sent out and receives the full HTTP request
80 | * as the first and the full HTTP response (or null if the "fireAndForget"
81 | * option or simulation mode are used) as the second argument.
82 | */
83 | private var loggingCallback : Dynamic;
84 |
85 | /**
86 | * Seconds (float allowed) to wait until timeout when connecting to the
87 | * Google analytics endpoint host
88 | * @see internals.request.HttpRequest::send()
89 | */
90 | private var requestTimeout : Float = 1;
91 |
92 | // FIXME: Add SSL support, https://ssl.google-analytics.com
93 |
94 | /**
95 | * Setting this to 'https' allows analytics to be sent over SSL.
96 | */
97 | private var urlScheme : String = 'http';
98 |
99 | /**
100 | * Google Analytics tracking request endpoint host. Can be set to null to
101 | * silently simulate (and log) requests without actually sending them.
102 | * @see internals.request.HttpRequest::send()
103 | */
104 | private var endPointHost : String = 'www.google-analytics.com';
105 |
106 | /**
107 | * Google Analytics tracking request endpoint path
108 | * @see internals.request.HttpRequest::send()
109 | */
110 | private var endPointPath : String = '/__utm.gif';
111 |
112 | /**
113 | * Defines a new sample set size (0-100) for Site Speed data collection.
114 | * By default, a fixed 1% sampling of your site visitors make up the data pool from which
115 | * the Site Speed metrics are derived.
116 | * @see Page::$loadTime
117 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._setSiteSpeedSampleRate
118 | */
119 | private var sitespeedSampleRate : Int = 1;
120 |
121 | public function new(useSSL:Bool = false) {
122 | setUrlScheme('http' + (useSSL ? 's' : ''));
123 | /*for(property => value in properties) {
124 | // PHP doesn't care about case in method names
125 | setterMethod = 'set' + property;
126 |
127 | if(Reflect.hasMethod(Type.resolveClass_getClass(this), setterMethod)) {
128 | this.setterMethod(value);
129 | } else {
130 | return Tracker._raiseError('There is no setting "' + property + '".', 'Config.new');
131 | }
132 | }*/
133 | }
134 |
135 | /**
136 | * @return int See self::ERROR_SEVERITY_* constants
137 | */
138 | public function getErrorSeverity() : Int {
139 | return this.errorSeverity;
140 | }
141 |
142 | /**
143 | * @param errorSeverity See self::ERROR_SEVERITY_* constants
144 | */
145 | public function setErrorSeverity(errorSeverity:Int) {
146 | this.errorSeverity = errorSeverity;
147 | }
148 |
149 | public function getSendOnShutdown() : Bool {
150 | return this.sendOnShutdown;
151 | }
152 |
153 | public function setSendOnShutdown(sendOnShutdown:Bool) {
154 | this.sendOnShutdown = sendOnShutdown;
155 | }
156 |
157 | public function getFireAndForget() : Bool {
158 | return this.fireAndForget;
159 | }
160 |
161 | public function setFireAndForget(fireAndForget:Bool) {
162 | this.fireAndForget = fireAndForget;
163 | }
164 |
165 | public function getLoggingCallback() : Dynamic {
166 | return this.loggingCallback;
167 | }
168 |
169 | public function setLoggingCallback(cb:Dynamic) {
170 | this.loggingCallback = cb;
171 | }
172 |
173 | public function getRequestTimeout() : Float {
174 | return this.requestTimeout;
175 | }
176 |
177 | public function setRequestTimeout(requestTimeout:Float) {
178 | this.requestTimeout = requestTimeout;
179 | }
180 |
181 | public function getUrlScheme() : String {
182 | return this.urlScheme;
183 | }
184 |
185 | public function setUrlScheme(urlScheme:String) : String {
186 | return this.urlScheme = urlScheme;
187 | }
188 |
189 | public function getEndPointHost() : String {
190 | return this.endPointHost;
191 | }
192 |
193 | public function setEndPointHost(endPointHost:String) {
194 | this.endPointHost = endPointHost;
195 | }
196 |
197 | public function getEndPointPath() : String {
198 | return this.endPointPath;
199 | }
200 |
201 | public function setEndPointPath(endPointPath:String) {
202 | this.endPointPath = endPointPath;
203 | }
204 |
205 | public function getSitespeedSampleRate() : Int {
206 | return this.sitespeedSampleRate;
207 | }
208 |
209 | public function setSitespeedSampleRate(sitespeedSampleRate:Int) {
210 | if(sitespeedSampleRate < 0 || sitespeedSampleRate > 100) {
211 | Tracker._raiseError('For consistency with ga.js, sample rates must be specified as a number between 0 and 100.', 'config.setSitespeedSampleRate');
212 | return;
213 | }
214 | this.sitespeedSampleRate = sitespeedSampleRate;
215 | }
216 | }
--------------------------------------------------------------------------------
/src/googleAnalytics/CustomVariable.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 | import googleAnalytics.internals.Util;
29 |
30 | /**
31 | * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html
32 | */
33 |
34 | class CustomVariable {
35 |
36 | /**
37 | */
38 | private var index : Int;
39 |
40 | /**
41 | * WATCH OUT: It's a known issue that GA will not decode URL-encoded characters
42 | * in custom variable names and values properly, so spaces will show up
43 | * as "%20" in the interface etc.
44 | * @link http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=2cdb3ec0be32e078
45 | */
46 | private var name : String;
47 |
48 | /**
49 | * WATCH OUT: It's a known issue that GA will not decode URL-encoded characters
50 | * in custom variable names and values properly, so spaces will show up
51 | * as "%20" in the interface etc.
52 | * @link http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=2cdb3ec0be32e078
53 | */
54 | private var value : Dynamic;
55 |
56 | /**
57 | * See SCOPE_* constants
58 | */
59 | private var scope : Int = /*self.*/SCOPE_PAGE;
60 |
61 | static inline public var SCOPE_VISITOR = 1;
62 | static inline public var SCOPE_SESSION = 2;
63 | static inline public var SCOPE_PAGE = 3;
64 |
65 |
66 | /**
67 | * @param scope See SCOPE_* constants
68 | */
69 | public function new(index:Int=0, name:String=null, value:Dynamic=null, scope:Int=0) {
70 | if(index != 0) this.setIndex(index);
71 | if(name != null) this.setName(name);
72 | if(value != null) this.setValue(value);
73 | if(scope != 0) this.setScope(scope);
74 | }
75 |
76 | public function validate() : Void {
77 | // According to the GA documentation, there is a limit to the combined size of
78 | // name and value of 64 bytes after URL encoding,
79 | // see http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html#varTypes
80 | // and http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 563
81 | // This limit was increased to 128 bytes BEFORE encoding with the 2012-01 release of ga.js however,
82 | // see http://code.google.com/apis/analytics/community/gajs_changelog.html
83 | if((this.name + this.value).length > 128) {
84 | Tracker._raiseError('Custom Variable combined name and value length must not be larger than 128 bytes.', 'CustomVariable.validate');
85 | }
86 | }
87 |
88 | public function getIndex() : Int {
89 | return this.index;
90 | }
91 |
92 | /**
93 | * @link http://code.google.com/intl/de-DE/apis/analytics/docs/tracking/gaTrackingCustomVariables.html#usage
94 | */
95 | public function setIndex(index:Int) {
96 | // Custom Variables are limited to five slots officially, but there seems to be a
97 | // trick to allow for more of them which we could investigate at a later time (see
98 | // http://analyticsimpact.com/2010/05/24/get-more-than-5-custom-variables-in-google-analytics/)
99 | if(index < 1 || index > 5) {
100 | Tracker._raiseError('Custom Variable index has to be between 1 and 5.', 'CustomVariable.setIndex');
101 | }
102 | this.index = index;
103 | }
104 |
105 | public function getName() : String {
106 | return this.name;
107 | }
108 |
109 | public function setName(name:String) {
110 | this.name = name;
111 | }
112 |
113 | public function getValue() : Dynamic {
114 | return this.value;
115 | }
116 |
117 | public function setValue(value:Dynamic) {
118 | this.value = value;
119 | }
120 |
121 | public function getScope() : Int {
122 | return this.scope;
123 | }
124 |
125 | public function setScope(scope:Int) {
126 | if( scope != SCOPE_PAGE && scope != SCOPE_SESSION && scope != SCOPE_VISITOR ) {
127 | Tracker._raiseError('Custom Variable scope has to be one of the CustomVariable::SCOPE_* constant values.', 'CustomVariable.setScope');
128 | }
129 | this.scope = scope;
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/src/googleAnalytics/DateTime.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 | class DateTime {
30 | private var date : String;
31 | public function new(current:String = null) {
32 | if (current == null) {
33 |
34 | date = Math.round(Date.now().getTime())+'';
35 | }else {
36 | date = current;
37 | }
38 | }
39 |
40 | public function toString():String{
41 | return date;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Event.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 | /**
30 | * @link http://code.google.com/apis/analytics/docs/tracking/eventTrackerOverview.html
31 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html
32 | */
33 |
34 | class Event {
35 |
36 | /**
37 | * The general event category (e.g. "Videos").
38 | */
39 | private var category : String;
40 |
41 | /**
42 | * The action for the event (e.g. "Play").
43 | */
44 | private var action : String;
45 |
46 | /**
47 | * An optional descriptor for the event (e.g. the video's title).
48 | */
49 | private var label : String;
50 |
51 | /**
52 | * An optional value associated with the event. You can see your event values in the Overview,
53 | * Categories, and Actions reports, where they are listed by event or aggregated across events,
54 | * depending upon your report view.
55 | */
56 | private var value : Int;
57 |
58 | /**
59 | * Default value is false. By default, event hits will impact a visitor's bounce rate.
60 | * By setting this parameter to true, this event hit will not be used in bounce rate calculations.
61 | */
62 | private var noninteraction : Bool = false;
63 |
64 |
65 | public function new(category:String=null, action:String=null, label:String=null, value:Int=0, noninteraction:Bool=false) {
66 | if(category != null) this.setCategory(category);
67 | if(action != null) this.setAction(action);
68 | if(label != null) this.setLabel(label);
69 | this.setValue(value);
70 | this.setNoninteraction(noninteraction);
71 | }
72 |
73 | public function validate() : Void {
74 | if(this.category == null || this.action == null) {
75 | Tracker._raiseError('Events need at least to have a category and action defined.', 'Event.validate');
76 | }
77 | }
78 |
79 | public function getCategory() : String {
80 | return this.category;
81 | }
82 |
83 | public function setCategory(category:String) {
84 | this.category = category;
85 | }
86 |
87 | public function getAction() : String {
88 | return this.action;
89 | }
90 |
91 | public function setAction(action:String) {
92 | this.action = action;
93 | }
94 |
95 | public function getLabel() : String {
96 | return this.label;
97 | }
98 |
99 | public function setLabel(label:String) {
100 | this.label = label;
101 | }
102 |
103 | public function getValue() : Int {
104 | return this.value;
105 | }
106 |
107 | public function setValue(value:Int) {
108 | this.value = value;
109 | }
110 |
111 | public function getNoninteraction() : Bool {
112 | return this.noninteraction;
113 | }
114 |
115 | public function setNoninteraction(value:Bool) {
116 | this.noninteraction = value;
117 | }
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Item.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 | /**
30 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/ecommerce/Item.as
31 | */
32 | class Item {
33 |
34 | /**
35 | * Order ID, e.g. "a2343898", will be mapped to "utmtid" parameter
36 | * @see internals.ParameterHolder::$utmtid
37 | */
38 | private var orderId : String;
39 |
40 | /**
41 | * Product Code. This is the sku code for a given product, e.g. "989898ajssi",
42 | * will be mapped to "utmipc" parameter
43 | * @see internals.ParameterHolder::$utmipc
44 | */
45 | private var sku : String;
46 |
47 | /**
48 | * Product Name, e.g. "T-Shirt", will be mapped to "utmipn" parameter
49 | * @see internals.ParameterHolder::$utmipn
50 | */
51 | private var name : String;
52 |
53 | /**
54 | * Variations on an item, e.g. "white", "black", "green" etc., will be mapped
55 | * to "utmiva" parameter
56 | * @see internals.ParameterHolder::$utmiva
57 | */
58 | private var variation : String;
59 |
60 | /**
61 | * Unit Price. Value is set to numbers only (e.g. 19.95), will be mapped to
62 | * "utmipr" parameter
63 | * @see internals.ParameterHolder::$utmipr
64 | */
65 | private var price : Float;
66 |
67 | /**
68 | * Unit Quantity, e.g. 4, will be mapped to "utmiqt" parameter
69 | * @see internals.ParameterHolder::$utmiqt
70 | */
71 | private var quantity : Int = 1;
72 |
73 |
74 | public function validate() : Void {
75 | if(this.sku == null) {
76 | Tracker._raiseError('Items need to have a sku/product code defined.', 'Item.validate');
77 | }
78 | }
79 |
80 | public function getOrderId() : String {
81 | return this.orderId;
82 | }
83 |
84 | public function setOrderId(orderId:String) {
85 | this.orderId = orderId;
86 | }
87 |
88 | public function getSku() : String {
89 | return this.sku;
90 | }
91 |
92 | public function setSku(sku:String) {
93 | this.sku = sku;
94 | }
95 |
96 | public function getName() : String {
97 | return this.name;
98 | }
99 |
100 | public function setName(name:String) {
101 | this.name = name;
102 | }
103 |
104 | public function getVariation() : String {
105 | return this.variation;
106 | }
107 |
108 | public function setVariation(variation:String) {
109 | this.variation = variation;
110 | }
111 |
112 | public function getPrice() : Float {
113 | return this.price;
114 | }
115 |
116 | public function setPrice(price:Float) {
117 | this.price = price;
118 | }
119 |
120 | public function getQuantity() : Int {
121 | return this.quantity;
122 | }
123 |
124 | public function setQuantity(quantity:Int) {
125 | this.quantity = quantity;
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Page.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 | class Page {
30 |
31 | /**
32 | * Page request URI, e.g. "/path/page.html", will be mapped to
33 | * "utmp" parameter
34 | * @see internals.ParameterHolder::$utmp
35 | */
36 | private var path : String;
37 |
38 | /**
39 | * Page title, will be mapped to "utmdt" parameter
40 | * @see internals.ParameterHolder::$utmdt
41 | */
42 | private var title : String;
43 |
44 | /**
45 | * Charset encoding (e.g. "UTF-8"), will be mapped to "utmcs" parameter
46 | * @see internals.ParameterHolder::$utmcs
47 | */
48 | private var charset : String;
49 |
50 | /**
51 | * Referer URL, e.g. "http://www.example.com/path/page.html", will be
52 | * mapped to "utmr" parameter
53 | * @see internals.ParameterHolder::$utmr
54 | */
55 | private var referrer : String;
56 |
57 | /**
58 | * Page load time in milliseconds, will be encoded into "utme" parameter.
59 | * @see internals.ParameterHolder::$utme
60 | */
61 | private var loadTime : Int;
62 |
63 |
64 | /**
65 | * Constant to mark referrer as a site-internal one.
66 | *
67 | * @see Page::$referrer
68 | * @const string
69 | */
70 | static inline public var REFERRER_INTERNAL = '0';
71 |
72 |
73 | public function new(path:String) {
74 | this.setPath(path);
75 | }
76 |
77 | public function setPath(path:String) {
78 | if(path!=null && path.charAt(0) != '/') {
79 | Tracker._raiseError('The page path should always start with a slash ("/").','Page.setPath');
80 | }
81 |
82 | this.path = path;
83 | }
84 |
85 | public function getPath() : String {
86 | return this.path;
87 | }
88 |
89 | public function setTitle(title:String) {
90 | this.title = title;
91 | }
92 |
93 | public function getTitle() : String {
94 | return this.title;
95 | }
96 |
97 | public function setCharset(encoding) {
98 | this.charset = encoding;
99 | }
100 |
101 | public function getCharset() : String {
102 | return this.charset;
103 | }
104 |
105 | public function setReferrer(referrer:String) {
106 | this.referrer = referrer;
107 | }
108 |
109 | public function getReferrer() : String {
110 | return this.referrer;
111 | }
112 |
113 | public function setLoadTime(loadTime:Int) {
114 | this.loadTime = loadTime;
115 | }
116 |
117 | public function getLoadTime() : Int {
118 | return this.loadTime;
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Session.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 | import googleAnalytics.internals.Util;
30 |
31 | /**
32 | * You should serialize this object and store it in the user session to keep it
33 | * persistent between requests (similar to the "__umtb" cookie of
34 | * the GA Javascript client).
35 | */
36 | class Session {
37 |
38 | /**
39 | * A unique per-session ID, will be mapped to "utmhid" parameter
40 | * @see internals.ParameterHolder::$utmhid
41 | */
42 | private var sessionId : Int;
43 |
44 | /**
45 | * The amount of pageviews that were tracked within this session so far,
46 | * will be part of the "__utmb" cookie parameter.
47 | * Will get incremented automatically upon each request.
48 | * @see internals.ParameterHolder::$__utmb
49 | * @see internals.request\Request::buildHttpRequest()
50 | */
51 | private var trackCount : Int;
52 |
53 | /**
54 | * Timestamp of the start of this new session, will be part of the "__utmb"
55 | * cookie parameter
56 | * @see internals.ParameterHolder::$__utmb
57 | */
58 | private var startTime : DateTime;
59 |
60 |
61 | public function new() : Void {
62 | this.setSessionId(this.generateSessionId());
63 | this.setTrackCount(0);
64 | this.setStartTime(new DateTime());
65 | }
66 |
67 | /**
68 | * Will extract information for the "trackCount" and "startTime"
69 | * properties from the given "__utmb" cookie value.
70 | * @see internals.ParameterHolder::$__utmb
71 | * @see internals.request\Request::buildCookieParameters()
72 | * @return $this
73 | */
74 | public function fromUtmb(value:String) {
75 | var parts : Array = value.split('.');
76 | if(parts.length != 4) {
77 | Tracker._raiseError('The given "__utmb" cookie value is invalid.', 'Session.fromUtmb');
78 | return this;
79 | }
80 |
81 | this.setTrackCount(Util.parseInt(parts[1],0));
82 | this.setStartTime(new DateTime(parts[3]));
83 |
84 | // Allow chaining
85 | return this;
86 | }
87 |
88 | /**
89 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/DocumentInfo.as#52
90 | */
91 | private function generateSessionId() : Int {
92 | // TODO: Integrate AdSense support
93 | return Util.generate32bitRandom();
94 | }
95 |
96 | public function getSessionId() : Int {
97 | return this.sessionId;
98 | }
99 |
100 | public function setSessionId(sessionId:Int) {
101 | this.sessionId = sessionId;
102 | }
103 |
104 | public function getTrackCount() : Int {
105 | return this.trackCount;
106 | }
107 |
108 | public function setTrackCount(trackCount:Int) {
109 | this.trackCount = trackCount;
110 | }
111 |
112 | public function increaseTrackCount(byAmount:Int=1) {
113 | this.trackCount += byAmount;
114 | }
115 |
116 | public function getStartTime() : DateTime {
117 | return this.startTime;
118 | }
119 |
120 | public function setStartTime(startTime:DateTime) {
121 | this.startTime = startTime;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/googleAnalytics/SocialInteraction.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 |
30 | class SocialInteraction {
31 |
32 | /**
33 | * Required. A string representing the social network being tracked (e.g. "Facebook", "Twitter", "LinkedIn", ...),
34 | * will be mapped to "utmsn" parameter
35 | * @see internals.ParameterHolder::$utmsn
36 | */
37 | private var network : String;
38 |
39 | /**
40 | * Required. A string representing the social action being tracked (e.g. "Like", "Share", "Tweet", ...),
41 | * will be mapped to "utmsa" parameter
42 | * @see internals.ParameterHolder::$utmsa
43 | */
44 | private var action : String;
45 |
46 | /**
47 | * Optional. A string representing the URL (or resource) which receives the action. For example,
48 | * if a user clicks the Like button on a page on a site, the the target might be set to the title
49 | * of the page, or an ID used to identify the page in a content management system. In many cases,
50 | * the page you Like is the same page you are on. So if this parameter is not given, we will default
51 | * to using the path of the corresponding Page object.
52 | * @see internals.ParameterHolder::$utmsid
53 | */
54 | private var target : String;
55 |
56 |
57 | public function new(network=null, action=null, target=null) {
58 | if(network != null) this.setNetwork(network);
59 | if(action != null) this.setAction(action);
60 | if(target != null) this.setTarget(target);
61 | }
62 |
63 | public function validate() : Void {
64 | if(this.network == null || this.action == null) {
65 | Tracker._raiseError('Social interactions need to have at least the "network" and "action" attributes defined.', 'SocialInteraction.validate');
66 | }
67 | }
68 |
69 | public function setNetwork(network:String) {
70 | this.network = network;
71 | }
72 |
73 | public function getNetwork() : String {
74 | return this.network;
75 | }
76 |
77 | public function setAction(action:String) {
78 | this.action = action;
79 | }
80 |
81 | public function getAction() : String {
82 | return this.action;
83 | }
84 |
85 | public function setTarget(target:String) {
86 | this.target = target;
87 | }
88 |
89 | public function getTarget() : String {
90 | return this.target;
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Stats.hx:
--------------------------------------------------------------------------------
1 | package googleAnalytics;
2 |
3 | #if (flash || openfl)
4 | import extension.locale.Locale;
5 | import flash.net.SharedObject;
6 | import flash.system.Capabilities;
7 | import flash.Lib;
8 | import haxe.Unserializer;
9 | import haxe.Serializer;
10 | #end
11 | #if js
12 | import extension.locale.Locale;
13 | import haxe.Unserializer;
14 | import haxe.Serializer;
15 | #end
16 |
17 | class Stats {
18 |
19 | private static var accountId:String=null;
20 | private static var cache:Map=null;
21 | private static var domainName:String=null;
22 | private static var paused:Bool=false;
23 | private static var session:Session=null;
24 | private static var tracker:Tracker=null;
25 | private static var visitor:Visitor=null;
26 |
27 | public static function init(accountId:String,domainName:String,useSSL:Bool=false){
28 | if(Stats.accountId!=null) return;
29 | Stats.accountId=accountId;
30 | Stats.domainName=domainName;
31 | tracker = new Tracker(accountId,domainName,new Config(useSSL));
32 | cache = new Map();
33 | session = new Session();
34 | loadVisitor();
35 | }
36 |
37 | public static function trackPageview(path:String,title:String=null){
38 | var hash='page:'+path;
39 | if(!cache.exists(hash)){
40 | var p=new Page(path);
41 | if(title!=null) p.setTitle(title);
42 | cache.set(hash,new GATrackObject(p,null));
43 | }
44 | Stats.track(hash);
45 | }
46 |
47 | public static function trackEvent(category:String,event:String,label:String,value:Int=0){
48 | var hash='event:'+category+'/'+event+'/'+label+':'+value;
49 | if(!cache.exists(hash)){
50 | cache.set(hash,new GATrackObject(null,new Event(category,event,label,value)));
51 | }
52 | Stats.track(hash);
53 | }
54 |
55 | private static function track(hash:String){
56 | if(paused) return;
57 | cache.get(hash).track(tracker,visitor,session);
58 | Stats.persistVisitor();
59 | }
60 |
61 | public static function pause() {
62 | paused = true;
63 | }
64 |
65 | public static function resume() {
66 | paused = false;
67 | }
68 |
69 | private static function loadVisitor(){
70 | var version:String=" [haxe]";
71 | visitor = new Visitor();
72 | #if (flash || openfl)
73 | var ld:SharedObject=SharedObject.getLocal('ga-visitor');
74 | if(ld.data!=null && ld.data.gaVisitor!=null){
75 | try{
76 | visitor=Unserializer.run(ld.data.gaVisitor);
77 | }catch(e:Dynamic){
78 | visitor = new Visitor();
79 | }
80 | }
81 | #end
82 |
83 | #if js
84 | try{
85 | visitor=Unserializer.run(js.Cookie.get('MUSES_TRACKING'));
86 | }catch(e:Dynamic){
87 | visitor = new Visitor();
88 | }
89 | #end
90 |
91 | #if (openfl && !flash && !html5)
92 | #if (!openfl_legacy)
93 | version+="/" + Lib.application.config.packageName + "." + Lib.application.config.version;
94 | #else
95 | version+="/" + Lib.packageName + "." + Lib.version;
96 | #end
97 | #end
98 |
99 | #if ios
100 | visitor.setUserAgent('iOS'+version);
101 | #elseif android
102 | visitor.setUserAgent('Android'+version);
103 | #elseif mac
104 | visitor.setUserAgent('OS-X'+version);
105 | #elseif tizen
106 | visitor.setUserAgent("Tizen"+version);
107 | #elseif blackberry
108 | visitor.setUserAgent("BlackBerry"+version);
109 | #elseif windows
110 | visitor.setUserAgent("Windows"+version);
111 | #elseif linux
112 | visitor.setUserAgent("Linux"+version);
113 | #elseif js
114 | visitor.setUserAgent("JS"+version);
115 | #else
116 | visitor.setUserAgent('-not-set-'+version);
117 | #end
118 |
119 | #if (flash || openfl)
120 | visitor.setScreenResolution(''+Capabilities.screenResolutionX+'x'+Capabilities.screenResolutionY);
121 | visitor.setLocale(Locale.getLangCode());
122 | #elseif js
123 | if(js.Browser.window != null){
124 | visitor.setScreenResolution(js.Browser.window.screen.availWidth+'x'+js.Browser.window.screen.availHeight);
125 | visitor.setLocale(js.Browser.navigator.language);
126 | visitor.setUserAgent(js.Browser.navigator.userAgent);
127 | }else{
128 | visitor.setScreenResolution('1024x768');
129 | visitor.setLocale(Locale.getLangCode());
130 | }
131 | #else
132 | visitor.setScreenResolution('1024x768');
133 | visitor.setLocale('en_US');
134 | #end
135 |
136 | visitor.getUniqueId();
137 | visitor.addSession(session);
138 | Stats.persistVisitor();
139 | }
140 |
141 | private static function persistVisitor(){
142 | try{
143 | #if (flash || openfl)
144 | var ld=SharedObject.getLocal('ga-visitor');
145 | var old_USE_CACHE = Serializer.USE_CACHE;
146 | Serializer.USE_CACHE = true;
147 | ld.data.gaVisitor = Serializer.run(visitor);
148 | Serializer.USE_CACHE = old_USE_CACHE;
149 | ld.flush();
150 | #elseif js
151 | var old_USE_CACHE = Serializer.USE_CACHE;
152 | Serializer.USE_CACHE = true;
153 | var data = Serializer.run(visitor);
154 | Serializer.USE_CACHE = old_USE_CACHE;
155 | js.Cookie.set('MUSES_TRACKING',data,3600*24*365);
156 | #end
157 | }catch( e:Dynamic ){
158 | trace("Error while saving Google Analytics Visitor!");
159 | }
160 | }
161 |
162 | }
163 |
164 | private class GATrackObject {
165 |
166 | private var event:Event;
167 | private var page:Page;
168 |
169 | public function new(page:Page,event:Event) {
170 | this.page=page;
171 | this.event=event;
172 | }
173 |
174 | public function track(tracker:Tracker,visitor:Visitor,session:Session){
175 | if(this.page!=null){
176 | tracker.trackPageview(page,session,visitor);
177 | }
178 | if(this.event!=null){
179 | tracker.trackEvent(event,session,visitor);
180 | }
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/src/googleAnalytics/ThreadedSocketRequest.hx:
--------------------------------------------------------------------------------
1 | package googleAnalytics;
2 |
3 | #if cpp
4 | import cpp.vm.Thread;
5 | #elseif neko
6 | import neko.vm.Thread;
7 | #end
8 |
9 | class ThreadedSocketRequest {
10 |
11 | #if ( cpp || neko )
12 |
13 | private static var thread:Thread;
14 | private static var initted:Bool=false;
15 |
16 | public static function init() {
17 | if(initted) return;
18 | initted=true;
19 | thread = Thread.create(onThreadMessage);
20 | }
21 |
22 | private static function onThreadMessage(){
23 | var s:sys.net.Socket = null;
24 | var msg:String = null;
25 | while(true){
26 | try {
27 | msg = Thread.readMessage(true);
28 | if ( msg == null ) continue;
29 | var t1:Float = Sys.time();
30 | s = new sys.net.Socket();
31 | s.setTimeout(2);
32 | s.connect(new sys.net.Host("www.google-analytics.com"),80);
33 | s.write(msg);
34 | s.input.readLine();
35 | var t2:Float = Sys.time();
36 | // trace(Math.round((t2-t1)*1000)+"ms ");
37 | } catch(e:Dynamic) {
38 | // trace("Exception: "+e);
39 | }
40 |
41 | try {
42 | if(s!=null){
43 | s.close();
44 | s=null;
45 | }
46 | } catch(e:Dynamic) {
47 | // trace("Closing Exception: "+e);
48 | }
49 | }
50 | }
51 |
52 | #end
53 |
54 | public static function request(url:String, userAgent:String){
55 | #if ( cpp || neko )
56 | init();
57 | thread.sendMessage("GET "+url+" HTTP/1.1\nUser-Agent: "+userAgent+"\n\n");
58 | #end
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Tracker.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 | import googleAnalytics.internals.Util;
30 | import googleAnalytics.internals.request.PageviewRequest;
31 | import googleAnalytics.internals.request.EventRequest;
32 | import googleAnalytics.internals.request.TransactionRequest;
33 | import googleAnalytics.internals.request.ItemRequest;
34 | import googleAnalytics.internals.request.SocialInteractionRequest;
35 |
36 |
37 | class Tracker {
38 |
39 | /**
40 | * Google Analytics client version on which this library is built upon,
41 | * will be mapped to "utmwv" parameter.
42 | *
43 | * This doesn't necessarily mean that all features of the corresponding
44 | * ga.js version are implemented but rather that the requests comply
45 | * with these of ga.js.
46 | *
47 | * @link http://code.google.com/apis/analytics/docs/gaJS/changelog.html
48 | * @const string
49 | */
50 |
51 | static inline public var VERSION:String = '5.2.5'; // As of 25.02.2012
52 |
53 |
54 | /**
55 | * The configuration to use for all tracker instances.
56 | */
57 | private static var config : Config;
58 |
59 | /**
60 | * Google Analytics account ID, e.g. "UA-1234567-8", will be mapped to
61 | * "utmac" parameter
62 | * @see internals.ParameterHolder::$utmac
63 | */
64 | private var accountId : String;
65 |
66 | /**
67 | * Host Name, e.g. "www.example.com", will be mapped to "utmhn" parameter
68 | * @see internals.ParameterHolder::$utmhn
69 | */
70 | private var domainName : String;
71 |
72 | /**
73 | * Whether to generate a unique domain hash, default is true to be consistent
74 | * with the GA Javascript Client
75 | * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#setAllowHash
76 | * @see internals.request\Request::generateDomainHash()
77 | */
78 | private var allowHash : Bool = true;
79 |
80 | private var customVariables : Array;
81 |
82 | private var campaign : Campaign;
83 |
84 |
85 | public function new(accountId:String, domainName:String, config:Config=null) {
86 | customVariables = new Array();
87 | setConfig(config!=null ? config : new Config());
88 | this.setAccountId(accountId);
89 | this.setDomainName(domainName);
90 | }
91 |
92 | public static function getConfig() : Config {
93 | return config;
94 | }
95 |
96 | public static function setConfig(config:Config) {
97 | Tracker.config = config;
98 | }
99 |
100 | public function setAccountId(value:String) {
101 | var r = ~/^(UA|MO)-[0-9]*-[0-9]*$/;
102 | if(!r.match(value)) {
103 | _raiseError('"' + value + '" is not a valid Google Analytics account ID.', 'Tracker.setAccountId');
104 | }
105 |
106 | this.accountId = value;
107 | }
108 |
109 | public function getAccountId() : String {
110 | return this.accountId;
111 | }
112 |
113 | public function setDomainName(value:String) {
114 | this.domainName = value;
115 | }
116 |
117 | public function getDomainName() : String {
118 | return this.domainName;
119 | }
120 |
121 | public function setAllowHash(value:Bool) {
122 | this.allowHash = value;
123 | }
124 |
125 | public function getAllowHash() : Bool {
126 | return this.allowHash;
127 | }
128 |
129 | /**
130 | * Equivalent of _setCustomVar() in GA Javascript client.
131 | * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html
132 | */
133 | public function addCustomVariable(customVariable:CustomVariable) {
134 | // Ensure that all required parameters are set
135 | customVariable.validate();
136 | customVariables[customVariable.getIndex()] = customVariable;
137 | }
138 |
139 | public function getCustomVariables() : Array {
140 | return this.customVariables;
141 | }
142 |
143 | /**
144 | * Equivalent of _deleteCustomVar() in GA Javascript client.
145 | */
146 | public function removeCustomVariable(index:Int) {
147 | customVariables.remove(customVariables[index]);
148 | }
149 |
150 | /**
151 | * @param googleAnalytics.Campaign $campaign Isn't really optional, but can be set to null
152 | */
153 | public function setCampaign(campaign:Campaign=null) {
154 | if(campaign!=null) {
155 | // Ensure that all required parameters are set
156 | campaign.validate();
157 | }
158 |
159 | this.campaign = campaign;
160 | }
161 |
162 | public function getCampaign() : Campaign {
163 | return this.campaign;
164 | }
165 |
166 | /**
167 | * Equivalent of _trackPageview() in GA Javascript client.
168 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview
169 | */
170 | public function trackPageview(page:Page, session:Session, visitor:Visitor) {
171 | var request = new PageviewRequest(config);
172 | request.setPage(page);
173 | request.setSession(session);
174 | request.setVisitor(visitor);
175 | request.setTracker(this);
176 | request.send();
177 | }
178 |
179 | /**
180 | * Equivalent of _trackEvent() in GA Javascript client.
181 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html#_gat.GA_EventTracker_._trackEvent
182 | */
183 | public function trackEvent(event:Event, session:Session, visitor:Visitor) {
184 | // Ensure that all required parameters are set
185 | event.validate();
186 |
187 | var request = new EventRequest(config);
188 | request.setEvent(event);
189 | request.setSession(session);
190 | request.setVisitor(visitor);
191 | request.setTracker(this);
192 | request.send();
193 | }
194 |
195 | /**
196 | * Combines _addTrans(), _addItem() (indirectly) and _trackTrans() of GA Javascript client.
197 | * Although the naming of "_addTrans()" would suggest multiple possible transactions
198 | * per request, there is just one allowed actually.
199 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans
200 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addItem
201 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._trackTrans
202 | */
203 | public function trackTransaction(transaction:Transaction, session:Session, visitor:Visitor) {
204 | // Ensure that all required parameters are set
205 | transaction.validate();
206 |
207 | var transactionRequest = new TransactionRequest(config);
208 | transactionRequest.setTransaction(transaction);
209 | transactionRequest.setSession(session);
210 | transactionRequest.setVisitor(visitor);
211 | transactionRequest.setTracker(this);
212 | transactionRequest.send();
213 |
214 | // Every item gets a separate request,
215 | // see http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#312
216 | var item:Item;
217 | for(item in transaction.getItems()) {
218 | // Ensure that all required parameters are set
219 | item.validate();
220 |
221 | var itemRequest = new ItemRequest(config);
222 | itemRequest.setItem(item);
223 | itemRequest.setSession(session);
224 | itemRequest.setVisitor(visitor);
225 | itemRequest.setTracker(this);
226 | itemRequest.send();
227 | }
228 | }
229 |
230 | /**
231 | * Equivalent of _trackSocial() in GA Javascript client.
232 | * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingSocial.html#settingUp
233 | */
234 | public function trackSocial(socialInteraction:SocialInteraction, page:Page, session:Session, visitor:Visitor) {
235 | var request = new SocialInteractionRequest(config);
236 | request.setSocialInteraction(socialInteraction);
237 | request.setPage(page);
238 | request.setSession(session);
239 | request.setVisitor(visitor);
240 | request.setTracker(this);
241 | request.send();
242 | }
243 |
244 | /**
245 | * For internal use only. Will trigger an error according to the current
246 | * Config::$errorSeverity setting.
247 | * @see Config::$errorSeverity
248 | */
249 | public static function _raiseError(message:String, method:String) {
250 | message = method + '(): ' + message;
251 | var errorSeverity:Int = config!=null ? config.getErrorSeverity() : Config.ERROR_SEVERITY_SILENCE;
252 | switch(errorSeverity) {
253 | case Config.ERROR_SEVERITY_TRACE: trace(message);
254 | case Config.ERROR_SEVERITY_EXCEPTIONS: throw message;
255 | case Config.ERROR_SEVERITY_SILENCE: // Do nothing
256 | default:
257 | }
258 | }
259 |
260 | }
261 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Transaction.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 |
30 | /**
31 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/ecommerce/Transaction.as
32 | */
33 | class Transaction {
34 |
35 | /**
36 | * Order ID, e.g. "a2343898", will be mapped to "utmtid" parameter
37 | * @see internals.ParameterHolder::$utmtid
38 | */
39 | private var orderId : String;
40 |
41 | /**
42 | * Affiliation, Will be mapped to "utmtst" parameter
43 | * @see internals.ParameterHolder::$utmtst
44 | */
45 | private var affiliation : String;
46 |
47 | /**
48 | * Total Cost, will be mapped to "utmtto" parameter
49 | * @see internals.ParameterHolder::$utmtto
50 | */
51 | private var total : Float;
52 |
53 | /**
54 | * Tax Cost, will be mapped to "utmttx" parameter
55 | * @see internals.ParameterHolder::$utmttx
56 | */
57 | private var tax : Float;
58 |
59 | /**
60 | * Shipping Cost, values as for unit and price, e.g. 3.95, will be mapped to
61 | * "utmtsp" parameter
62 | * @see internals.ParameterHolder::$utmtsp
63 | */
64 | private var shipping : Float;
65 |
66 | /**
67 | * Billing City, e.g. "Cologne", will be mapped to "utmtci" parameter
68 | * @see internals.ParameterHolder::$utmtci
69 | */
70 | private var city : String;
71 |
72 | /**
73 | * Billing Region, e.g. "North Rhine-Westphalia", will be mapped to "utmtrg" parameter
74 | * @see internals.ParameterHolder::$utmtrg
75 | */
76 | private var region : String;
77 |
78 | /**
79 | * Billing Country, e.g. "Germany", will be mapped to "utmtco" parameter
80 | * @see internals.ParameterHolder::$utmtco
81 | */
82 | private var country : String;
83 |
84 | /**
85 | * @see Transaction::addItem()
86 | */
87 | private var items : Map;
88 |
89 | public function new() {
90 | items = new Map();
91 | }
92 |
93 | public function validate() : Void {
94 | if(this.items==null) {
95 | Tracker._raiseError('Transactions need to consist of at least one item.', 'Transaction.validate');
96 | }
97 | }
98 |
99 | /**
100 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addItem
101 | */
102 | public function addItem(item:Item) {
103 | // Associated items inherit the transaction's order ID
104 | item.setOrderId(this.orderId);
105 | items.set(item.getSku(),item);
106 | }
107 |
108 | public function getItems() : Map {
109 | return this.items;
110 | }
111 |
112 | public function getOrderId() : String {
113 | return this.orderId;
114 | }
115 |
116 | public function setOrderId(orderId:String) {
117 | this.orderId = orderId;
118 |
119 | // Update order IDs of all associated items too
120 | for(item in this.items) {
121 | item.setOrderId(orderId);
122 | }
123 | }
124 |
125 | public function getAffiliation() : String {
126 | return this.affiliation;
127 | }
128 |
129 | public function setAffiliation(affiliation:String) {
130 | this.affiliation = affiliation;
131 | }
132 |
133 | public function getTotal() : Float {
134 | return this.total;
135 | }
136 |
137 | public function setTotal(total:Float) {
138 | this.total = total;
139 | }
140 |
141 | public function getTax() : Float {
142 | return this.tax;
143 | }
144 |
145 | public function setTax(tax:Float) {
146 | this.tax = tax;
147 | }
148 |
149 | public function getShipping() : Float {
150 | return this.shipping;
151 | }
152 |
153 | public function setShipping(shipping:Float) {
154 | this.shipping = shipping;
155 | }
156 |
157 | public function getCity() : String {
158 | return this.city;
159 | }
160 |
161 | public function setCity(city:String) {
162 | this.city = city;
163 | }
164 |
165 | public function getRegion() : String {
166 | return this.region;
167 | }
168 |
169 | public function setRegion(region:String) {
170 | this.region = region;
171 | }
172 |
173 | public function getCountry() : String {
174 | return this.country;
175 | }
176 |
177 | public function setCountry(country:String) {
178 | this.country = country;
179 | }
180 |
181 | }
182 |
--------------------------------------------------------------------------------
/src/googleAnalytics/URLParser.hx:
--------------------------------------------------------------------------------
1 | package googleAnalytics;
2 |
3 | /**
4 | * Generic Server-Side Google Analytics Haxe Client
5 | *
6 | * This library is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License (LGPL) as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This library is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this library; if not, write to the Free Software
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 | *
20 | * Google Analytics is a registered trademark of Google Inc.
21 | *
22 | * @link http://haxe.org/doc/snip/uri_parser
23 | *
24 | * @license http://www.gnu.org/licenses/lgpl.html
25 | * @author Mike Cann
26 | */
27 |
28 | import haxe.Http;
29 |
30 | class URLParser
31 | {
32 | // Publics
33 | public var url : String;
34 | public var source : String;
35 | public var protocol : String;
36 | public var authority : String;
37 | public var userInfo : String;
38 | public var user : String;
39 | public var password : String;
40 | public var host : String;
41 | public var port : String;
42 | public var relative : String;
43 | public var path : String;
44 | public var directory : String;
45 | public var file : String;
46 | public var query : String;
47 | public var anchor : String;
48 |
49 | private static var parts : Array = ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];
50 |
51 | public function new(url:String)
52 | {
53 | // Save for 'ron
54 | this.url = url;
55 |
56 | // The almighty regexp (courtesy of http://blog.stevenlevithan.com/archives/parseuri)
57 | var r : EReg = ~/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
58 |
59 | // Match the regexp to the url
60 | r.match(url);
61 |
62 | // Use reflection to set each part
63 | for (i in 0...parts.length)
64 | {
65 | Reflect.setField(this, parts[i], r.matched(i));
66 | }
67 | }
68 |
69 | public function toString() : String
70 | {
71 | var s : String = "For Url -> " + url + "\n";
72 | for (i in 0...parts.length)
73 | {
74 | s += parts[i] + ": " + Reflect.field(this, parts[i]) + (i==parts.length-1?"":"\n");
75 | }
76 | return s;
77 | }
78 |
79 | public static function parse(url:String) : URLParser
80 | {
81 | return new URLParser(url);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/googleAnalytics/Visitor.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics;
28 |
29 | import googleAnalytics.internals.Util;
30 |
31 | /**
32 | * You should serialize this object and store it in the user database to keep it
33 | * persistent for the same user permanently (similar to the "__umta" cookie of
34 | * the GA Javascript client).
35 | */
36 | class Visitor {
37 |
38 | /**
39 | * Unique user ID, will be part of the "__utma" cookie parameter
40 | * @see internals.ParameterHolder::$__utma
41 | */
42 | private var uniqueId : Int;
43 |
44 | /**
45 | * Time of the very first visit of this user, will be part of the "__utma"
46 | * cookie parameter
47 | * @see internals.ParameterHolder::$__utma
48 | */
49 | private var firstVisitTime : DateTime;
50 |
51 | /**
52 | * Time of the previous visit of this user, will be part of the "__utma"
53 | * cookie parameter
54 | * @see internals.ParameterHolder::$__utma
55 | * @see addSession
56 | */
57 | private var previousVisitTime : DateTime;
58 |
59 | /**
60 | * Time of the current visit of this user, will be part of the "__utma"
61 | * cookie parameter
62 | * @see internals.ParameterHolder::$__utma
63 | * @see addSession
64 | */
65 | private var currentVisitTime : DateTime;
66 |
67 | /**
68 | * Amount of total visits by this user, will be part of the "__utma"
69 | * cookie parameter
70 | * @see internals.ParameterHolder::$__utma
71 | */
72 | private var visitCount : Int;
73 |
74 | /**
75 | * IP Address of the end user, e.g. "123.123.123.123", will be mapped to "utmip" parameter
76 | * and "X-Forwarded-For" request header
77 | * @see internals.ParameterHolder::$utmip
78 | * @see internals.request\HttpRequest::$xForwardedFor
79 | */
80 | private var ipAddress : String;
81 |
82 | /**
83 | * User agent string of the end user, will be mapped to "User-Agent" request header
84 | * @see internals.request\HttpRequest::$userAgent
85 | */
86 | private var userAgent : String;
87 |
88 | /**
89 | * Locale string (country part optional), e.g. "de-DE", will be mapped to "utmul" parameter
90 | * @see internals.ParameterHolder::$utmul
91 | */
92 | private var locale : String;
93 |
94 | /**
95 | * Visitor's Flash version, e.g. "9.0 r28", will be maped to "utmfl" parameter
96 | * @see internals.ParameterHolder::$utmfl
97 | */
98 | private var flashVersion : String;
99 |
100 | /**
101 | * Visitor's Java support, will be mapped to "utmje" parameter
102 | * @see internals.ParameterHolder::$utmje
103 | */
104 | private var javaEnabled : Bool;
105 |
106 | /**
107 | * Visitor's screen color depth, e.g. 32, will be mapped to "utmsc" parameter
108 | * @see internals.ParameterHolder::$utmsc
109 | */
110 | private var screenColorDepth : String;
111 |
112 | /**
113 | * Visitor's screen resolution, e.g. "1024x768", will be mapped to "utmsr" parameter
114 | * @see internals.ParameterHolder::$utmsr
115 | */
116 | private var screenResolution : String;
117 |
118 |
119 | /**
120 | * Creates a new visitor without any previous visit information.
121 | */
122 | public function new() {
123 | // ga.js sets all three timestamps to now for new visitors, so we do the same
124 | var now = new DateTime();
125 | this.uniqueId = 0;
126 | this.setFirstVisitTime(now);
127 | this.setPreviousVisitTime(now);
128 | this.setCurrentVisitTime(now);
129 | this.setVisitCount(1);
130 | }
131 |
132 | /**
133 | * Will extract information for the "uniqueId", "firstVisitTime", "previousVisitTime",
134 | * "currentVisitTime" and "visitCount" properties from the given "__utma" cookie
135 | * value.
136 | * @see internals.ParameterHolder::$__utma
137 | * @see internals.request\Request::buildCookieParameters()
138 | * @return $this
139 | */
140 | public function fromUtma(value:String) {
141 | var parts : Array = value.split('.');
142 | if(parts.length != 6) {
143 | Tracker._raiseError('The given "__utma" cookie value is invalid.', 'Visitor.fromUtma');
144 | return this;
145 | }
146 |
147 | this.setUniqueId(Util.parseInt(parts[1],0));
148 | this.setFirstVisitTime(new DateTime(parts[2]));
149 | this.setPreviousVisitTime(new DateTime(parts[3]));
150 | this.setCurrentVisitTime(new DateTime(parts[4]));
151 | this.setVisitCount(Util.parseInt(parts[5],0));
152 |
153 | // Allow chaining
154 | return this;
155 | }
156 |
157 | /**
158 | * Generates a hashed value from user-specific properties.
159 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#542
160 | */
161 | private function generateHash() : Int {
162 | // TODO: Emulate orginal Google Analytics client library generation more closely
163 | return Util.generateHash(this.userAgent + this.screenResolution + this.screenColorDepth);
164 | }
165 |
166 | /**
167 | * Generates a unique user ID from the current user-specific properties.
168 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#563
169 | */
170 | private function generateUniqueId() : Int {
171 | // There seems to be an error in the gaforflash code, so we take the formula
172 | // from http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 711
173 | // instead ("&" instead of "*")
174 | return ((Util.generate32bitRandom() ^ this.generateHash()) & 0x7fffffff);
175 | }
176 |
177 | /**
178 | * @see generateUniqueId
179 | */
180 | public function setUniqueId(value:Int) {
181 | if(value < 0 || value > 0x7fffffff) {
182 | Tracker._raiseError('Visitor unique ID has to be a 32-bit integer between 0 and ' + 0x7fffffff + '.', 'Visitor.setUniqueId');
183 | }
184 | this.uniqueId = value;
185 | }
186 |
187 | /**
188 | * Will be generated on first call (if not set already) to include as much
189 | * user-specific information as possible.
190 | */
191 | public function getUniqueId() : Int {
192 | if(this.uniqueId == 0) {
193 | this.uniqueId = this.generateUniqueId();
194 | }
195 | return this.uniqueId;
196 | }
197 |
198 | /**
199 | * Updates the "previousVisitTime", "currentVisitTime" and "visitCount"
200 | * fields based on the given session object.
201 | */
202 | public function addSession(session:Session) {
203 | var startTime = session.getStartTime();
204 | if(startTime != this.currentVisitTime) {
205 | this.previousVisitTime = this.currentVisitTime;
206 | this.currentVisitTime = startTime;
207 | ++this.visitCount;
208 | }
209 | }
210 |
211 | /**
212 | */
213 | public function setFirstVisitTime(value:DateTime) {
214 | this.firstVisitTime = value;
215 | }
216 |
217 | public function getFirstVisitTime() : DateTime {
218 | return this.firstVisitTime;
219 | }
220 |
221 | public function setPreviousVisitTime(value:DateTime) {
222 | this.previousVisitTime = value;
223 | }
224 |
225 | public function getPreviousVisitTime() : DateTime {
226 | return this.previousVisitTime;
227 | }
228 |
229 | public function setCurrentVisitTime(value:DateTime) {
230 | this.currentVisitTime = value;
231 | }
232 |
233 | public function getCurrentVisitTime() : DateTime {
234 | return this.currentVisitTime;
235 | }
236 |
237 | public function setVisitCount(value:Int) {
238 | this.visitCount = value;
239 | }
240 |
241 | public function getVisitCount() : Int {
242 | return this.visitCount;
243 | }
244 |
245 | public function setIpAddress(value:String) {
246 | this.ipAddress = value;
247 | }
248 |
249 | public function getIpAddress() : String {
250 | return this.ipAddress;
251 | }
252 |
253 | public function setUserAgent(value:String) {
254 | this.userAgent = value;
255 | }
256 |
257 | public function getUserAgent() : String {
258 | return this.userAgent;
259 | }
260 |
261 | public function setLocale(value:String) {
262 | this.locale = value;
263 | }
264 |
265 | public function getLocale() : String {
266 | return this.locale;
267 | }
268 |
269 | public function setFlashVersion(value:String) {
270 | this.flashVersion = value;
271 | }
272 |
273 | public function getFlashVersion() : String {
274 | return this.flashVersion;
275 | }
276 |
277 | public function setJavaEnabled(value:Bool) {
278 | this.javaEnabled = value;
279 | }
280 |
281 | public function getJavaEnabled() : Bool {
282 | return this.javaEnabled;
283 | }
284 |
285 | public function setScreenColorDepth(value:String) {
286 | this.screenColorDepth = value;
287 | }
288 |
289 | public function getScreenColorDepth() : String {
290 | return this.screenColorDepth;
291 | }
292 |
293 | public function setScreenResolution(value:String) {
294 | this.screenResolution = value;
295 | }
296 |
297 | public function getScreenResolution() : String {
298 | return this.screenResolution;
299 | }
300 |
301 | }
302 |
--------------------------------------------------------------------------------
/src/googleAnalytics/internals/ParameterHolder.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics.internals;
28 |
29 | import googleAnalytics.Tracker;
30 |
31 | /**
32 | * This simple class is mainly meant to be a well-documented overview of all
33 | * possible GA tracking parameters.
34 | *
35 | * @link http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html#gifParameters
36 | */
37 |
38 | class ParameterHolder {
39 |
40 | // - - - - - - - - - - - - - - - - - General parameters - - - - - - - - - - - - - - - - -
41 |
42 | /**
43 | * Google Analytics client version, e.g. "4.7.2"
44 | */
45 | public var utmwv : String;
46 |
47 | /**
48 | * Google Analytics account ID, e.g. "UA-1234567-8"
49 | */
50 | public var utmac : String;
51 |
52 | /**
53 | * Host Name, e.g. "www.example.com"
54 | */
55 | public var utmhn : String;
56 |
57 | /**
58 | * Unique visitor ID (random number but should be persisted on the application side)
59 | */
60 | public var utmvid : Int;
61 |
62 | /**
63 | * Indicates the type of request, which is one of null (for page), "event",
64 | * "tran", "item", "social", "var" (deprecated) or "error" (used by ga.js
65 | * for internal client error logging).
66 | */
67 | public var utmt : String;
68 |
69 | /**
70 | * Contains the amount of requests done in this session. Added in ga.js v4.9.2.
71 | */
72 | public var utms : Int;
73 |
74 | /**
75 | * Unique ID (random number) generated for each GIF request
76 | */
77 | public var utmn : Int;
78 |
79 | /**
80 | * Contains all cookie values, see below
81 | */
82 | public var utmcc : String;
83 |
84 | /**
85 | * Extensible Parameter, used for events and custom variables
86 | */
87 | public var utme : String;
88 |
89 | /**
90 | * Event "non-interaction" parameter. By default, the event hit will impact a visitor's bounce rate.
91 | * By setting this parameter to 1, this event hit will not be used in bounce rate calculations.
92 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html
93 | */
94 | public var utmni : Int;
95 |
96 | /**
97 | * Used for GA-internal statistical client function usage and error tracking,
98 | * not implemented in php-ga as of now, but here for documentation completeness.
99 | * @link http://glucik.blogspot.com/2011/02/utmu-google-analytics-request-parameter.html
100 | */
101 | public var utmu : String;
102 |
103 |
104 | // - - - - - - - - - - - - - - - - - Page parameters - - - - - - - - - - - - - - - - -
105 |
106 | /**
107 | * Page request URI, e.g. "/path/page.html"
108 | */
109 | public var utmp : String;
110 |
111 | /**
112 | * Page title
113 | */
114 | public var utmdt : String;
115 |
116 | /**
117 | * Charset encoding (e.g. "UTF-8") or "-" as default
118 | */
119 | public var utmcs : String;
120 |
121 | /**
122 | * Referer URL, e.g. "http://www.example.com/path/page.html", "-" as default
123 | * or "0" for internal referers
124 | */
125 | public var utmr : String;
126 |
127 |
128 | // - - - - - - - - - - - - - - - - - Visitor parameters - - - - - - - - - - - - - - - - -
129 |
130 | /**
131 | * IP Address of the end user, e.g. "123.123.123.123", found in GA for Mobile examples,
132 | * but sadly seems to be ignored in normal GA use
133 | * @link http://github.com/mptre/php-ga/blob/master/ga.php
134 | */
135 | public var utmip : String;
136 |
137 | /**
138 | * Visitor's locale string (all lower-case, country part optional), e.g. "de-de"
139 | */
140 | public var utmul : String;
141 |
142 | /**
143 | * Visitor's Flash version, e.g. "9.0 r28" or "-" as default
144 | */
145 | public var utmfl : String;
146 |
147 | /**
148 | * Visitor's Java support, either 0 or 1 or "-" as default
149 | */
150 | public var utmje : String;
151 |
152 | /**
153 | * Visitor's screen color depth, e.g. "32-bit"
154 | */
155 | public var utmsc : String;
156 |
157 | /**
158 | * Visitor's screen resolution, e.g. "1024x768"
159 | */
160 | public var utmsr : String;
161 |
162 | /**
163 | * Visitor tracking cookie parameter.
164 | * This cookie is typically written to the browser upon the first visit to your site from that web browser.
165 | * If the cookie has been deleted by the browser operator, and the browser subsequently visits your site,
166 | * a new __utma cookie is written with a different unique ID.
167 | * This cookie is used to determine unique visitors to your site and it is updated with each page view.
168 | * Additionally, this cookie is provided with a unique ID that Google Analytics uses to ensure both the
169 | * validity and accessibility of the cookie as an extra security measure.
170 | * Expiration:
171 | * 2 years from set/update.
172 | * Format:
173 | * __utma=.....
174 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMA.as
175 | */
176 | public var __utma : String;
177 |
178 |
179 | // - - - - - - - - - - - - - - - - - Session parameters - - - - - - - - - - - - - - - - -
180 |
181 | /**
182 | * Hit id for revenue per page tracking for AdSense, a random per-session ID
183 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/DocumentInfo.as#117
184 | */
185 | public var utmhid : Int;
186 |
187 | /**
188 | * Session timeout cookie parameter.
189 | * Will never be sent with requests, but stays here for documentation completeness.
190 | * This cookie is used to establish and continue a user session with your site.
191 | * When a user views a page on your site, the Google Analytics code attempts to update this cookie.
192 | * If it does not find the cookie, a new one is written and a new session is established.
193 | * Each time a user visits a different page on your site, this cookie is updated to expire in 30 minutes,
194 | * thus continuing a single session for as long as user activity continues within 30-minute intervals.
195 | * This cookie expires when a user pauses on a page on your site for longer than 30 minutes.
196 | * You can modify the default length of a user session with the setSessionTimeout() method.
197 | * Expiration:
198 | * 30 minutes from set/update.
199 | * Format:
200 | * __utmb=...
201 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMB.as
202 | */
203 | public var __utmb : String;
204 |
205 | /**
206 | * Session tracking cookie parameter.
207 | * Will never be sent with requests, but stays here for documentation completeness.
208 | * This cookie operates in conjunction with the __utmb cookie to determine whether or not
209 | * to establish a new session for the user.
210 | * In particular, this cookie is not provided with an expiration date,
211 | * so it expires when the user exits the browser.
212 | * Should a user visit your site, exit the browser and then return to your website within 30 minutes,
213 | * the absence of the __utmc cookie indicates that a new session needs to be established,
214 | * despite the fact that the __utmb cookie has not yet expired.
215 | * Expiration:
216 | * Not set.
217 | * Format:
218 | * __utmc=
219 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMC.as
220 | */
221 | public var __utmc : Int;
222 |
223 |
224 | // - - - - - - - - - - - - - - - - - E-Commerce parameters - - - - - - - - - - - - - - - - -
225 |
226 | /**
227 | * Product Code. This is the sku code for a given product, e.g. "989898ajssi"
228 | */
229 | public var utmipc : String;
230 |
231 | /**
232 | * Product Name, e.g. "T-Shirt"
233 | */
234 | public var utmipn : String;
235 |
236 | /**
237 | * Unit Price. Value is set to numbers only, e.g. 19.95
238 | */
239 | public var utmipr : Float;
240 |
241 | /**
242 | * Unit Quantity, e.g. 4
243 | */
244 | public var utmiqt : Int;
245 |
246 | /**
247 | * Variations on an item, e.g. "white", "black", "green" etc.
248 | */
249 | public var utmiva : String;
250 |
251 | /**
252 | * Order ID, e.g. "a2343898"
253 | */
254 | public var utmtid : String;
255 |
256 | /**
257 | * Affiliation
258 | */
259 | public var utmtst : String;
260 |
261 | /**
262 | * Total Cost, e.g. 20.00
263 | */
264 | public var utmtto : Float;
265 |
266 | /**
267 | * Tax Cost, e.g. 4.23
268 | */
269 | public var utmttx : Float;
270 |
271 | /**
272 | * Shipping Cost, e.g. 3.95
273 | */
274 | public var utmtsp : Float;
275 |
276 | /**
277 | * Billing City, e.g. "Cologne"
278 | */
279 | public var utmtci : String;
280 |
281 | /**
282 | * Billing Region, e.g. "North Rhine-Westphalia"
283 | */
284 | public var utmtrg : String;
285 |
286 | /**
287 | * Billing Country, e.g. "Germany"
288 | */
289 | public var utmtco : String;
290 |
291 |
292 | // - - - - - - - - - - - - - - - - - Campaign parameters - - - - - - - - - - - - - - - - -
293 |
294 | /**
295 | * Starts a new campaign session. Either utmcn or utmcr is present on any given request,
296 | * but never both at the same time. Changes the campaign tracking data; but does not start
297 | * a new session. Either 1 or not set.
298 | * Found in gaforflash but not in ga.js, so we do not use it, but it will stay here for
299 | * documentation completeness.
300 | * @deprecated
301 | */
302 | public var utmcn : Int;
303 |
304 | /**
305 | * Indicates a repeat campaign visit. This is set when any subsequent clicks occur on the
306 | * same link. Either utmcn or utmcr is present on any given request, but never both at the
307 | * same time. Either 1 or not set.
308 | * Found in gaforflash but not in ga.js, so we do not use it, but it will stay here for
309 | * documentation completeness.
310 | * @deprecated
311 | */
312 | public var utmcr : Int;
313 |
314 | /**
315 | * Campaign ID, a.k.a. "utm_id" query parameter for ga.js
316 | */
317 | public var utmcid : String;
318 |
319 | /**
320 | * Source, a.k.a. "utm_source" query parameter for ga.js
321 | */
322 | public var utmcsr : String;
323 |
324 | /**
325 | * Google AdWords Click ID, a.k.a. "gclid" query parameter for ga.js
326 | */
327 | public var utmgclid : String;
328 |
329 | /**
330 | * Not known for sure, but expected to be a DoubleClick Ad Click ID.
331 | */
332 | public var utmdclid : String;
333 |
334 | /**
335 | * Name, a.k.a. "utm_campaign" query parameter for ga.js
336 | */
337 | public var utmccn : String;
338 |
339 | /**
340 | * Medium, a.k.a. "utm_medium" query parameter for ga.js
341 | */
342 | public var utmcmd : String;
343 |
344 | /**
345 | * Terms/Keywords, a.k.a. "utm_term" query parameter for ga.js
346 | */
347 | public var utmctr : String;
348 |
349 | /**
350 | * Ad Content Description, a.k.a. "utm_content" query parameter for ga.js
351 | */
352 | public var utmcct : String;
353 |
354 | /**
355 | * Unknown so far. Found in ga.js.
356 | */
357 | public var utmcvr : Int;
358 |
359 | /**
360 | * Campaign tracking cookie parameter.
361 | * This cookie stores the type of referral used by the visitor to reach your site,
362 | * whether via a direct method, a referring link, a website search, or a campaign such as an ad or an email link.
363 | * It is used to calculate search engine traffic, ad campaigns and page navigation within your own site.
364 | * The cookie is updated with each page view to your site.
365 | * Expiration:
366 | * 6 months from set/update.
367 | * Format:
368 | * __utmz=....
369 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMZ.as
370 | */
371 | public var __utmz : String;
372 |
373 |
374 | // - - - - - - - - - - - - - - - - - Social Tracking parameters - - - - - - - - - - - - - - - - -
375 |
376 | /**
377 | * The network on which the action occurs (e.g. Facebook, Twitter).
378 | */
379 | public var utmsn : String;
380 |
381 | /**
382 | * The type of action that happens (e.g. Like, Send, Tweet).
383 | */
384 | public var utmsa : String;
385 |
386 | /**
387 | * The page URL from which the action occurred.
388 | */
389 | public var utmsid : String;
390 |
391 |
392 | // - - - - - - - - - - - - - - - - - Google Website Optimizer (GWO) parameters - - - - - - - - - - - - - - - - -
393 |
394 | // TODO: Implementation needed
395 | /**
396 | * Website Optimizer cookie parameter.
397 | * This cookie is used by Website Optimizer and only set when Website Optimizer is used in combination
398 | * with GA. See the Google Website Optimizer Help Center for details.
399 | * Expiration:
400 | * 2 years from set/update.
401 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMX.as
402 | */
403 | public var __utmx : String;
404 |
405 |
406 | // - - - - - - - - - - - - - - - - - Custom Variables parameters (deprecated) - - - - - - - - - - - - - - - - -
407 |
408 | // TODO: Implementation needed?
409 | /**
410 | * Deprecated custom variables cookie parameter.
411 | * This cookie parameter is no longer relevant as of migration from setVar() to
412 | * setCustomVar() and hence not supported by this library, but will stay here for
413 | * documentation completeness.
414 | * The __utmv cookie passes the information provided via the setVar() method,
415 | * which you use to create a custom user segment.
416 | * Expiration:
417 | * 2 years from set/update.
418 | * Format:
419 | * __utmv=.
420 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/UTMV.as
421 | * @deprecated
422 | */
423 | public var __utmv : String;
424 |
425 |
426 | /**
427 | * Converts this parameter holder to a pure PHP array, filtering out all properties
428 | * prefixed with an underscore ("_").
429 | */
430 | public function toHashTable() : Map {
431 | var hash = new Map();
432 | var property:String;
433 | for (property in Type.getInstanceFields(ParameterHolder)) {
434 | if (property.charAt(0) != '_' && !Reflect.isFunction(Reflect.field(this,property))) {
435 | hash.set(property, Reflect.field(this, property));
436 | }
437 | }
438 | return hash;
439 | }
440 |
441 | public function toQueryString() : String {
442 | var qs : String = '';
443 | var property:String;
444 | for (property in Type.getInstanceFields(ParameterHolder)) {
445 | if (property.charAt(0) != '_' && !Reflect.isFunction(Reflect.field(this, property)) && Reflect.field(this, property) != null && Reflect.field(this, property) != 'null' ) {
446 | qs += property + '=' + StringTools.replace(Reflect.field(this, property)+'', '&', '%26') + '&';
447 | }
448 | }
449 | return qs;
450 | }
451 |
452 | public function new() {
453 | utmwv = googleAnalytics.Tracker.VERSION;
454 | utmr=utmcs=utmfl=utmje= '0';
455 | }
456 |
457 | }
458 |
--------------------------------------------------------------------------------
/src/googleAnalytics/internals/Util.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics.internals;
28 |
29 | /**
30 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/Utils.as
31 | */
32 |
33 | class Util {
34 |
35 | /**
36 | * Mimics Javascript's encodeURIComponent() function for consistency with the GA Javascript client.
37 | */
38 | public static function encodeUriComponent(value:Dynamic) : String {
39 | return convertToUriComponentEncoding(StringTools.urlEncode(value));
40 | }
41 |
42 | public static function stringReplaceArray(s:String, sub:Array, by:Array):String {
43 | for (i in 0...sub.length ) {
44 | if (sub[i] == null) continue;
45 | s = StringTools.replace(s+' ', sub[i], by[i]);
46 |
47 | }
48 | return StringTools.trim(s);
49 | }
50 |
51 | public static function parseInt(s:String, defaultVal:Int):Int{
52 | return (s==null)?defaultVal:Std.parseInt(s);
53 | }
54 |
55 | /**
56 | * Here as a separate method so it can also be applied to e.g. a http_build_query() result.
57 | * @link http://stackoverflow.com/questions/1734250/what-is-the-equivalent-of-javascripts-encodeuricomponent-in-php/1734255#1734255
58 | * @link http://devpro.it/examples/php_js_escaping.php
59 | */
60 | public static function convertToUriComponentEncoding(encodedValue:String) : String {
61 | return stringReplaceArray(encodedValue, [ '!', '*', "'", '(', ')', ' ', '+' ],[ '%21', '%2A', '%27', '%28', '%29' , '%20', '%20']);
62 | }
63 |
64 | /**
65 | * Generates a 32bit random number.
66 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/Utils.as#33
67 | */
68 | public static function generate32bitRandom() : Int {
69 | return Math.round(Math.random() * 0x7fffffff);
70 | }
71 |
72 | /**
73 | * Generates a hash for input string.
74 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/Utils.as#44
75 | */
76 | public static function generateHash(string:String) : Int {
77 | var hash:Int = 1;
78 | var current;
79 | var leftMost7;
80 | if(string != null && string != '') {
81 | hash = 0;
82 | var pos:Int = string.length - 1;
83 | while(pos >= 0) {
84 | current = string.charCodeAt(pos);
85 | hash = ((hash << 6) & 0xfffffff) + current + (current << 14);
86 | leftMost7 = hash & 0xfe00000;
87 | if(leftMost7 != 0) {
88 | hash ^= leftMost7 >> 21;
89 | }
90 | pos--;
91 | }
92 | }
93 |
94 | return hash;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/googleAnalytics/internals/X10.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics.internals;
28 | import haxe.crypto.BaseCode;
29 |
30 | /**
31 | * This is nearly a 1:1 Haxe port of the gaforflash X10 class code.
32 | * I'm sure it cointains errors (since it's been ported form ActionScript to PHP and from PHP
33 | * to Haxe. I'm not sure also what's X10 about u.u
34 | *
35 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/data/X10.as
36 | */
37 |
38 | class X10 {
39 |
40 | private var projectData : Map>>;
41 | private var KEY : String;
42 | private var VALUE : String;
43 | private var SET : Array;
44 |
45 | /**
46 | * Opening delimiter for wrapping a set of values belonging to the same type.
47 | */
48 | private var DELIM_BEGIN : String;
49 |
50 | /**
51 | * Closing delimiter for wrapping a set of values belonging to the same type.
52 | */
53 | private var DELIM_END : String;
54 |
55 | /**
56 | * Delimiter between two consecutive num/value pairs.
57 | */
58 | private var DELIM_SET : String;
59 |
60 | /**
61 | * Delimiter between a num and its corresponding value.
62 | */
63 | private var DELIM_NUM_VALUE : String;
64 |
65 | /**
66 | * Mapping of escapable characters to their escaped forms.
67 | */
68 | private var ESCAPE_CHAR_MAP : Map;
69 |
70 | private var MINIMUM : Int;
71 |
72 | public function new() {
73 | projectData = new Map>>();
74 | KEY = 'k';
75 | VALUE = 'v';
76 | SET = [ 'k', 'v' ];
77 | DELIM_BEGIN = '(';
78 | DELIM_END = ')';
79 | DELIM_SET = '*';
80 | DELIM_NUM_VALUE = '!';
81 | MINIMUM = 1;
82 | ESCAPE_CHAR_MAP = new Map();
83 | ESCAPE_CHAR_MAP.set('\'', '\'0');
84 | ESCAPE_CHAR_MAP.set(')' , '\'1');
85 | ESCAPE_CHAR_MAP.set('*' , '\'2');
86 | ESCAPE_CHAR_MAP.set('!' , '\'3');
87 | }
88 |
89 |
90 |
91 | static inline public var OBJECT_KEY_NUM = 1;
92 | static inline public var TYPE_KEY_NUM = 2;
93 | static inline public var LABEL_KEY_NUM = 3;
94 | static inline public var VALUE_VALUE_NUM = 1;
95 |
96 | private function hasProject(projectId:String) : Bool {
97 | return projectData.exists(projectId);
98 | }
99 |
100 | public function setKey(projectId:String, num:Int, value:Dynamic) {
101 | this.setInternal(projectId, this.KEY, num, value);
102 | }
103 |
104 | public function getKey(projectId:String, num:Int) : Dynamic {
105 | return this.getInternal(projectId, this.KEY, num);
106 | }
107 |
108 | public function clearKey(projectId:String) {
109 | this.clearInternal(projectId, this.KEY);
110 | }
111 |
112 | public function setValue(projectId:String, num:Int, value:Dynamic) {
113 | this.setInternal(projectId, this.VALUE, num, value);
114 | }
115 |
116 | public function getValue(projectId:String, num:Int) : Dynamic {
117 | return this.getInternal(projectId, this.VALUE, num);
118 | }
119 |
120 | public function clearValue(projectId:String) {
121 | this.clearInternal(projectId, this.VALUE);
122 | }
123 |
124 | /**
125 | * Shared internal implementation for setting an X10 data type.
126 | */
127 | private function setInternal(projectId:String, type:String, num:Int, value:Dynamic) {
128 | if(!projectData.exists(projectId)) {
129 | projectData.set(projectId, new Map>());
130 | }
131 | var p = projectData.get(projectId);
132 | if(!p.exists(type)) {
133 | p.set(type, new Array());
134 | }
135 | p.get(type)[num] = value;
136 | }
137 |
138 | /**
139 | * Shared internal implementation for getting an X10 data type.
140 | */
141 | private function getInternal(projectId:String, type:String, num:Int) : Dynamic {
142 | if (!projectData.exists(projectId)) return null;
143 | var p : Map> = projectData.get(projectId);
144 | if (!p.exists(type)) return null;
145 | var a : Array = p.get(type);
146 | if (a[num]==null) return null;
147 | return a[num];
148 | }
149 |
150 | /**
151 | * Shared internal implementation for clearing all X10 data of a type from a
152 | * certain project.
153 | */
154 | private function clearInternal(projectId:String, type:String) {
155 | if(projectData.exists(projectId) && projectData.get(projectId).exists(type)) {
156 | projectData.get(projectId).remove(type);
157 | }
158 | }
159 |
160 | /**
161 | * Escape X10 string values to remove ambiguity for special characters.
162 | * @see X10::$escapeCharMap
163 | */
164 | private function escapeExtensibleValue(value:String) : String {
165 | var result = '';
166 | for(i in 0...value.length) {
167 | var char = value.charAt(i);
168 | if(ESCAPE_CHAR_MAP.exists(char)) {
169 | result += this.ESCAPE_CHAR_MAP.get(char);
170 | } else {
171 | result += char;
172 | }
173 | }
174 |
175 | return result;
176 | }
177 |
178 | function SORT_NUMERIC(v1:String, v2:String):Int {
179 | if (v1 == v2) return 0;
180 | if (v1 > v2) return 1;
181 | return -1;
182 | }
183 |
184 | /**
185 | * Given a data array for a certain type, render its string encoding.
186 | */
187 | private function renderDataType(data:Array) : String {
188 | var result:Array = new Array();
189 | var lastI:Int = 0;
190 | // The original order must be retained, otherwise event's category/action/label will be mixed up
191 | //data.sort(SORT_NUMERIC); // on PHP -> ksort(data, SORT_NUMERIC);
192 |
193 | for (i in 0...data.length) {
194 | var entry = data[i];
195 | if(entry!=null) {
196 | var str: String = '';
197 |
198 | // Check if we need to append the number. If the last number was
199 | // outputted, or if this is the assumed minimum, then we don't.
200 | if(i != this.MINIMUM && i - 1 != lastI) {
201 | str += i;
202 | str += this.DELIM_NUM_VALUE;
203 | }
204 |
205 | str += this.escapeExtensibleValue(entry);
206 | result.push(str);
207 | }
208 |
209 | lastI = i;
210 | }
211 |
212 | return this.DELIM_BEGIN + result.join(this.DELIM_SET) + this.DELIM_END;
213 | }
214 |
215 | /**
216 | * Given a project array, render its string encoding.
217 | */
218 | private function renderProject(project:Map>) : String {
219 | var result = '';
220 |
221 | // Do we need to output the type string? As an optimization we do not
222 | // output the type string if it's the first type, or if the previous
223 | // type was present.
224 | var needTypeQualifier: Bool = false;
225 |
226 | for(i in 0...SET.length) {
227 | if(project.exists(this.SET[i])) {
228 | if(needTypeQualifier) {
229 | result += SET[i];
230 | }
231 | result += renderDataType(project.get(this.SET[i]));
232 | needTypeQualifier = false;
233 | } else {
234 | needTypeQualifier = true;
235 | }
236 | }
237 |
238 | return result;
239 | }
240 |
241 | /**
242 | * Generates the URL parameter string for the current internal extensible data state.
243 | */
244 | public function renderUrlString() : String {
245 | var result = '';
246 | for(projectId in this.projectData.keys()) {
247 | result += projectId + this.renderProject(this.projectData.get(projectId));
248 | }
249 | return result;
250 | }
251 |
252 | }
253 |
--------------------------------------------------------------------------------
/src/googleAnalytics/internals/request/EventRequest.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics.internals.request;
28 |
29 | import googleAnalytics.Event;
30 | import googleAnalytics.internals.ParameterHolder;
31 |
32 | import googleAnalytics.internals.X10;
33 |
34 |
35 | class EventRequest extends Request {
36 |
37 | /**
38 | * @var googleAnalytics.Event
39 | */
40 | private var event : Event;
41 |
42 |
43 | /**
44 | * @const int
45 | */
46 | static inline public var X10_EVENT_PROJECT_ID = '5';
47 |
48 |
49 | /**
50 | */
51 | override private function getType() : String {
52 | return Request.TYPE_EVENT;
53 | }
54 |
55 | /**
56 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#1503
57 | */
58 | override private function buildParameters() : ParameterHolder {
59 | var p = super.buildParameters();
60 |
61 | var x10 = new X10();
62 |
63 | x10.clearKey(/*self.*/X10_EVENT_PROJECT_ID);
64 | x10.clearValue(/*self.*/X10_EVENT_PROJECT_ID);
65 |
66 | // Object / Category
67 | x10.setKey(/*self.*/X10_EVENT_PROJECT_ID, X10.OBJECT_KEY_NUM, this.event.getCategory());
68 |
69 | // Event Type / Action
70 | x10.setKey(/*self.*/X10_EVENT_PROJECT_ID, X10.TYPE_KEY_NUM, this.event.getAction());
71 |
72 | if(this.event.getLabel() != null) {
73 | // Event Description / Label
74 | x10.setKey(/*self.*/X10_EVENT_PROJECT_ID, X10.LABEL_KEY_NUM, this.event.getLabel());
75 | }
76 |
77 | if(this.event.getValue() >= 0) {
78 | x10.setValue(/*self.*/X10_EVENT_PROJECT_ID, X10.VALUE_VALUE_NUM, this.event.getValue());
79 | }
80 |
81 | var eventFragment:String = x10.renderUrlString();
82 | // Append only if not null to avoid "null" in event fragments
83 | if (eventFragment != null) {
84 | if(p.utme == null) p.utme = eventFragment;
85 | else p.utme += eventFragment;
86 | }
87 |
88 | if(this.event.getNoninteraction()) {
89 | p.utmni = 1;
90 | }
91 |
92 | return p;
93 | }
94 |
95 | public function getEvent() : Event {
96 | return this.event;
97 | }
98 |
99 | public function setEvent(event:Event) {
100 | this.event = event;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/googleAnalytics/internals/request/ItemRequest.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics.internals.request;
28 |
29 | import googleAnalytics.Item;
30 |
31 | import googleAnalytics.internals.ParameterHolder;
32 |
33 |
34 | class ItemRequest extends Request {
35 |
36 | private var item : Item;
37 |
38 | override private function getType() : String {
39 | return Request.TYPE_ITEM;
40 | }
41 |
42 | /**
43 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/ecommerce/Item.as#61
44 | */
45 | override private function buildParameters() : ParameterHolder {
46 | var p = super.buildParameters();
47 |
48 | p.utmtid = this.item.getOrderId();
49 | p.utmipc = this.item.getSku();
50 | p.utmipn = this.item.getName();
51 | p.utmiva = this.item.getVariation();
52 | p.utmipr = this.item.getPrice();
53 | p.utmiqt = this.item.getQuantity();
54 |
55 | return p;
56 | }
57 |
58 | /**
59 | * The GA Javascript client doesn't send any visitor information for
60 | * e-commerce requests, so we don't either.
61 | */
62 | override private function buildVisitorParameters(p:ParameterHolder) : ParameterHolder {
63 | return p;
64 | }
65 |
66 | /**
67 | * The GA Javascript client doesn't send any custom variables for
68 | * e-commerce requests, so we don't either.
69 | */
70 | override private function buildCustomVariablesParameter(p:ParameterHolder) : ParameterHolder {
71 | return p;
72 | }
73 |
74 | public function getItem() : Item {
75 | return this.item;
76 | }
77 |
78 | public function setItem(item:Item) {
79 | this.item = item;
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/src/googleAnalytics/internals/request/PageviewRequest.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics.internals.request;
28 |
29 | import googleAnalytics.Config;
30 | import googleAnalytics.internals.ParameterHolder;
31 | import googleAnalytics.Page;
32 |
33 | class PageviewRequest extends Request {
34 |
35 | private var page : Page;
36 |
37 | override private function getType() : String {
38 | return Request.TYPE_PAGE;
39 | }
40 |
41 | public function new(config:Config=null) {
42 | super(config);
43 | }
44 |
45 | override private function buildParameters() : ParameterHolder {
46 | var p = super.buildParameters();
47 | p.utmp = this.page.getPath();
48 | p.utmdt = this.page.getTitle();
49 | if(this.page.getCharset() != null) {
50 | p.utmcs = this.page.getCharset();
51 | }
52 | if(this.page.getReferrer() != null) {
53 | p.utmr = this.page.getReferrer();
54 | }
55 |
56 | if(this.page.getLoadTime()!=0) {
57 | // Sample sitespeed measurements
58 | if(p.utmn % 100 < this.config.getSitespeedSampleRate()) {
59 | if(p.utme == null) p.utme = "" + 0;
60 | else p.utme += 0;
61 | }
62 | }
63 |
64 | return p;
65 | }
66 |
67 | public function getPage() : Page {
68 | return this.page;
69 | }
70 |
71 | public function setPage(page:Page) {
72 | this.page = page;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/src/googleAnalytics/internals/request/Request.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics.internals.request;
28 |
29 | import googleAnalytics.Config;
30 | import googleAnalytics.Tracker;
31 | import googleAnalytics.Visitor;
32 | import googleAnalytics.Session;
33 | import googleAnalytics.CustomVariable;
34 | import haxe.Http;
35 |
36 | import googleAnalytics.internals.ParameterHolder;
37 | import googleAnalytics.internals.Util;
38 | import googleAnalytics.internals.X10;
39 |
40 | class Request {
41 |
42 | /**
43 | * Indicates the type of request, will be mapped to "utmt" parameter
44 | * @see ParameterHolder::$utmt
45 | */
46 | private var type : String;
47 | private var config : Config;
48 | private var userAgent : String;
49 | private var tracker : Tracker;
50 | private var visitor : Visitor;
51 | private var session : Session;
52 |
53 | static inline public var TYPE_PAGE = null;
54 | static inline public var TYPE_EVENT = 'event';
55 | static inline public var TYPE_TRANSACTION = 'tran';
56 | static inline public var TYPE_ITEM = 'item';
57 | static inline public var TYPE_SOCIAL = 'social';
58 |
59 | /**
60 | * This type of request is deprecated in favor of encoding custom variables
61 | * within the "utme" parameter, but we include it here for completeness
62 | *
63 | * @see ParameterHolder::$__utmv
64 | * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._setVar
65 | * @deprecated
66 | */
67 | static inline public var TYPE_CUSTOMVARIABLE = 'var';
68 | static inline public var X10_CUSTOMVAR_NAME_PROJECT_ID = '8';
69 | static inline public var X10_CUSTOMVAR_VALUE_PROJECT_ID = '9';
70 | static inline public var X10_CUSTOMVAR_SCOPE_PROJECT_ID = '11';
71 | static inline public var CAMPAIGN_DELIMITER = '|';
72 |
73 |
74 | public function new(config:Config=null) {
75 | setConfig((config!=null) ? config : new Config());
76 | }
77 |
78 | public function getConfig() : Config {
79 | return this.config;
80 | }
81 |
82 | public function setConfig(config:Config) {
83 | this.config = config;
84 | }
85 |
86 | private function setUserAgent(value:String) {
87 | this.userAgent = value;
88 | }
89 |
90 | public function getTracker() : Tracker {
91 | return this.tracker;
92 | }
93 |
94 | public function setTracker(tracker:Tracker) {
95 | this.tracker = tracker;
96 | }
97 |
98 | public function getVisitor() : Visitor {
99 | return this.visitor;
100 | }
101 |
102 | public function setVisitor(visitor:Visitor) {
103 | this.visitor = visitor;
104 | }
105 |
106 | public function getSession() : Session {
107 | return this.session;
108 | }
109 |
110 | public function setSession(session:Session) {
111 | this.session = session;
112 | }
113 |
114 | private static function onError (_) {}
115 |
116 | private function increaseTrackCount() {
117 | // Increment session track counter for each request
118 | this.session.increaseTrackCount();
119 | // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Configuration.as?r=237#48
120 | // and http://code.google.com/intl/de-DE/apis/analytics/docs/tracking/eventTrackerGuide.html#implementationConsiderations
121 | if(this.session.getTrackCount() > 500) {
122 | Tracker._raiseError('Google Analytics does not guarantee to process more than 500 requests per session.', 'Request.buildHttpRequest');
123 | }
124 | if(this.tracker.getCampaign()!=null) {
125 | this.tracker.getCampaign().increaseResponseCount();
126 | }
127 | }
128 |
129 | /**
130 | * This method should only be called directly or indirectly by fire(), but must
131 | * remain public as it can be called by a closure function.
132 | * Sends either a normal HTTP request with response or an asynchronous request
133 | * to Google Analytics without waiting for the response. Will always return
134 | * null in the latter case, or false if any connection problems arise.
135 | * @return null|string
136 | */
137 | public function send() {
138 | // Do not actually send the request if endpoint host is set to null
139 | if (config.getEndPointHost() == null) return;
140 | var parameters = this.buildParameters();
141 | if ( visitor != null ) {
142 | setUserAgent( visitor.getUserAgent() );
143 | parameters.utmvid = visitor.getUniqueId();
144 | }
145 | var queryString : String = Util.convertToUriComponentEncoding(parameters.toQueryString());
146 | var url : String = config.getUrlScheme() + '://' + config.getEndPointHost() + config.getEndPointPath() + '?' + queryString;
147 | increaseTrackCount();
148 | #if js
149 | // well, in javascript ocurrs the same thing with CORS, so no request, just load an image.
150 | var img:js.html.Image = new js.html.Image();
151 | img.src = url;
152 | #elseif flash
153 | // we must load GoogleAnalytics using Flash API (like loading an image to avoid the check
154 | // of a crossdomain.xml
155 | var l : flash.display.Loader = new flash.display.Loader();
156 | var urlRequest : flash.net.URLRequest=new flash.net.URLRequest();
157 | urlRequest.url=url;
158 | //flash have unspoken error that can happen nonetheless due to denied DNS resolution...
159 | l.contentLoaderInfo.addEventListener( flash.events.IOErrorEvent.IO_ERROR, onError );
160 | try{ l.load(urlRequest); }catch(e:Dynamic){}
161 | #else
162 |
163 | #if (cpp || neko)
164 | // On CPP and Neko, we must use ThreadedSocketRequest to avoid blocking.
165 | // But, since ThreadedSocketRequest does not support https, we may not use it.
166 | var useThreadedSocketRequest:Bool = config.getUrlScheme()=='http';
167 | #else
168 | var useThreadedSocketRequest:Bool = false;
169 | #end
170 |
171 | if(useThreadedSocketRequest){
172 | googleAnalytics.ThreadedSocketRequest.request(url,userAgent);
173 | } else {
174 | var request : Http = new Http(url);
175 | if(userAgent!=null && userAgent!='') {
176 | request.setHeader('User-Agent', userAgent);
177 | }
178 | request.setHeader('Host', config.getUrlScheme() + '://' + config.getEndPointHost());
179 | request.setHeader('Connection', 'close');
180 | #if (neko||php||cpp||cs||java)
181 | request.cnxTimeout=config.getRequestTimeout();
182 | #end
183 | request.onError = onError;
184 | request.request(false);
185 | }
186 | #end
187 | }
188 |
189 | /**
190 | * Indicates the type of request, will be mapped to "utmt" parameter
191 | *
192 | * @see ParameterHolder::$utmt
193 | * @return string See Request::TYPE_* constants
194 | */
195 | private function getType() : String { return null; }
196 |
197 | private function buildParameters() : ParameterHolder {
198 | var p:ParameterHolder = new ParameterHolder();
199 |
200 | p.utmac = this.tracker.getAccountId();
201 | p.utmhn = this.tracker.getDomainName();
202 |
203 | p.utmt = ''+this.getType();
204 | p.utmn = Util.generate32bitRandom();
205 |
206 | // The "utmip" parameter is only relevant if a mobile analytics
207 | // ID (MO-123456-7) was given,
208 | // see https://github.com/fbricker/haxe-ga/issues/detail?id=9
209 | p.utmip = this.visitor.getIpAddress();
210 |
211 | p.utmhid = this.session.getSessionId();
212 | p.utms = this.session.getTrackCount();
213 |
214 | p = this.buildVisitorParameters(p);
215 | p = this.buildCustomVariablesParameter(p);
216 | p = this.buildCampaignParameters(p);
217 | p = this.buildCookieParameters(p);
218 |
219 | return p;
220 | }
221 |
222 | private function buildVisitorParameters(p:ParameterHolder) : ParameterHolder {
223 | // Ensure correct locale format, see https://developer.mozilla.org/en/navigator.language
224 | if(visitor.getLocale()!=null){
225 | p.utmul = StringTools.replace(visitor.getLocale(), '_', '-').toLowerCase();
226 | }
227 | if(this.visitor.getFlashVersion() != null) {
228 | p.utmfl = this.visitor.getFlashVersion();
229 | }
230 | p.utmje = this.visitor.getJavaEnabled()?'1':'0';
231 | if(this.visitor.getScreenColorDepth() != null) {
232 | p.utmsc = this.visitor.getScreenColorDepth() + '-bit';
233 | }
234 | p.utmsr = this.visitor.getScreenResolution();
235 | return p;
236 | }
237 |
238 | /**
239 | * @link http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 575
240 | \ */
241 | private function buildCustomVariablesParameter(p:ParameterHolder) : ParameterHolder {
242 | var customVars = this.tracker.getCustomVariables();
243 | if (customVars == null) return p;
244 | if(customVars.length > 5) {
245 | // See http://code.google.com/intl/de-DE/apis/analytics/docs/tracking/gaTrackingCustomVariables.html#usage
246 | Tracker._raiseError('The sum of all custom variables cannot exceed 5 in any given request.', 'Request.buildCustomVariablesParameter');
247 | }
248 |
249 | var x10:X10 = new X10();
250 | var name;
251 | var value;
252 |
253 | x10.clearKey(/*self.*/X10_CUSTOMVAR_NAME_PROJECT_ID);
254 | x10.clearKey(/*self.*/X10_CUSTOMVAR_VALUE_PROJECT_ID);
255 | x10.clearKey(/*self.*/X10_CUSTOMVAR_SCOPE_PROJECT_ID);
256 |
257 | for(customVar in customVars) {
258 | // Name and value get encoded here,
259 | // see http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 563
260 | name = Util.encodeUriComponent(customVar.getName());
261 | value = Util.encodeUriComponent(customVar.getValue());
262 |
263 | x10.setKey(/*self.*/X10_CUSTOMVAR_NAME_PROJECT_ID, customVar.getIndex(), name);
264 | x10.setKey(/*self.*/X10_CUSTOMVAR_VALUE_PROJECT_ID, customVar.getIndex(), value);
265 | if(customVar.getScope() != CustomVariable.SCOPE_PAGE) {
266 | x10.setKey(/*self.*/X10_CUSTOMVAR_SCOPE_PROJECT_ID, customVar.getIndex(), customVar.getScope());
267 | }
268 | }
269 |
270 | var eventFragment:String = x10.renderUrlString();
271 | // Append only if not null to avoid "null" in event fragments
272 | if (eventFragment != null) {
273 | if(p.utme == null) p.utme = eventFragment;
274 | else p.utme += eventFragment;
275 | }
276 | return p;
277 | }
278 |
279 | /**
280 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/GIFRequest.as#123
281 | */
282 | private function buildCookieParameters(p:ParameterHolder) : ParameterHolder {
283 | var domainHash = this.generateDomainHash();
284 | p.__utma = domainHash + '.';
285 | p.__utma += this.visitor.getUniqueId() + '.';
286 | p.__utma += this.visitor.getFirstVisitTime().toString() + '.';
287 | p.__utma += this.visitor.getPreviousVisitTime().toString() + '.';
288 | p.__utma += this.visitor.getCurrentVisitTime().toString() + '.';
289 | p.__utma += this.visitor.getVisitCount();
290 |
291 | p.__utmb = domainHash + '.';
292 | p.__utmb += this.session.getTrackCount() + '.';
293 | // FIXME: What does "token" mean? I only encountered a value of 10 in my tests.
294 | p.__utmb += 10 + '.';
295 | p.__utmb += this.session.getStartTime().toString();
296 |
297 | p.__utmc = domainHash;
298 |
299 | var cookies : String = '__utma=' + p.__utma + ';';
300 | if(p.__utmz!=null) {
301 | cookies += '+__utmz=' + p.__utmz + ';';
302 | }
303 | if(p.__utmv!=null) {
304 | cookies += '+__utmv=' + p.__utmv + ';';
305 | }
306 | p.utmcc = cookies;
307 | return p;
308 | }
309 |
310 | private function buildCampaignParameters(p:ParameterHolder) : ParameterHolder {
311 | var campaign = this.tracker.getCampaign();
312 | if (campaign == null) return p;
313 | p.__utmz = this.generateDomainHash() + '.';
314 | p.__utmz += campaign.getCreationTime().toString() + '.';
315 | p.__utmz += this.visitor.getVisitCount() + '.';
316 | p.__utmz += campaign.getResponseCount() + '.';
317 |
318 | // See http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/campaign/CampaignTracker.as#236
319 | var data:String =
320 | 'utmcid=' + campaign.getId() + CAMPAIGN_DELIMITER +
321 | 'utmcsr=' + campaign.getSource() + CAMPAIGN_DELIMITER +
322 | 'utmgclid=' + campaign.getGClickId() + CAMPAIGN_DELIMITER +
323 | 'utmdclid=' + campaign.getDClickId() + CAMPAIGN_DELIMITER +
324 | 'utmccn=' + campaign.getName() + CAMPAIGN_DELIMITER +
325 | 'utmcmd=' + campaign.getMedium() + CAMPAIGN_DELIMITER +
326 | 'utmctr=' + campaign.getTerm() + CAMPAIGN_DELIMITER +
327 | 'utmcct=' + campaign.getContent();
328 | p.__utmz += StringTools.replace(StringTools.replace(data, '+', '%20'), ' ', '%20');
329 | return p;
330 | }
331 |
332 | /**
333 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#585
334 | */
335 | private function generateDomainHash() : Int {
336 | var hash:Int = 1;
337 | if (this.tracker.getAllowHash()) {
338 | hash = Util.generateHash(this.tracker.getDomainName());
339 | }
340 | return hash;
341 | }
342 |
343 | }
344 |
--------------------------------------------------------------------------------
/src/googleAnalytics/internals/request/SocialInteractionRequest.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics.internals.request;
28 |
29 | import googleAnalytics.Config;
30 | import googleAnalytics.internals.ParameterHolder;
31 | import googleAnalytics.SocialInteraction;
32 |
33 |
34 | class SocialInteractionRequest extends PageviewRequest {
35 |
36 | private var socialInteraction : SocialInteraction;
37 |
38 | override private function getType() : String {
39 | return Request.TYPE_SOCIAL;
40 | }
41 |
42 | override private function buildParameters() : ParameterHolder {
43 | var p = super.buildParameters();
44 |
45 | p.utmsn = this.socialInteraction.getNetwork();
46 | p.utmsa = this.socialInteraction.getAction();
47 | p.utmsid = this.socialInteraction.getTarget();
48 | if(p.utmsid == null) {
49 | // Default to page path like ga.js,
50 | // see http://code.google.com/apis/analytics/docs/tracking/gaTrackingSocial.html#settingUp
51 | p.utmsid = this.page.getPath();
52 | }
53 |
54 | return p;
55 | }
56 |
57 | public function getSocialInteraction() : SocialInteraction {
58 | return this.socialInteraction;
59 | }
60 |
61 | public function setSocialInteraction(socialInteraction:SocialInteraction) {
62 | this.socialInteraction = socialInteraction;
63 | }
64 |
65 | public function new(config:Config = null) {
66 | super(config);
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/src/googleAnalytics/internals/request/TransactionRequest.hx:
--------------------------------------------------------------------------------
1 | /**
2 | * Generic Server-Side Google Analytics Haxe Client
3 | *
4 | * This library is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU Lesser General Public
6 | * License (LGPL) as published by the Free Software Foundation; either
7 | * version 3 of the License, or (at your option) any later version.
8 | *
9 | * This library is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | * Lesser General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Lesser General Public
15 | * License along with this library; if not, write to the Free Software
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 | *
18 | * Google Analytics is a registered trademark of Google Inc.
19 | *
20 | * @link https://github.com/fbricker/haxe-ga
21 | *
22 | * @license http://www.gnu.org/licenses/lgpl.html
23 | * @author Federico Bricker
24 | * @copyright Copyright (c) 2012 SempaiGames (http://www.sempaigames.com)
25 | */
26 |
27 | package googleAnalytics.internals.request;
28 |
29 | import googleAnalytics.Transaction;
30 |
31 | import googleAnalytics.internals.ParameterHolder;
32 |
33 |
34 | class TransactionRequest extends Request {
35 |
36 | private var transaction : Transaction;
37 |
38 | override private function getType() : String {
39 | return Request.TYPE_TRANSACTION;
40 | }
41 |
42 | /**
43 | * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/ecommerce/Transaction.as#76
44 | */
45 | override private function buildParameters() : ParameterHolder {
46 | var p = super.buildParameters();
47 |
48 | p.utmtid = this.transaction.getOrderId();
49 | p.utmtst = this.transaction.getAffiliation();
50 | p.utmtto = this.transaction.getTotal();
51 | p.utmttx = this.transaction.getTax();
52 | p.utmtsp = this.transaction.getShipping();
53 | p.utmtci = this.transaction.getCity();
54 | p.utmtrg = this.transaction.getRegion();
55 | p.utmtco = this.transaction.getCountry();
56 |
57 | return p;
58 | }
59 |
60 | /**
61 | * The GA Javascript client doesn't send any visitor information for
62 | * e-commerce requests, so we don't either.
63 | */
64 | override private function buildVisitorParameters(p:ParameterHolder) : ParameterHolder {
65 | return p;
66 | }
67 |
68 | /**
69 | * The GA Javascript client doesn't send any custom variables for
70 | * e-commerce requests, so we don't either.
71 | */
72 | override private function buildCustomVariablesParameter(p:ParameterHolder) : ParameterHolder {
73 | return p;
74 | }
75 |
76 | public function getTransaction() : Transaction {
77 | return this.transaction;
78 | }
79 |
80 | public function setTransaction(transaction:Transaction) {
81 | this.transaction = transaction;
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/src/haxelib.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "haxe-ga",
3 | "url": "https://github.com/sempaigames/haxe-ga",
4 | "license": "MIT",
5 | "contributors":["fbricker"],
6 | "tags": ["cross","api","google","analytics"],
7 | "description": "Generic Google Analytics client that implements nearly every parameter and tracking feature of the original GA Javascript client.",
8 | "version": "0.5.5",
9 | "dependencies": {"extension-locale": ""},
10 | "releasenote": "Avoid negative values on events"
11 | }
12 |
--------------------------------------------------------------------------------
/src/include.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
--------------------------------------------------------------------------------
/src/installPackage.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | dir=`dirname "$0"`
3 | cd "$dir"
4 | haxelib remove haxe-ga
5 | haxelib local haxe-ga.zip
6 |
--------------------------------------------------------------------------------