├── .gitignore ├── GAnalytics.hx ├── LICENSE ├── NOTICE ├── README.md ├── build.bat ├── build.sh ├── dependencies ├── android │ ├── AndroidManifest.xml │ ├── build.gradle │ ├── build.xml │ ├── project.properties │ └── src │ │ └── org │ │ └── haxe │ │ └── extension │ │ └── GAnalytics.java └── ios │ └── libs │ └── libGoogleAnalyticsServices.a ├── haxelib.json ├── include.xml └── project ├── Build.xml ├── common └── ExternalInterface.cpp ├── iPhone ├── GAnalytics.mm └── include │ ├── GAI.h │ ├── GAIDictionaryBuilder.h │ ├── GAIEcommerceFields.h │ ├── GAIEcommerceProduct.h │ ├── GAIEcommerceProductAction.h │ ├── GAIEcommercePromotion.h │ ├── GAIFields.h │ ├── GAILogger.h │ ├── GAITrackedViewController.h │ └── GAITracker.h └── include └── Utils.h /.gitignore: -------------------------------------------------------------------------------- 1 | [Bb]in*/ 2 | [Ee]xport*/ 3 | .DS_Store 4 | .build 5 | *.build 6 | *.sublime-project 7 | *.sublime-workspace 8 | *.hxproj 9 | obj 10 | all_objs -------------------------------------------------------------------------------- /GAnalytics.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | /* 4 | Copyright (c) 2013, Hyperfiction 5 | All rights reserved. 6 | 7 | Update to Google Analytics V3 API and latest OpenFL API by Emiliano Angelini - Emibap 8 | 9 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 10 | 11 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 12 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | */ 16 | 17 | 18 | #if cpp 19 | import cpp.Lib; 20 | #elseif neko 21 | import neko.Lib; 22 | #end 23 | 24 | #if (android && openfl) 25 | import openfl.utils.JNI; 26 | #end 27 | 28 | 29 | class GAnalytics { 30 | 31 | // -------o public 32 | 33 | /** 34 | * Start the Ga tracking session 35 | * 36 | * @public 37 | * @param sUA : GA UA code ( String ) 38 | * @param iPeriod ( Int ) 39 | * @return void 40 | */ 41 | 42 | static public function startSession( sUA : String , iPeriod : Int = 15 ) : Void { 43 | #if (android && openfl) 44 | 45 | if (ganalytics_startNewSession_jni == null) ganalytics_startNewSession_jni = JNI.createStaticMethod ("org.haxe.extension.GAnalytics", "startSession", "(Ljava/lang/String;I)V"); 46 | 47 | ganalytics_startNewSession_jni(sUA, iPeriod); 48 | 49 | #elseif ios 50 | 51 | ganalytics_startNewSession(sUA, iPeriod); 52 | 53 | #end 54 | } 55 | 56 | /** 57 | * Stop the GA tracking session 58 | * 59 | * @public 60 | * @return void 61 | */ 62 | 63 | static public function stopSession( ) : Void { 64 | #if (android && openfl) 65 | 66 | #elseif ios 67 | 68 | ganalytics_stopSession(); 69 | 70 | #end 71 | } 72 | 73 | /** 74 | * Set the userID of a user 75 | * https://developers.google.com/analytics/devguides/collection/android/v4/user-id 76 | * https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#uid 77 | * 78 | * @public 79 | * @param sUserId : User Id ( String ) 80 | * @return void 81 | */ 82 | 83 | static public function setUserId( sUserId : String ) : Void { 84 | #if (android && openfl) 85 | 86 | if (ganalytics_setUserId_jni == null) ganalytics_setUserId_jni = JNI.createStaticMethod ("org.haxe.extension.GAnalytics", "setUserId", "(Ljava/lang/String;)V"); 87 | 88 | ganalytics_setUserId_jni(setUserId); 89 | 90 | #elseif ios 91 | 92 | ganalytics_setUserId(setUserId); 93 | 94 | #end 95 | } 96 | 97 | /** 98 | * Track a screen view 99 | * 100 | * @public 101 | * @param sScreen : Code of the screen to be tracked ( String ) 102 | * @return void 103 | */ 104 | 105 | static public function trackScreen( sScreen : String ) : Void { 106 | #if (android && openfl) 107 | 108 | if (ganalytics_trackScreen_jni == null) ganalytics_trackScreen_jni = JNI.createStaticMethod ("org.haxe.extension.GAnalytics", "trackScreen", "(Ljava/lang/String;)V"); 109 | 110 | ganalytics_trackScreen_jni(sScreen); 111 | 112 | #elseif ios 113 | 114 | ganalytics_sendScreenView(sScreen); 115 | 116 | #end 117 | } 118 | 119 | /** 120 | * Track a event 121 | * 122 | * @public 123 | * @param sCat : Event category ( String ) 124 | * @param sCat : Action ( String ) 125 | * @param sLabel : Event label ( String ) 126 | * @param value : Event value ( Int ) 127 | * @return void 128 | */ 129 | 130 | static public function trackEvent( sCat : String , sAction : String , sLabel : String , value : Int = 1 ) : Void { 131 | #if (android && openfl) 132 | 133 | if (ganalytics_trackEvent_jni == null) ganalytics_trackEvent_jni = JNI.createStaticMethod ("org.haxe.extension.GAnalytics", "trackEvent", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V"); 134 | ganalytics_trackEvent_jni(sCat, sAction, sLabel, value); 135 | 136 | #elseif ios 137 | ganalytics_sendEvent(sCat, sAction, sLabel, value); 138 | #end 139 | } 140 | 141 | /** 142 | * 143 | * 144 | * @public 145 | * @param sCat : Event category ( String ) 146 | * @param iInterval : Timing interval ( Int ) 147 | * @param sName : Timing name ( String ) 148 | * @param sLabel : Label ( String ) 149 | * @return void 150 | */ 151 | 152 | static public function sendTiming( sCat : String , iInterval : Int , sName : String , sLabel : String ) : Void { 153 | #if (android && openfl) 154 | 155 | if (ganalytics_sendTiming_jni == null) ganalytics_sendTiming_jni = JNI.createStaticMethod ("org.haxe.extension.GAnalytics", "sendTiming", "(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); 156 | ganalytics_sendTiming_jni(sCat, iInterval, sName, sLabel); 157 | 158 | #elseif ios 159 | 160 | ganalytics_sendTiming(sCat, iInterval, sName, sLabel); 161 | 162 | #end 163 | } 164 | 165 | /** 166 | * Set a custom dimension value 167 | * 168 | * @public 169 | * @param iIndex : Index of the dimension ( Int ) 170 | * @param sValue : Dimension value ( String ) 171 | * @return void 172 | */ 173 | 174 | static public function setCustom_dimension( iIndex : Int , sValue : String ) : Void { 175 | #if (android && openfl) 176 | 177 | #elseif ios 178 | ganalytics_setCustom_dimension(iIndex, sValue); 179 | #end 180 | } 181 | 182 | /** 183 | * Set a custom metric value 184 | * 185 | * @public 186 | * @param iIndex : Index of the metric ( Int ) 187 | * @param sValue : Metric value ( String ) 188 | * @return void 189 | */ 190 | 191 | static public function setCustom_metric( iIndex : Int , iValue : Int ) : Void { 192 | #if (android && openfl) 193 | 194 | #elseif ios 195 | 196 | ganalytics_setCustom_metric(iIndex, iValue); 197 | 198 | #end 199 | } 200 | 201 | /** 202 | * Track a social event 203 | * 204 | * @public 205 | * @param sSocial_network :Targetted social network ( String ) 206 | * @param sAction : Action ( String ) 207 | * @return void 208 | */ 209 | 210 | static public function trackSocial( sSocial_network : String , sAction : String , sTarget : String ) : Void { 211 | #if (android && openfl) 212 | 213 | if (ganalytics_trackSocial_jni == null) ganalytics_trackSocial_jni = JNI.createStaticMethod ("org.haxe.extension.GAnalytics", "trackSocial", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); 214 | ganalytics_trackSocial_jni(sSocial_network, sAction, sTarget); 215 | 216 | #elseif ios 217 | 218 | ganalytics_sendSocial(sSocial_network, sAction, sTarget); 219 | 220 | #end 221 | } 222 | 223 | /** 224 | * Send uncaught exception 225 | * 226 | * @public 227 | * @param description : A description of the exception (up to 100 characters) 228 | * @param fatal : Indicates whether the exception was fatal. True indicates fatal. 229 | * @return void 230 | */ 231 | 232 | static public function sendUncaughtException(description:String, fatal:Bool):Void { 233 | #if (android && openfl) 234 | 235 | if (ganalytics_sendUncaughtException_jni == null) ganalytics_sendUncaughtException_jni = JNI.createStaticMethod ("org.haxe.extension.GAnalytics", "sendUncaughtException", "(Ljava/lang/String;Z)V"); 236 | ganalytics_sendUncaughtException_jni(description, fatal); 237 | 238 | #elseif ios 239 | 240 | ganalytics_sendUncaughtException(description, fatal); 241 | 242 | #end 243 | } 244 | 245 | // -------o protected 246 | 247 | // -------o misc 248 | 249 | 250 | #if ios 251 | 252 | private static var ganalytics_startNewSession = Lib.load ("ganalytics", "ganalytics_startNewSession", 2); 253 | 254 | private static var ganalytics_stopSession = Lib.load ("ganalytics", "ganalytics_stopSession", 0); 255 | 256 | private static var ganalytics_sendScreenView = Lib.load ("ganalytics", "ganalytics_sendScreenView", 1); 257 | 258 | private static var ganalytics_sendEvent = Lib.load ("ganalytics", "ganalytics_sendEvent", 4); 259 | 260 | private static var ganalytics_sendTiming = Lib.load ("ganalytics", "ganalytics_sendTiming", 4); 261 | 262 | private static var ganalytics_setCustom_dimension = Lib.load ("ganalytics", "ganalytics_setCustom_dimension", 2); 263 | 264 | private static var ganalytics_setCustom_metric = Lib.load ("ganalytics", "ganalytics_setCustom_metric", 2); 265 | 266 | private static var ganalytics_sendSocial = Lib.load ("ganalytics", "ganalytics_sendSocial", 3); 267 | 268 | private static var ganalytics_setUserId = Lib.load ("ganalytics", "ganalytics_setUserId", 1); 269 | 270 | private static var ganalytics_sendUncaughtException = Lib.load ("ganalytics", "ganalytics_sendUncaughtException", 2); 271 | 272 | #end 273 | 274 | #if (android && openfl) 275 | 276 | private static var ganalytics_startNewSession_jni: Dynamic; 277 | 278 | private static var ganalytics_trackScreen_jni: Dynamic; 279 | 280 | private static var ganalytics_trackEvent_jni: Dynamic; 281 | 282 | private static var ganalytics_sendTiming_jni: Dynamic; 283 | 284 | private static var ganalytics_trackSocial_jni: Dynamic; 285 | 286 | private static var ganalytics_setUserId_jni: Dynamic; 287 | 288 | private static var ganalytics_sendUncaughtException_jni: Dynamic; 289 | 290 | #end 291 | 292 | 293 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Hyperfiction 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | THE FOLLOWING SETS FORTH ATTRIBUTION NOTICES FOR THIRD PARTY SOFTWARE THAT MAY BE CONTAINED IN PORTIONS OF THE FACEBOOK PRODUCT. 2 | 3 | ----- 4 | 5 | The following software may be included in this product: Android. This software contains the following license and notice below: 6 | 7 | Apache License 8 | Version 2.0, January 2004 9 | http://www.apache.org/licenses/ 10 | 11 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 12 | 13 | 1. Definitions. 14 | 15 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 16 | 17 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 18 | 19 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 20 | 21 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 22 | 23 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 24 | 25 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 26 | 27 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 28 | 29 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 30 | 31 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 32 | 33 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 34 | 35 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 36 | 37 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 38 | 39 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 40 | 41 | (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and 42 | 43 | (b) You must cause any modified files to carry prominent notices stating that You changed the files; and 44 | 45 | (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 46 | 47 | (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 48 | 49 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 50 | 51 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 52 | 53 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 54 | 55 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 56 | 57 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 58 | 59 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 60 | 61 | END OF TERMS AND CONDITIONS 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GAnalytics 2 | ============================= 3 | A Google Analytics native extension for OpenFL 4 | ----------------------------- 5 | 6 | This OpenFL native extension allows you to integrate Google Analytics ( v3.03 ) into your OpenFL application. 7 | The supported compilation targets are [iOS](https://developers.google.com/analytics/devguides/collection/ios/v3) & [Android](https://developers.google.com/analytics/devguides/collection/android/v3/) 8 | 9 | Installation 10 | ------------ 11 | You can install it directly from haxelib: 12 | 13 | haxelib install ganalytics 14 | 15 | 16 | If you didn't install this extension via haxelib and or to have the latest dev version you can download 17 | this sources and set its folder as the source using the following command: 18 | 19 | haxelib dev ganalytics path/to/your/downloaded/files 20 | 21 | Android Libraries 22 | ----------------- 23 | 24 | Since the recent Android SDK update, this library depends on `extension-googleplayservices-basement`. By default the dependent package does not include the Analytics Library, so make sure to add the package `google-play-services-analytics-impl` by running `select_dependencies.sh` in that extension, and selecting the `google-play-services-analytics-impl` package. 25 | 26 | Recompiling 27 | ----------- 28 | lime rebuild ganalytics ios 29 | 30 | or 31 | lime rebuild ganalytics android 32 | 33 | Usage 34 | ----- 35 | Just call the public methods on the GAnalytics class. 36 | 37 | **Basic reference** 38 | 39 | First start the session via : 40 | GAnalytics.startSession( "YOUR-UA-CODE" ); 41 | 42 | Tracking a screen view : 43 | GAnalytics.trackScreen( "your-page-code" ); 44 | 45 | Tracking an event : 46 | GAnalytics.trackEvent( "event-cat" , "event-action", "event-label", 1 ); 47 | 48 | For more advance methods just take a look a the GAnalytics class. 49 | All the Google Analytics V3 methods are supported( timing, metric , social , dimension... ) 50 | 51 | 52 | **This project was Originally forked from HypGA (Hyperfiction)** 53 | [hyperfiction.fr](http://hyperfiction.fr) 54 | 55 | License 56 | ------- 57 | This work is under BSD simplified License. 58 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | rmdir ndll\Android /s /q 2 | cd project 3 | rmdir obj /s /q 4 | 5 | lime rebuild . android 6 | 7 | REM haxelib run hxcpp Build.xml -Dmac 8 | REM haxelib run hxcpp Build.xml -Dandroid -DHXCPP_ARMV7 9 | REM haxelib run hxcpp Build.xml -Diphoneos -DHXCPP_ARMV7 10 | REM haxelib run hxcpp Build.xml -Diphonesim -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | rm -rf ndll\Android 2 | cd project 3 | rm -rf obj 4 | 5 | lime rebuild . ios 6 | -------------------------------------------------------------------------------- /dependencies/android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | ; 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /dependencies/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven { 4 | url "http://repo1.maven.org/maven2/" 5 | } 6 | } 7 | 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:2.1.0' 10 | } 11 | } 12 | 13 | apply plugin: 'com.android.library' 14 | 15 | android { 16 | compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) 17 | buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION 18 | 19 | sourceSets { 20 | main { 21 | manifest.srcFile 'AndroidManifest.xml' 22 | java.srcDirs = ["src"] 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | compile project(':deps:extension-api') 29 | compile project(':deps:google-play-services') 30 | } -------------------------------------------------------------------------------- /dependencies/android/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /dependencies/android/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "build.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | android.library=true 11 | 12 | android.library.reference.1=../extension-api 13 | android.library.reference.2=../google-play-services-basement 14 | android.library.reference.3=../google-play-services-analytics-impl 15 | 16 | # Project target. 17 | target=android-::ANDROID_TARGET_SDK_VERSION:: 18 | -------------------------------------------------------------------------------- /dependencies/android/src/org/haxe/extension/GAnalytics.java: -------------------------------------------------------------------------------- 1 | package org.haxe.extension; 2 | 3 | 4 | import com.google.android.gms.analytics.*; 5 | 6 | import android.util.Log; 7 | import android.app.Activity; 8 | import android.content.res.AssetManager; 9 | import android.content.Context; 10 | import android.content.Intent; 11 | import android.os.Bundle; 12 | import android.os.Handler; 13 | import android.view.View; 14 | 15 | /* 16 | You can use the Android Extension class in order to hook 17 | into the Android activity lifecycle. This is not required 18 | for standard Java code, this is designed for when you need 19 | deeper integration. 20 | 21 | You can access additional references from the Extension class, 22 | depending on your needs: 23 | 24 | - Extension.assetManager (android.content.res.AssetManager) 25 | - Extension.callbackHandler (android.os.Handler) 26 | - Extension.mainActivity (android.app.Activity) 27 | - Extension.mainContext (android.content.Context) 28 | - Extension.mainView (android.view.View) 29 | 30 | You can also make references to static or instance methods 31 | and properties on Java classes. These classes can be included 32 | as single files using within your 33 | project, or use the full Android Library Project format (such 34 | as this example) in order to include your own AndroidManifest 35 | data, additional dependencies, etc. 36 | 37 | These are also optional, though this example shows a static 38 | function for performing a single task, like returning a value 39 | back to Haxe from Java. 40 | */ 41 | public class GAnalytics extends Extension { 42 | 43 | 44 | 45 | 46 | private static Tracker _gaTracker; 47 | 48 | // -------o constructor 49 | 50 | /** 51 | * constructor 52 | * 53 | * @param 54 | * @return void 55 | */ 56 | public GAnalytics( ){ 57 | //trace("constructor"); 58 | } 59 | 60 | // -------o public 61 | 62 | /** 63 | * 64 | * 65 | * @public 66 | * @return void 67 | */ 68 | public static void setDry_run( boolean b ){ 69 | GoogleAnalytics.getInstance( mainContext ).setDryRun( b ); 70 | } 71 | 72 | /** 73 | * 74 | * 75 | * @public 76 | * @return void 77 | */ 78 | public static void setOpt_out( boolean b ){ 79 | GoogleAnalytics.getInstance( mainContext ).setAppOptOut( b ); 80 | } 81 | 82 | 83 | /** 84 | * 85 | * 86 | * @public 87 | * @return void 88 | */ 89 | public static void startSession( String sUA_code , int iPeriod ) { 90 | //trace("startSession ::: "+sUA_code+" - "+iPeriod); 91 | //_gaTracker = GoogleAnalytics.getInstance( mainContext ).getTracker( sUA_code ); 92 | _gaTracker = GoogleAnalytics.getInstance( mainContext ).newTracker( sUA_code ); 93 | 94 | setDispatch_period( iPeriod ); 95 | } 96 | 97 | /** 98 | * 99 | * 100 | * @public 101 | * @return void 102 | */ 103 | public static void setDispatch_period( int iPeriod ) { 104 | GoogleAnalytics.getInstance( mainContext ).setLocalDispatchPeriod(iPeriod); 105 | } 106 | 107 | /** 108 | * 109 | * 110 | * @public 111 | * @return void 112 | */ 113 | public static void setUserId( String userId ) { 114 | _gaTracker.set("&uid", userId); 115 | } 116 | 117 | 118 | /** 119 | * 120 | * 121 | * @public 122 | * @return void 123 | */ 124 | public static void dispatch( ){ 125 | GoogleAnalytics.getInstance( mainContext ).dispatchLocalHits( ); 126 | } 127 | 128 | /** 129 | * 130 | * 131 | * @public 132 | * @return void 133 | */ 134 | public static void trackScreen( String sScreen ){ 135 | //trace("trackScreen ::: "+sScreen); 136 | //_gaTracker.send( MapBuilder.createAppView( ).set( Fields.SCREEN_NAME , sScreen ).build( ) ); 137 | 138 | Log.d("GoogleAnalytic","Track screen: " + sScreen); 139 | 140 | _gaTracker.setScreenName( sScreen ); 141 | _gaTracker.send( new HitBuilders.ScreenViewBuilder().build() ); 142 | 143 | } 144 | 145 | /** 146 | * 147 | * 148 | * @public 149 | * @return void 150 | */ 151 | public static void trackEvent( String sCat , String sAction , String sLabel , int iVal ){ 152 | //_gaTracker.send( MapBuilder.createEvent( sCat , sAction , sLabel , Long.valueOf( iVal ) ).build( ) ); 153 | 154 | Log.d("GoogleAnalytic","Track event: " + sCat + " : " + sAction + " : " + sLabel); 155 | 156 | _gaTracker.send( new HitBuilders.EventBuilder() 157 | .setCategory(sCat) 158 | .setAction(sAction) 159 | .setLabel(sLabel) 160 | .build() ); 161 | } 162 | 163 | /** 164 | * 165 | * 166 | * @public 167 | * @return void 168 | */ 169 | public static void trackSocial( String sSocial_network , String sAction , String sTarget ){ 170 | //_gaTracker.send( MapBuilder.createSocial( sSocial_network , sAction , sTarget ).build( ) ); 171 | 172 | _gaTracker.send( new HitBuilders.SocialBuilder() 173 | .setNetwork(sSocial_network) 174 | .setAction(sAction) 175 | .setTarget(sTarget) 176 | .build() ); 177 | } 178 | 179 | /** 180 | * 181 | * 182 | * @public 183 | * @return void 184 | */ 185 | public static void sendTiming( String sCat , int iInterval , String sName , String sLabel ){ 186 | //_gaTracker.send( MapBuilder.createTiming( sCat , Long.valueOf( iInterval ) , sName , sLabel ).build( ) ); 187 | 188 | _gaTracker.send( new HitBuilders.TimingBuilder() 189 | .setCategory(sCat) 190 | .setValue(iInterval) 191 | .setVariable(sName) 192 | .setLabel(sLabel) 193 | .build() ); 194 | } 195 | 196 | public static void sendUncaughtException(String description, boolean fatal) { 197 | //_gaTracker.send(MapBuilder.createException(description, (Boolean)fatal).build()); 198 | 199 | _gaTracker.send( new HitBuilders.ExceptionBuilder() 200 | .setDescription(description) 201 | .setFatal(fatal) 202 | .build() ); 203 | } 204 | 205 | // -------o protected 206 | 207 | 208 | 209 | // -------o misc 210 | 211 | 212 | 213 | public static int sampleMethod (int inputValue) { 214 | 215 | return inputValue * 100; 216 | 217 | } 218 | 219 | 220 | /** 221 | * Called when an activity you launched exits, giving you the requestCode 222 | * you started it with, the resultCode it returned, and any additional data 223 | * from it. 224 | */ 225 | public boolean onActivityResult (int requestCode, int resultCode, Intent data) { 226 | 227 | return true; 228 | 229 | } 230 | 231 | 232 | /** 233 | * Called when the activity is starting. 234 | */ 235 | public void onCreate (Bundle savedInstanceState) { 236 | 237 | 238 | 239 | } 240 | 241 | 242 | /** 243 | * Perform any final cleanup before an activity is destroyed. 244 | */ 245 | public void onDestroy () { 246 | 247 | 248 | 249 | } 250 | 251 | 252 | /** 253 | * Called as part of the activity lifecycle when an activity is going into 254 | * the background, but has not (yet) been killed. 255 | */ 256 | public void onPause () { 257 | 258 | 259 | 260 | } 261 | 262 | 263 | /** 264 | * Called after {@link #onStop} when the current activity is being 265 | * re-displayed to the user (the user has navigated back to it). 266 | */ 267 | public void onRestart () { 268 | 269 | GoogleAnalytics.getInstance( mainContext ).reportActivityStop( mainActivity ); 270 | 271 | } 272 | 273 | 274 | /** 275 | * Called after {@link #onRestart}, or {@link #onPause}, for your activity 276 | * to start interacting with the user. 277 | */ 278 | public void onResume () { 279 | 280 | 281 | 282 | } 283 | 284 | 285 | /** 286 | * Called after {@link #onCreate} — or after {@link #onRestart} when 287 | * the activity had been stopped, but is now again being displayed to the 288 | * user. 289 | */ 290 | public void onStart () { 291 | 292 | GoogleAnalytics.getInstance( mainContext ).reportActivityStart( mainActivity ); 293 | GoogleAnalytics.getInstance( mainContext ).getLogger( ).setLogLevel( Logger.LogLevel.VERBOSE ); 294 | 295 | } 296 | 297 | 298 | /** 299 | * Called when the activity is no longer visible to the user, because 300 | * another activity has been resumed and is covering this one. 301 | */ 302 | public void onStop () { 303 | 304 | 305 | 306 | } 307 | 308 | 309 | } -------------------------------------------------------------------------------- /dependencies/ios/libs/libGoogleAnalyticsServices.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emibap/GAnalytics/4c643b1637985aa1e4c59705f1b008a38008015a/dependencies/ios/libs/libGoogleAnalyticsServices.a -------------------------------------------------------------------------------- /haxelib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ganalytics", 3 | "url": "http://github.com/emibap/GAnalytics", 4 | "license": "BSD", 5 | "tags": ["OpenFL","analytics","google"], 6 | "description": "A Google Analytics native extension for OpenFL", 7 | "version": "0.0.3", 8 | "releasenote": "remove unused sample method", 9 | "contributors": ["emibap"], 10 | "dependencies": { 11 | "extension-googleplayservices-basement": "", 12 | "google-play-services": "" 13 | } 14 | } -------------------------------------------------------------------------------- /include.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 |
12 | 13 |
14 | 15 | 16 |
17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
-------------------------------------------------------------------------------- /project/Build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /project/common/ExternalInterface.cpp: -------------------------------------------------------------------------------- 1 | #ifndef STATIC_LINK 2 | #define IMPLEMENT_API 3 | #endif 4 | 5 | #if defined(HX_WINDOWS) || defined(HX_MACOS) || defined(HX_LINUX) 6 | #define NEKO_COMPATIBLE 7 | #endif 8 | 9 | 10 | #include 11 | #include "Utils.h" 12 | 13 | 14 | using namespace ganalytics; 15 | 16 | 17 | 18 | #ifdef IPHONE 19 | 20 | static value ganalytics_startNewSession( value sUA_code , value iPeriod ){ 21 | startNewSession( val_string( sUA_code ) , val_int( iPeriod ) ); 22 | return alloc_null( ); 23 | } 24 | DEFINE_PRIM( ganalytics_startNewSession , 2 ); 25 | 26 | static value ganalytics_sendScreenView( value sScreen ){ 27 | sendScreenView( val_string( sScreen ) ); 28 | return alloc_null( ); 29 | } 30 | DEFINE_PRIM( ganalytics_sendScreenView , 1 ); 31 | 32 | static value ganalytics_setUserId( value sUserId ){ 33 | setUserId( val_string( sUserId ) ); 34 | return alloc_null( ); 35 | } 36 | DEFINE_PRIM( ganalytics_setUserId , 1 ); 37 | 38 | static value ganalytics_sendEvent( value sCat , value sAction , value sLabel , value iValue ){ 39 | sendEvent( 40 | val_string( sCat ), 41 | val_string( sAction ), 42 | val_string( sLabel ), 43 | val_int( iValue ) 44 | ); 45 | return alloc_null( ); 46 | } 47 | DEFINE_PRIM( ganalytics_sendEvent , 4 ); 48 | 49 | static value ganalytics_setCustom_dimension( value iIndex , value sValue ){ 50 | setCustom_dimension( val_int( iIndex ) , val_string( sValue ) ); 51 | return alloc_null( ); 52 | } 53 | DEFINE_PRIM( ganalytics_setCustom_dimension , 2 ); 54 | 55 | static value ganalytics_setCustom_metric( value iIndex , value iMetric ){ 56 | setCustom_metric( val_int( iIndex ) , val_int( iMetric ) ); 57 | return alloc_null( ); 58 | } 59 | DEFINE_PRIM( ganalytics_setCustom_metric , 2 ); 60 | 61 | static value ganalytics_sendTiming( value sCat , value interval , value name , value label ){ 62 | sendTiming( val_string( sCat ) , val_int( interval ) , val_string( name ) , val_string( label ) ); 63 | return alloc_null( ); 64 | } 65 | DEFINE_PRIM( ganalytics_sendTiming , 4 ); 66 | 67 | static value ganalytics_stopSession( ){ 68 | stopSession( ); 69 | return alloc_null( ); 70 | } 71 | DEFINE_PRIM( ganalytics_stopSession , 0 ); 72 | 73 | static value ganalytics_sendSocial( value sNetwork , value sAction , value sTarget ){ 74 | sendSocial( val_string( sNetwork ) , val_string( sAction ) , val_string( sTarget ) ); 75 | return alloc_null( ); 76 | } 77 | DEFINE_PRIM( ganalytics_sendSocial , 3 ); 78 | 79 | static value ganalytics_sendUncaughtException( value description , value fatal ){ 80 | sendUncaughtException( val_string( description ) , val_bool( fatal ) ); 81 | return alloc_null( ); 82 | } 83 | DEFINE_PRIM( ganalytics_sendUncaughtException , 3 ); 84 | 85 | #endif 86 | 87 | 88 | extern "C" void ganalytics_main () { 89 | 90 | val_int(0); // Fix Neko init 91 | 92 | } 93 | DEFINE_ENTRY_POINT (ganalytics_main); 94 | 95 | 96 | extern "C" int ganalytics_register_prims () { return 0; } -------------------------------------------------------------------------------- /project/iPhone/GAnalytics.mm: -------------------------------------------------------------------------------- 1 | #include "Utils.h" 2 | 3 | #import 4 | #import "GAI.h" 5 | #import "GAITracker.h" 6 | #import "GAIDictionaryBuilder.h" 7 | #import "GAIFields.h" 8 | 9 | namespace ganalytics { 10 | 11 | static id tracker; 12 | 13 | void startNewSession( const char *sUID , int iPeriod ){ 14 | NSString *NSUID = [NSString stringWithUTF8String:sUID]; 15 | //NSLog( @"startNewSession %@" , NSUID ); 16 | tracker = [[GAI sharedInstance] trackerWithTrackingId:NSUID]; 17 | //tracker.debug = YES; 18 | } 19 | 20 | void sendScreenView( const char *sScreen ) { 21 | NSString *NSScreen = [[NSString alloc] initWithUTF8String:sScreen]; 22 | //NSLog( @"sendScreenView %@" , NSScreen ); 23 | // Set the screen name on the tracker so that it is used in all hits sent from this screen. 24 | [tracker set:kGAIScreenName value:NSScreen]; 25 | 26 | // Send a screenview. 27 | [tracker send:[[GAIDictionaryBuilder createScreenView] build]]; 28 | } 29 | 30 | void setUserId( const char *sUserId ) { 31 | NSString *NSUserId = [[NSString alloc] initWithUTF8String:sUserId]; 32 | // Set the user id on the tracker so that it is used in all hits sent from this screen. 33 | [tracker set:kGAIUserId value:NSUserId]; 34 | } 35 | 36 | void sendEvent( const char *sCat , const char *sAction , const char *sLabel , int iValue ){ 37 | NSString *NS_Cat = [ [NSString alloc] initWithUTF8String:sCat]; 38 | NSString *NS_Act = [ [NSString alloc] initWithUTF8String:sAction]; 39 | NSString *NS_Lab = [ [NSString alloc] initWithUTF8String:sLabel]; 40 | //NSLog( @"SendEvent cat:%@ act:%@ label:%@ val%i" , NS_Cat , NS_Act , NS_Lab , iValue ); 41 | //[tracker sendEventWithCategory:NS_Cat withAction:NS_Act withLabel:NS_Lab withValue:[NSNumber numberWithInt:iValue]]; 42 | 43 | [tracker send:[[GAIDictionaryBuilder createEventWithCategory:NS_Cat 44 | action:NS_Act 45 | label:NS_Lab 46 | value:[NSNumber numberWithInt:iValue]] build]]; 47 | } 48 | 49 | void setCustom_dimension( int iIndex , const char *sValue ){ 50 | NSString *NS_Val = [[NSString alloc] initWithUTF8String:sValue]; 51 | //NSLog( @"setCustom_dimension index:%i value:%s" , iIndex , sValue ); 52 | //[tracker setCustom:iIndex dimension:NS_Val]; 53 | 54 | [tracker set:[GAIFields customDimensionForIndex: iIndex] 55 | value:NS_Val]; 56 | 57 | } 58 | 59 | void setCustom_metric( int iIndex , int iMetric ){ 60 | //NSLog( @"setCustom_metric index:%i metrid:%i",iIndex,iMetric); 61 | //[tracker setCustom:iIndex metric:[NSNumber numberWithInt:iMetric]]; 62 | 63 | [tracker set:[GAIFields customMetricForIndex: iIndex] 64 | value:[NSString stringWithFormat:@"%d", iMetric]]; 65 | } 66 | 67 | void sendTiming( const char *sCat , int iInterval , const char *sName , const char *sLabel ){ 68 | NSString *NS_Cat = [ [NSString alloc] initWithUTF8String:sCat]; 69 | NSString *NS_Name = [ [NSString alloc] initWithUTF8String:sName]; 70 | NSString *NS_Label = [ [NSString alloc] initWithUTF8String:sLabel]; 71 | //[tracker sendTimingWithCategory:NS_Cat withValue:iInterval withName:NS_Name withLabel:NS_Label]; 72 | 73 | [tracker send:[[GAIDictionaryBuilder createTimingWithCategory:NS_Cat 74 | interval:[NSNumber numberWithInt:iInterval] 75 | name:NS_Name 76 | label:NS_Label] build]]; 77 | } 78 | 79 | void sendSocial( const char *sSocial_network , const char *sAction , const char *sTarget ){ 80 | NSString *NS_Net = [ [NSString alloc] initWithUTF8String:sSocial_network]; 81 | NSString *NS_Act = [ [NSString alloc] initWithUTF8String:sAction]; 82 | NSString *NS_Tgt = [ [NSString alloc] initWithUTF8String:sTarget]; 83 | //[tracker sendSocial:NS_Net withAction:NS_Act withTarget:NS_Tgt]; 84 | 85 | [tracker send:[[GAIDictionaryBuilder createSocialWithNetwork:NS_Net 86 | action:NS_Act 87 | target:NS_Tgt] build]]; 88 | 89 | } 90 | 91 | void sendUncaughtException( const char *description, bool fatal ){ 92 | NSString *NSDescription = [ [NSString alloc] initWithUTF8String:description]; 93 | 94 | [tracker send:[[GAIDictionaryBuilder createExceptionWithDescription:NSDescription withFatal:fatal ? @YES : @NO] build]]; 95 | } 96 | 97 | void stopSession( ){ 98 | //[[GANTracker sharedTracker] stopTracker]; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /project/iPhone/include/GAI.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAI.h 3 | @abstract Google Analytics iOS SDK Header 4 | @version 3.17 5 | @copyright Copyright 2015 Google Inc. All rights reserved. 6 | */ 7 | 8 | #import 9 | 10 | #import "GAILogger.h" 11 | #import "GAITrackedViewController.h" 12 | #import "GAITracker.h" 13 | 14 | typedef NS_ENUM(NSUInteger, GAIDispatchResult) { 15 | kGAIDispatchNoData, 16 | kGAIDispatchGood, 17 | kGAIDispatchError 18 | }; 19 | 20 | /*! Google Analytics product string. */ 21 | extern NSString *const kGAIProduct; 22 | 23 | /*! Google Analytics version string. */ 24 | extern NSString *const kGAIVersion; 25 | 26 | /*! 27 | NSError objects returned by the Google Analytics SDK may have this error domain 28 | to indicate that the error originated in the Google Analytics SDK. 29 | */ 30 | extern NSString *const kGAIErrorDomain; 31 | 32 | /*! Google Analytics error codes. */ 33 | typedef enum { 34 | // This error code indicates that there was no error. Never used. 35 | kGAINoError = 0, 36 | 37 | // This error code indicates that there was a database-related error. 38 | kGAIDatabaseError, 39 | 40 | // This error code indicates that there was a network-related error. 41 | kGAINetworkError, 42 | } GAIErrorCode; 43 | 44 | /*! 45 | Google Analytics iOS top-level class. Provides facilities to create trackers 46 | and set behaviorial flags. 47 | */ 48 | @interface GAI : NSObject 49 | 50 | /*! 51 | For convenience, this class exposes a default tracker instance. 52 | This is initialized to `nil` and will be set to the first tracker that is 53 | instantiated in trackerWithTrackingId:. It may be overridden as desired. 54 | 55 | The GAITrackedViewController class will, by default, use this tracker instance. 56 | */ 57 | @property(nonatomic, assign) id defaultTracker; 58 | 59 | /*! 60 | The GAILogger to use. 61 | */ 62 | @property(nonatomic, retain) id logger; 63 | 64 | /*! 65 | When this is true, no tracking information will be gathered; tracking calls 66 | will effectively become no-ops. When set to true, all tracking information that 67 | has not yet been submitted. The value of this flag will be persisted 68 | automatically by the SDK. Developers can optionally use this flag to implement 69 | an opt-out setting in the app to allows users to opt out of Google Analytics 70 | tracking. 71 | 72 | This is set to `NO` the first time the Google Analytics SDK is used on a 73 | device, and is persisted thereafter. 74 | */ 75 | @property(nonatomic, assign) BOOL optOut; 76 | 77 | /*! 78 | If this value is positive, tracking information will be automatically 79 | dispatched every dispatchInterval seconds. Otherwise, tracking information must 80 | be sent manually by calling dispatch. 81 | 82 | By default, this is set to `120`, which indicates tracking information should 83 | be dispatched automatically every 120 seconds. 84 | */ 85 | @property(nonatomic, assign) NSTimeInterval dispatchInterval; 86 | 87 | /*! 88 | When set to true, the SDK will record the currently registered uncaught 89 | exception handler, and then register an uncaught exception handler which tracks 90 | the exceptions that occurred using defaultTracker. If defaultTracker is not 91 | `nil`, this function will track the exception on the tracker and attempt to 92 | dispatch any outstanding tracking information for 5 seconds. It will then call 93 | the previously registered exception handler, if any. When set back to false, 94 | the previously registered uncaught exception handler will be restored. 95 | */ 96 | @property(nonatomic, assign) BOOL trackUncaughtExceptions; 97 | 98 | /*! 99 | When this is 'YES', no tracking information will be sent. Defaults to 'NO'. 100 | */ 101 | @property(nonatomic, assign) BOOL dryRun; 102 | 103 | /*! Get the shared instance of the Google Analytics for iOS class. */ 104 | + (GAI *)sharedInstance; 105 | 106 | /*! 107 | Creates or retrieves a GAITracker implementation with the specified name and 108 | tracking ID. If the tracker for the specified name does not already exist, then 109 | it will be created and returned; otherwise, the existing tracker will be 110 | returned. If the existing tracker for the respective name has a different 111 | tracking ID, that tracking ID is not changed by this method. If defaultTracker 112 | is not set, it will be set to the tracker instance returned here. 113 | 114 | @param name The name of this tracker. Must not be `nil` or empty. 115 | 116 | @param trackingID The tracking ID to use for this tracker. It should be of 117 | the form `UA-xxxxx-y`. 118 | 119 | @return A GAITracker associated with the specified name. The tracker 120 | can be used to send tracking data to Google Analytics. The first time this 121 | method is called with a particular name, the tracker for that name will be 122 | returned, and subsequent calls with the same name will return the same 123 | instance. It is not necessary to retain the tracker because the tracker will be 124 | retained internally by the library. 125 | 126 | If an error occurs or the name is not valid, this method will return 127 | `nil`. 128 | */ 129 | - (id)trackerWithName:(NSString *)name 130 | trackingId:(NSString *)trackingId; 131 | 132 | /*! 133 | Creates or retrieves a GAITracker implementation with name equal to 134 | the specified tracking ID. If the tracker for the respective name does not 135 | already exist, it is created, has it's tracking ID set to |trackingId|, 136 | and is returned; otherwise, the existing tracker is returned. If the existing 137 | tracker for the respective name has a different tracking ID, that tracking ID 138 | is not changed by this method. If defaultTracker is not set, it is set to the 139 | tracker instance returned here. 140 | 141 | @param trackingID The tracking ID to use for this tracker. It should be of 142 | the form `UA-xxxxx-y`. The name of the tracker will be the same as trackingID. 143 | 144 | @return A GAITracker associated with the specified trackingID. The tracker 145 | can be used to send tracking data to Google Analytics. The first time this 146 | method is called with a particular trackingID, the tracker for the respective 147 | name will be returned, and subsequent calls with the same trackingID 148 | will return the same instance. It is not necessary to retain the tracker 149 | because the tracker will be retained internally by the library. 150 | 151 | If an error occurs or the trackingId is not valid, this method will return 152 | `nil`. 153 | */ 154 | - (id)trackerWithTrackingId:(NSString *)trackingId; 155 | 156 | /*! 157 | Remove a tracker from the trackers dictionary. If it is the default tracker, 158 | clears the default tracker as well. 159 | 160 | @param name The name of the tracker. 161 | */ 162 | - (void)removeTrackerByName:(NSString *)name; 163 | 164 | /*! 165 | Dispatches any pending tracking information. 166 | 167 | Note that this does not have any effect on dispatchInterval, and can be used in 168 | conjunction with periodic dispatch. */ 169 | - (void)dispatch; 170 | 171 | /*! 172 | Dispatches the next tracking beacon in the queue, calling completionHandler when 173 | the tracking beacon has either been sent (returning kGAIDispatchGood) or an error has resulted 174 | (returning kGAIDispatchError). If there is no network connection or there is no data to send, 175 | kGAIDispatchNoData is returned. 176 | 177 | Note that calling this method with a non-nil completionHandler disables periodic dispatch. 178 | Periodic dispatch can be reenabled by setting the dispatchInterval to a positive number when 179 | the app resumes from the background. 180 | 181 | Calling this method with a nil completionHandler is the same as calling the dispatch 182 | above. 183 | 184 | This method can be used for background data fetching in iOS 7.0 or later. It would be wise to 185 | call this when the application is exiting to initiate the submission of any unsubmitted 186 | tracking information. 187 | 188 | @param completionHandler The block to run after a single dispatch request. The GAIDispatchResult 189 | param indicates whether the dispatch succeeded, had an error, or had no hits to dispatch. 190 | */ 191 | - (void)dispatchWithCompletionHandler:(void (^)(GAIDispatchResult result))completionHandler; 192 | @end 193 | -------------------------------------------------------------------------------- /project/iPhone/include/GAIDictionaryBuilder.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAIDictionaryBuilder.h 3 | @abstract Google Analytics iOS SDK Hit Format Header 4 | @copyright Copyright 2013 Google Inc. All rights reserved. 5 | */ 6 | 7 | #import 8 | 9 | #import "GAIEcommerceProduct.h" 10 | #import "GAIEcommerceProductAction.h" 11 | #import "GAIEcommercePromotion.h" 12 | 13 | /*! 14 | * Helper class to build a dictionary of hit parameters and values. 15 | *
16 | * Examples: 17 | * 18 | * id t = // get a tracker. 19 | * [t send:[[[GAIDictionaryBuilder createEventWithCategory:@"EventCategory" 20 | * action:@"EventAction" 21 | * label:nil 22 | * value:nil] 23 | * set:@"dimension1" forKey:[GAIFields customDimensionForIndex:1]] build]]; 24 | * 25 | * This will send an event hit type with the specified parameters 26 | * and a custom dimension parameter. 27 | *
28 | * If you want to send a parameter with all hits, set it on GAITracker directly. 29 | * 30 | * [t set:kGAIScreenName value:@"Home"]; 31 | * [t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+" 32 | * action:@"PlusOne" 33 | * target:@"SOME_URL"] build]]; 34 | * [t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+" 35 | * action:@"Share" 36 | * target:@"SOME_POST"] build]]; 37 | * [t send:[[GAIDictionaryBuilder createSocialWithNetwork:@"Google+" 38 | * action:@"HangOut" 39 | * target:@"SOME_CIRCLE"] 40 | * build]]; 41 | * 42 | * You can override a value set on the tracker by adding it to the dictionary. 43 | * 44 | * [t set:kGAIScreenName value:@"Home"]; 45 | * [t send:...]; 46 | * [t send[[[GAIDictionaryBuilder createEventWithCategory:@"click" 47 | * action:@"popup" 48 | * label:nil 49 | * value:nil] 50 | * set:@"popup title" forKey:kGAIScreenName] build]]; 51 | * 52 | * The values set via [GAIDictionaryBuilder set] or 53 | * [GAIDictionaryBuilder setAll] will override any existing values in the 54 | * GAIDictionaryBuilder object (i.e. initialized by 55 | * [GAIDictionaryBuilder createXYZ]). e.g. 56 | * 57 | * GAIDictionaryBuilder *m = 58 | * GAIDictionaryBuilder createTimingWithCategory:@"category" 59 | * interval:@0 60 | * name:@"name" 61 | * label:nil]; 62 | * [t send:[m.set:@"10" forKey:kGAITimingVar] build]; 63 | * [t send:[m.set:@"20" forKey:kGAITimingVar] build]; 64 | * 65 | */ 66 | @interface GAIDictionaryBuilder : NSObject 67 | 68 | - (GAIDictionaryBuilder *)set:(NSString *)value 69 | forKey:(NSString *)key; 70 | 71 | /*! 72 | * Copies all the name-value pairs from params into this object, ignoring any 73 | * keys that are not NSString and any values that are neither NSString or 74 | * NSNull. 75 | */ 76 | - (GAIDictionaryBuilder *)setAll:(NSDictionary *)params; 77 | 78 | /*! 79 | * Returns the value for the input parameter paramName, or nil if paramName 80 | * is not present. 81 | */ 82 | - (NSString *)get:(NSString *)paramName; 83 | 84 | /*! 85 | * Return an NSMutableDictionary object with all the parameters set in this 86 | */ 87 | - (NSMutableDictionary *)build; 88 | 89 | /*! 90 | * Parses and translates utm campaign parameters to analytics campaign param 91 | * and returns them as a map. 92 | * 93 | * @param params url containing utm campaign parameters. 94 | * 95 | * Valid campaign parameters are: 96 | *
    97 | *
  • utm_id
  • 98 | *
  • utm_campaign
  • 99 | *
  • utm_content
  • 100 | *
  • utm_medium
  • 101 | *
  • utm_source
  • 102 | *
  • utm_term
  • 103 | *
  • dclid
  • 104 | *
  • gclid
  • 105 | *
  • gmob_t
  • 106 | *
  • aclid
  • 107 | *
  • anid
  • 108 | *
109 | *

110 | * Example: 111 | * http://my.site.com/index.html?utm_campaign=wow&utm_source=source 112 | * utm_campaign=wow&utm_source=source. 113 | *

114 | * For more information on manual and auto-tagging, see 115 | * https://support.google.com/analytics/answer/1733663?hl=en 116 | */ 117 | - (GAIDictionaryBuilder *)setCampaignParametersFromUrl:(NSString *)urlString; 118 | 119 | /*! 120 | Returns a GAIDictionaryBuilder object with parameters specific to an appview 121 | hit. 122 | 123 | Note that using this method will not set the screen name for followon hits. To 124 | do that you need to call set:kGAIDescription value: on the 125 | GAITracker instance. 126 | 127 | This method is deprecated. Use createScreenView instead. 128 | */ 129 | + (GAIDictionaryBuilder *)createAppView DEPRECATED_MSG_ATTRIBUTE("Use createScreenView instead."); 130 | 131 | /*! 132 | Returns a GAIDictionaryBuilder object with parameters specific to a screenview 133 | hit. 134 | 135 | Note that using this method will not set the screen name for followon hits. To 136 | do that you need to call set:kGAIDescription value: on the 137 | GAITracker instance. 138 | */ 139 | + (GAIDictionaryBuilder *)createScreenView; 140 | 141 | /*! 142 | Returns a GAIDictionaryBuilder object with parameters specific to an event hit. 143 | */ 144 | + (GAIDictionaryBuilder *)createEventWithCategory:(NSString *)category 145 | action:(NSString *)action 146 | label:(NSString *)label 147 | value:(NSNumber *)value; 148 | 149 | /*! 150 | Returns a GAIDictionaryBuilder object with parameters specific to an exception 151 | hit. 152 | */ 153 | + (GAIDictionaryBuilder *)createExceptionWithDescription:(NSString *)description 154 | withFatal:(NSNumber *)fatal; 155 | 156 | /*! 157 | Returns a GAIDictionaryBuilder object with parameters specific to an item hit. 158 | */ 159 | + (GAIDictionaryBuilder *)createItemWithTransactionId:(NSString *)transactionId 160 | name:(NSString *)name 161 | sku:(NSString *)sku 162 | category:(NSString *)category 163 | price:(NSNumber *)price 164 | quantity:(NSNumber *)quantity 165 | currencyCode:(NSString *)currencyCode; 166 | 167 | /*! 168 | Returns a GAIDictionaryBuilder object with parameters specific to a social hit. 169 | */ 170 | + (GAIDictionaryBuilder *)createSocialWithNetwork:(NSString *)network 171 | action:(NSString *)action 172 | target:(NSString *)target; 173 | 174 | /*! 175 | Returns a GAIDictionaryBuilder object with parameters specific to a timing hit. 176 | */ 177 | + (GAIDictionaryBuilder *)createTimingWithCategory:(NSString *)category 178 | interval:(NSNumber *)intervalMillis 179 | name:(NSString *)name 180 | label:(NSString *)label; 181 | 182 | /*! 183 | Returns a GAIDictionaryBuilder object with parameters specific to a transaction 184 | hit. 185 | */ 186 | + (GAIDictionaryBuilder *)createTransactionWithId:(NSString *)transactionId 187 | affiliation:(NSString *)affiliation 188 | revenue:(NSNumber *)revenue 189 | tax:(NSNumber *)tax 190 | shipping:(NSNumber *)shipping 191 | currencyCode:(NSString *)currencyCode; 192 | 193 | /*! 194 | Set the product action field for this hit. 195 | */ 196 | - (GAIDictionaryBuilder *)setProductAction:(GAIEcommerceProductAction *)productAction; 197 | 198 | /*! 199 | Adds a product to this hit. 200 | */ 201 | - (GAIDictionaryBuilder *)addProduct:(GAIEcommerceProduct *)product; 202 | 203 | /*! 204 | Add a product impression to this hit. 205 | */ 206 | - (GAIDictionaryBuilder *)addProductImpression:(GAIEcommerceProduct *)product 207 | impressionList:(NSString *)name 208 | impressionSource:(NSString *)source; 209 | 210 | /*! 211 | Add a promotion to this hit. 212 | */ 213 | - (GAIDictionaryBuilder *)addPromotion:(GAIEcommercePromotion *)promotion; 214 | @end 215 | -------------------------------------------------------------------------------- /project/iPhone/include/GAIEcommerceFields.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAIEcommerceFields.h 3 | @abstract Google Analytics iOS SDK Ecommerce Hit Format Header 4 | @copyright Copyright 2014 Google Inc. All rights reserved. 5 | */ 6 | 7 | #import 8 | 9 | /*! 10 | This class provides several fields and methods useful as wire format parameters for 11 | Enhanced Ecommerce. See the online developer guides for Enhanced Ecommerce for details 12 | on how to use the Enhanced Ecommerce features. 13 | */ 14 | 15 | // Enhanced Ecommerce Product fields 16 | extern NSString *const kGAIProductId; 17 | extern NSString *const kGAIProductName; 18 | extern NSString *const kGAIProductBrand; 19 | extern NSString *const kGAIProductCategory; 20 | extern NSString *const kGAIProductVariant; 21 | extern NSString *const kGAIProductPrice; 22 | extern NSString *const kGAIProductQuantity; 23 | extern NSString *const kGAIProductCouponCode; 24 | extern NSString *const kGAIProductPosition; 25 | 26 | extern NSString *const kGAIProductAction; 27 | 28 | // product action values 29 | extern NSString *const kGAIPADetail; 30 | extern NSString *const kGAIPAClick; 31 | extern NSString *const kGAIPAAdd; 32 | extern NSString *const kGAIPARemove; 33 | extern NSString *const kGAIPACheckout; 34 | extern NSString *const kGAIPACheckoutOption; 35 | extern NSString *const kGAIPAPurchase; 36 | extern NSString *const kGAIPARefund; 37 | 38 | // product action fields 39 | // used for 'purchase' and 'refund' actions 40 | extern NSString *const kGAIPATransactionId; 41 | extern NSString *const kGAIPAAffiliation; 42 | extern NSString *const kGAIPARevenue; 43 | extern NSString *const kGAIPATax; 44 | extern NSString *const kGAIPAShipping; 45 | extern NSString *const kGAIPACouponCode; 46 | // used for 'checkout' action 47 | extern NSString *const kGAICheckoutStep; 48 | extern NSString *const kGAICheckoutOption; 49 | // used for 'detail' and 'click' actions 50 | extern NSString *const kGAIProductActionList; 51 | extern NSString *const kGAIProductListSource; 52 | 53 | // Enhanced Ecommerce Impressions fields 54 | extern NSString *const kGAIImpressionName; 55 | extern NSString *const kGAIImpressionListSource; 56 | extern NSString *const kGAIImpressionProduct; 57 | extern NSString *const kGAIImpressionProductId; 58 | extern NSString *const kGAIImpressionProductName; 59 | extern NSString *const kGAIImpressionProductBrand; 60 | extern NSString *const kGAIImpressionProductCategory; 61 | extern NSString *const kGAIImpressionProductVariant; 62 | extern NSString *const kGAIImpressionProductPosition; 63 | extern NSString *const kGAIImpressionProductPrice; 64 | 65 | // Enhanced Ecommerce Promotions fields 66 | extern NSString *const kGAIPromotionId; 67 | extern NSString *const kGAIPromotionName; 68 | extern NSString *const kGAIPromotionCreative; 69 | extern NSString *const kGAIPromotionPosition; 70 | 71 | // Promotion actions 72 | extern NSString *const kGAIPromotionAction; 73 | extern NSString *const kGAIPromotionView; 74 | extern NSString *const kGAIPromotionClick; 75 | 76 | @interface GAIEcommerceFields : NSObject 77 | 78 | /*! 79 | Generates an enhanced ecommerce product field. Note that field names generated by 80 | customDimensionForIndex and customMetricForIndex can be used as suffixes. 81 | 82 | @param index the index of the product 83 | @param suffix the product field suffix (such as kGAIProductPrice). 84 | 85 | @return an NSString representing the product field parameter 86 | */ 87 | + (NSString *)productFieldForIndex:(NSUInteger)index suffix:(NSString *)suffix; 88 | 89 | /*! 90 | Genrates an enhanced ecommerce impression list field name with an index. The return value of 91 | this method should also be used as input to the productImpressionForList method below. 92 | 93 | @param index the index of the impression list 94 | 95 | @return an NSString representing the impression list parameter 96 | */ 97 | + (NSString *)impressionListForIndex:(NSUInteger)index; 98 | 99 | /*! 100 | Generates an enhanced ecommerce product impression field with the impression list, product index 101 | and product suffix as parameters. The output of the method impressionListForIndex above should be 102 | used as the input list for this method. The output of customDimensionForIndex and 103 | customMetricForIndex can be used as suffixes. 104 | 105 | @param list the impression list for this product impression 106 | @param index the index of this product in the impression list 107 | @param suffix the product impression suffix for this field 108 | 109 | @return an NSString representing this product impression field parameter 110 | */ 111 | + (NSString *)productImpressionForList:(NSString *)list 112 | index:(NSUInteger)index 113 | suffix:(NSString *)Suffix; 114 | 115 | /*! 116 | Generates an enhanced ecommerce promotion field with an index and suffix. 117 | 118 | @param index the index of the promotion 119 | @param suffix the promotion suffix (such as kGAIPromotionId) 120 | 121 | @return an NSString representing this promotion field paramter 122 | */ 123 | + (NSString *)promotionForIndex:(NSUInteger)index suffix:(NSString *)suffix; 124 | @end 125 | -------------------------------------------------------------------------------- /project/iPhone/include/GAIEcommerceProduct.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAIEcommerceProduct.h 3 | @abstract Google Analytics iOS SDK Hit Format Header 4 | @copyright Copyright 2014 Google Inc. All rights reserved. 5 | */ 6 | 7 | #import 8 | 9 | /*! 10 | * Class to construct product related information for a Google Analytics beacon. Use this class to 11 | * report information about products sold by merchants or impressions of products seen by users. 12 | * Instances of this class can be associated with both Product Actions and Product 13 | * Impression Lists. 14 | *
15 | * Typical usage: 16 | * 17 | * [tracker set:kGAIScreenName value:@"MyScreen"]; 18 | * GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createScreenView]; 19 | * GAIEcommerceProduct *product = [[GAIEcommerceProduct alloc] init]; 20 | * [product setId:@""PID-1234""]; 21 | * [product setName:@"Space Monkeys!"]; 22 | * [product setPrice:@100]; 23 | * [product setQuantity:@2]; 24 | * [builder addProductImpression:product impressionList:@"listName"]; 25 | * [tracker send:[builder build]]; 26 | * 27 | */ 28 | @interface GAIEcommerceProduct : NSObject 29 | 30 | /*! 31 | Sets the id that is used to identify a product in GA reports. 32 | */ 33 | - (GAIEcommerceProduct *)setId:(NSString *)productId; 34 | 35 | /*! 36 | Sets the name that is used to indentify the product in GA reports. 37 | */ 38 | - (GAIEcommerceProduct *)setName:(NSString *)productName; 39 | 40 | /*! 41 | Sets the brand associated with the product in GA reports. 42 | */ 43 | - (GAIEcommerceProduct *)setBrand:(NSString *)productBrand; 44 | 45 | /*! 46 | Sets the category associated with the product in GA reports. 47 | */ 48 | - (GAIEcommerceProduct *)setCategory:(NSString *)productCategory; 49 | 50 | /*! 51 | Sets the variant of the product. 52 | */ 53 | - (GAIEcommerceProduct *)setVariant:(NSString *)productVariant; 54 | 55 | /*! 56 | Sets the price of the product. 57 | */ 58 | - (GAIEcommerceProduct *)setPrice:(NSNumber *)productPrice; 59 | 60 | /*! 61 | Sets the quantity of the product. This field is usually not used with product impressions. 62 | */ 63 | - (GAIEcommerceProduct *)setQuantity:(NSNumber *)productQuantity; 64 | 65 | /*! 66 | Sets the coupon code associated with the product. This field is usually not used with product 67 | impressions. 68 | */ 69 | - (GAIEcommerceProduct *)setCouponCode:(NSString *)productCouponCode; 70 | 71 | /*! 72 | Sets the position of the product on the screen/product impression list, etc. 73 | */ 74 | - (GAIEcommerceProduct *)setPosition:(NSNumber *)productPosition; 75 | 76 | /*! 77 | Sets the custom dimension associated with this product. 78 | */ 79 | - (GAIEcommerceProduct *)setCustomDimension:(NSUInteger)index value:(NSString *)value; 80 | 81 | /*! 82 | Sets the custom metric associated with this product. 83 | */ 84 | - (GAIEcommerceProduct *)setCustomMetric:(NSUInteger)index value:(NSNumber *)value; 85 | 86 | /*! 87 | Builds an NSDictionary of fields stored in this instance suitable for a product action. The 88 | index parameter is the index of this product in the product action list. 89 |
90 | Normally, users will have no need to call this method. 91 | */ 92 | - (NSDictionary *)buildWithIndex:(NSUInteger)index; 93 | 94 | /*! 95 | Builds an NSDictionary of fields stored in this instance suitable for an impression list. The 96 | lIndex parameter is the index of the product impression list while the index parameter is the 97 | index of this product in that impression list. 98 |
99 | Normally, users will have no need to call this method. 100 | */ 101 | - (NSDictionary *)buildWithListIndex:(NSUInteger)lIndex index:(NSUInteger)index; 102 | @end 103 | -------------------------------------------------------------------------------- /project/iPhone/include/GAIEcommerceProductAction.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAIProductAction.h 3 | @abstract Google Analytics iOS SDK Hit Format Header 4 | @copyright Copyright 2014 Google Inc. All rights reserved. 5 | */ 6 | 7 | #import 8 | 9 | /*! 10 | * Class to construct transaction/checkout or other product interaction related information for a 11 | * Google Analytics hit. Use this class to report information about products sold, viewed or 12 | * refunded. This class is intended to be used with GAIDictionaryBuilder. 13 | *
14 | * Typical usage: 15 | * 16 | * [tracker set:kGAIScreenName value:@"MyScreen"]; 17 | * GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createScreenView]; 18 | * GAIEcommerceProductAction *action = [[GAIEcommerceProductAction alloc] init]; 19 | * [action setAction:kGAIPAPurchase]; 20 | * [action setTransactionId:@"TT-1234"]; 21 | * [action setRevenue:@3.14]; 22 | * [action setCouponCode:@"EXTRA100"]; 23 | * [builder setProductAction:action]; 24 | * GAIEcommerceProduct *product = [[GAIEcommerceProduct alloc] init]; 25 | * [product setId:@""PID-1234""]; 26 | * [product setName:@"Space Monkeys!"]; 27 | * [product setPrice:@100]; 28 | * [product setQuantity:@2]; 29 | * [builder addProduct:product]; 30 | * [tracker send:[builder build]]; 31 | * 32 | */ 33 | @interface GAIEcommerceProductAction : NSObject 34 | 35 | /*! 36 | Sets the product action field for this product action. Valid values can be found in 37 | GAIEcommerceFields.h under "product action values". 38 | */ 39 | - (GAIEcommerceProductAction *)setAction:(NSString *)productAction; 40 | 41 | /*! 42 | The unique id associated with the transaction. This value is used for kGAIPAPurchase and 43 | kGAIPARefund product actions. 44 | */ 45 | - (GAIEcommerceProductAction *)setTransactionId:(NSString *)transactionId; 46 | 47 | /*! 48 | Sets the transaction's affiliation value. This value is used for kGAIPAPurchase and 49 | kGAIPARefund product actions. 50 | */ 51 | - (GAIEcommerceProductAction *)setAffiliation:(NSString *)affiliation; 52 | 53 | /*! 54 | Sets the transaction's total revenue. This value is used for kGAIPAPurchase and kGAIPARefund 55 | product actions. 56 | */ 57 | - (GAIEcommerceProductAction *)setRevenue:(NSNumber *)revenue; 58 | 59 | /*! 60 | Sets the transaction's total tax. This value is used for kGAIPAPurchase and kGAIPARefund 61 | product actions. 62 | */ 63 | - (GAIEcommerceProductAction *)setTax:(NSNumber *)tax; 64 | 65 | /*! 66 | Sets the transaction's total shipping costs. This value is used for kGAIPAPurchase and 67 | kGAIPARefund product actions. 68 | */ 69 | - (GAIEcommerceProductAction *)setShipping:(NSNumber *)shipping; 70 | 71 | /*! 72 | Sets the coupon code used in this transaction. This value is used for kGAIPAPurchase and 73 | kGAIPARefund product actions. 74 | */ 75 | - (GAIEcommerceProductAction *)setCouponCode:(NSString *)couponCode; 76 | 77 | /*! 78 | Sets the checkout process's progress. This value is used for kGAICheckout and 79 | kGAICheckoutOptions product actions. 80 | */ 81 | - (GAIEcommerceProductAction *)setCheckoutStep:(NSNumber *)checkoutStep; 82 | 83 | /*! 84 | Sets the option associated with the checkout. This value is used for kGAICheckout and 85 | kGAICheckoutOptions product actions. 86 | */ 87 | - (GAIEcommerceProductAction *)setCheckoutOption:(NSString *)checkoutOption; 88 | 89 | /*! 90 | Sets the list name associated with the products in Google Analytics beacons. This value is 91 | used in kGAIPADetail and kGAIPAClick product actions. 92 | */ 93 | - (GAIEcommerceProductAction *)setProductActionList:(NSString *)productActionList; 94 | 95 | /*! 96 | Sets the list source name associated with the products in Google Analytics beacons. This value 97 | is used in kGAIPADetail and kGAIPAClick product actions. 98 | */ 99 | - (GAIEcommerceProductAction *)setProductListSource:(NSString *)productListSource; 100 | 101 | /*! 102 | Builds an NSDictionary of fields stored in this instance representing this product action. 103 |
104 | Normally, users will have no need to call this method. 105 | */ 106 | - (NSDictionary *)build; 107 | @end 108 | -------------------------------------------------------------------------------- /project/iPhone/include/GAIEcommercePromotion.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAIEcommercePromotion.h 3 | @abstract Google Analytics iOS SDK Hit Format Header 4 | @copyright Copyright 2014 Google Inc. All rights reserved. 5 | */ 6 | 7 | #import 8 | 9 | /*! 10 | * Class to construct promotion related fields for Google Analytics hits. The fields from this class 11 | * can be used to represent internal promotions that run within an app, such as banners, banner ads 12 | * etc. 13 | * 14 | * Typical usage: 15 | * 16 | * GAIDictionaryBuilder *builder = [GAIDictionaryBuilder createScreenView]; 17 | * GAIEcommercePromotion *promotion = [[GAIEcommercePromotion alloc] init]; 18 | * [promotion setId:@"PROMO-ID1234"]; 19 | * [promotion setName:@"Home screen banner"]; 20 | * [builder set:kGAIPromotionClick forKey:kGAIPromotionAction]; 21 | * [builder addPromotion:promotion]; 22 | * [tracker send:builder.build]]; 23 | * 24 | */ 25 | @interface GAIEcommercePromotion : NSObject 26 | 27 | /*! 28 | Sets the id that is used to identify a promotion in GA reports. 29 | */ 30 | - (GAIEcommercePromotion *)setId:(NSString *)pid; 31 | 32 | /*! 33 | Sets the name that is used to identify a promotion in GA reports. 34 | */ 35 | - (GAIEcommercePromotion *)setName:(NSString *)name; 36 | 37 | /*! 38 | Sets the name of the creative associated with the promotion. 39 | */ 40 | - (GAIEcommercePromotion *)setCreative:(NSString *)creative; 41 | 42 | /*! 43 | Sets the position of the promotion. 44 | */ 45 | - (GAIEcommercePromotion *)setPosition:(NSString *)position; 46 | 47 | /*! 48 | Builds an NSDictionary of fields stored in this instance. The index parameter is the 49 | index of this promotion in that promotion list. 50 |
51 | Normally, users will have no need to call this method. 52 | */ 53 | - (NSDictionary *)buildWithIndex:(NSUInteger)index; 54 | @end 55 | -------------------------------------------------------------------------------- /project/iPhone/include/GAIFields.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAIFields.h 3 | @abstract Google Analytics iOS SDK Hit Format Header 4 | @copyright Copyright 2013 Google Inc. All rights reserved. 5 | */ 6 | 7 | #import 8 | 9 | /*! 10 | These fields can be used for the wire format parameter names required by 11 | the |GAITracker| get, set and send methods as well as the set methods in the 12 | |GAIDictionaryBuilder| class. 13 | */ 14 | extern NSString *const kGAIUseSecure; 15 | 16 | extern NSString *const kGAIHitType; 17 | extern NSString *const kGAITrackingId; 18 | extern NSString *const kGAIClientId; 19 | extern NSString *const kGAIDataSource; 20 | extern NSString *const kGAIAnonymizeIp; 21 | extern NSString *const kGAISessionControl; 22 | extern NSString *const kGAIDeviceModelVersion; 23 | extern NSString *const kGAIScreenResolution; 24 | extern NSString *const kGAIViewportSize; 25 | extern NSString *const kGAIEncoding; 26 | extern NSString *const kGAIScreenColors; 27 | extern NSString *const kGAILanguage; 28 | extern NSString *const kGAIJavaEnabled; 29 | extern NSString *const kGAIFlashVersion; 30 | extern NSString *const kGAINonInteraction; 31 | extern NSString *const kGAIReferrer; 32 | extern NSString *const kGAILocation; 33 | extern NSString *const kGAIHostname; 34 | extern NSString *const kGAIPage; 35 | extern NSString *const kGAIDescription; // synonym for kGAIScreenName 36 | extern NSString *const kGAIScreenName; // synonym for kGAIDescription 37 | extern NSString *const kGAITitle; 38 | extern NSString *const kGAIAdMobHitId; 39 | extern NSString *const kGAIAppName; 40 | extern NSString *const kGAIAppVersion; 41 | extern NSString *const kGAIAppId; 42 | extern NSString *const kGAIAppInstallerId; 43 | extern NSString *const kGAIUserId; 44 | 45 | extern NSString *const kGAIEventCategory; 46 | extern NSString *const kGAIEventAction; 47 | extern NSString *const kGAIEventLabel; 48 | extern NSString *const kGAIEventValue; 49 | 50 | extern NSString *const kGAISocialNetwork; 51 | extern NSString *const kGAISocialAction; 52 | extern NSString *const kGAISocialTarget; 53 | 54 | extern NSString *const kGAITransactionId; 55 | extern NSString *const kGAITransactionAffiliation; 56 | extern NSString *const kGAITransactionRevenue; 57 | extern NSString *const kGAITransactionShipping; 58 | extern NSString *const kGAITransactionTax; 59 | extern NSString *const kGAICurrencyCode; 60 | 61 | extern NSString *const kGAIItemPrice; 62 | extern NSString *const kGAIItemQuantity; 63 | extern NSString *const kGAIItemSku; 64 | extern NSString *const kGAIItemName; 65 | extern NSString *const kGAIItemCategory; 66 | 67 | extern NSString *const kGAICampaignSource; 68 | extern NSString *const kGAICampaignMedium; 69 | extern NSString *const kGAICampaignName; 70 | extern NSString *const kGAICampaignKeyword; 71 | extern NSString *const kGAICampaignContent; 72 | extern NSString *const kGAICampaignId; 73 | extern NSString *const kGAICampaignAdNetworkClickId; 74 | extern NSString *const kGAICampaignAdNetworkId; 75 | 76 | extern NSString *const kGAITimingCategory; 77 | extern NSString *const kGAITimingVar; 78 | extern NSString *const kGAITimingValue; 79 | extern NSString *const kGAITimingLabel; 80 | 81 | extern NSString *const kGAIExDescription; 82 | extern NSString *const kGAIExFatal; 83 | 84 | extern NSString *const kGAISampleRate; 85 | 86 | extern NSString *const kGAIIdfa; 87 | extern NSString *const kGAIAdTargetingEnabled; 88 | 89 | // hit types 90 | extern NSString *const kGAIAppView DEPRECATED_MSG_ATTRIBUTE("Use kGAIScreenView instead."); 91 | extern NSString *const kGAIScreenView; 92 | extern NSString *const kGAIEvent; 93 | extern NSString *const kGAISocial; 94 | extern NSString *const kGAITransaction; 95 | extern NSString *const kGAIItem; 96 | extern NSString *const kGAIException; 97 | extern NSString *const kGAITiming; 98 | 99 | /*! 100 | This class provides several fields and methods useful as wire format parameter 101 | names. The methods are used for wire format parameter names that are indexed. 102 | */ 103 | 104 | @interface GAIFields : NSObject 105 | 106 | /*! 107 | Generates the correct parameter name for a content group with an index. 108 | 109 | @param index the index of the content group. 110 | 111 | @return an NSString representing the content group parameter for the index. 112 | */ 113 | + (NSString *)contentGroupForIndex:(NSUInteger)index; 114 | 115 | /*! 116 | Generates the correct parameter name for a custon dimension with an index. 117 | 118 | @param index the index of the custom dimension. 119 | 120 | @return an NSString representing the custom dimension parameter for the index. 121 | */ 122 | + (NSString *)customDimensionForIndex:(NSUInteger)index; 123 | 124 | /*! 125 | Generates the correct parameter name for a custom metric with an index. 126 | 127 | @param index the index of the custom metric. 128 | 129 | @return an NSString representing the custom metric parameter for the index. 130 | */ 131 | + (NSString *)customMetricForIndex:(NSUInteger)index; 132 | 133 | @end 134 | -------------------------------------------------------------------------------- /project/iPhone/include/GAILogger.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAILogger.h 3 | @abstract Google Analytics iOS SDK Source 4 | @copyright Copyright 2011 Google Inc. All rights reserved. 5 | */ 6 | 7 | #import 8 | 9 | typedef NS_ENUM(NSUInteger, GAILogLevel) { 10 | kGAILogLevelNone = 0, 11 | kGAILogLevelError = 1, 12 | kGAILogLevelWarning = 2, 13 | kGAILogLevelInfo = 3, 14 | kGAILogLevelVerbose = 4 15 | }; 16 | 17 | /*! 18 | Protocol to be used for logging debug and informational messages from the SDK. 19 | Implementations of this protocol can be provided to the |GAI| class, 20 | to be used as the logger by the SDK. See the |logger| property in GAI.h. 21 | */ 22 | @protocol GAILogger 23 | @required 24 | 25 | /*! 26 | Only messages of |logLevel| and below are logged. 27 | */ 28 | @property (nonatomic, assign) GAILogLevel logLevel; 29 | 30 | /*! 31 | Logs message with log level |kGAILogLevelVerbose|. 32 | */ 33 | - (void)verbose:(NSString *)message; 34 | 35 | /*! 36 | Logs message with log level |kGAILogLevelInfo|. 37 | */ 38 | - (void)info:(NSString *)message; 39 | 40 | /*! 41 | Logs message with log level |kGAILogLevelWarning|. 42 | */ 43 | - (void)warning:(NSString *)message; 44 | 45 | /*! 46 | Logs message with log level |kGAILogLevelError|. 47 | */ 48 | - (void)error:(NSString *)message; 49 | @end 50 | -------------------------------------------------------------------------------- /project/iPhone/include/GAITrackedViewController.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAITrackedViewController.h 3 | @abstract Google Analytics for iOS Tracked View Controller Header 4 | @copyright Copyright 2012 Google Inc. All rights reserved. 5 | */ 6 | 7 | #import 8 | #import 9 | 10 | @protocol GAITracker; 11 | 12 | /*! 13 | Extends UIViewController to generate Google Analytics screenview calls 14 | whenever the view appears; this is done by overriding the `viewDidAppear:` 15 | method. The screen name must be set for any tracking calls to be made. 16 | 17 | By default, this will use [GAI defaultTracker] for tracking calls, but one can 18 | override this by setting the tracker property. 19 | */ 20 | @interface GAITrackedViewController : UIViewController 21 | 22 | /*! 23 | The tracker on which view tracking calls are be made, or `nil`, in which case 24 | [GAI defaultTracker] will be used. 25 | */ 26 | @property(nonatomic, assign) id tracker; 27 | /*! 28 | The screen name, for purposes of Google Analytics tracking. If this is `nil`, 29 | no tracking calls will be made. 30 | */ 31 | @property(nonatomic, copy) NSString *screenName; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /project/iPhone/include/GAITracker.h: -------------------------------------------------------------------------------- 1 | /*! 2 | @header GAITracker.h 3 | @abstract Google Analytics iOS SDK Tracker Header 4 | @copyright Copyright 2013 Google Inc. All rights reserved. 5 | */ 6 | 7 | #import 8 | 9 | /*! 10 | Google Analytics tracking interface. Obtain instances of this interface from 11 | [GAI trackerWithTrackingId:] to track screens, events, transactions, timing, 12 | and exceptions. The implementation of this interface is thread-safe, and no 13 | calls are expected to block or take a long time. All network and disk activity 14 | will take place in the background. 15 | */ 16 | @protocol GAITracker 17 | 18 | /*! 19 | Name of this tracker. 20 | */ 21 | @property(nonatomic, readonly) NSString *name; 22 | 23 | /*! 24 | Allow collection of IDFA and related fields if set to true. Default is false. 25 | */ 26 | @property(nonatomic) BOOL allowIDFACollection; 27 | 28 | /*! 29 | Set a tracking parameter. 30 | 31 | @param parameterName The parameter name. 32 | 33 | @param value The value to set for the parameter. If this is nil, the 34 | value for the parameter will be cleared. 35 | */ 36 | - (void)set:(NSString *)parameterName 37 | value:(NSString *)value; 38 | 39 | /*! 40 | Get a tracking parameter. 41 | 42 | @param parameterName The parameter name. 43 | 44 | @returns The parameter value, or nil if no value for the given parameter is 45 | set. 46 | */ 47 | - (NSString *)get:(NSString *)parameterName; 48 | 49 | /*! 50 | Queue tracking information with the given parameter values. 51 | 52 | @param parameters A map from parameter names to parameter values which will be 53 | set just for this piece of tracking information, or nil for none. 54 | */ 55 | - (void)send:(NSDictionary *)parameters; 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /project/include/Utils.h: -------------------------------------------------------------------------------- 1 | #ifndef GA_H 2 | #define GA_H 3 | 4 | 5 | namespace ganalytics { 6 | 7 | 8 | void startNewSession( const char *sUID , int iPeriod ); 9 | void sendScreenView( const char *sScreen ); 10 | void setUserId( const char *sUserId ); 11 | void sendEvent( const char *sCat , const char *sAction,const char *sLabel , int iValue ); 12 | void sendSocial( const char *sSocial_network , const char *sAction , const char *sTarget ); 13 | void setCustom_dimension( int iIndex , const char *sValue ); 14 | void setCustom_metric( int iIndex , int iMetric ); 15 | void sendTiming( const char *sCat , int iInterval , const char *sName , const char *sLabel ); 16 | void stopSession( ); 17 | void sendUncaughtException( const char *description, bool fatal ); 18 | 19 | } 20 | 21 | 22 | #endif --------------------------------------------------------------------------------