Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update iOS libraries to V3 and Make GA Lib Installation Easier #1

Open
wants to merge 3 commits into
base: haxe3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ HypGA
A Google Analytics native extension for NME
-----------------------------

This NME native extension allows you to integrate Google Analytics ( v2 Beta 4 ) into your NME application.
The supported compilation targets are [iOS](https://developers.google.com/analytics/devguides/collection/ios/v2/) & [Android](https://developers.google.com/analytics/devguides/collection/android/v2/)
This OpenFL native extension allows you to integrate Google Analytics into your OpenFL application.
The supported compilation targets are
* [iOS](https://developers.google.com/analytics/devguides/collection/ios/v3/)
* [Android](https://developers.google.com/analytics/devguides/collection/android/v2/)

Installation
------------
Expand All @@ -22,10 +24,11 @@ Usage
-----
Just call the public methods on the HypGA class.

For iOS you need to link the Google Analytics class package to your XCode project.
Just drag & drop on your project the HypGA folder. ( [your_export_folder]/ios/[ProjectName]/HypGA )
For iOS, put the following libs (from GA v3 SDK) into projects/iPhone/libs:
* libAdIdAccess.a
* libGoogleAnalyticsServices.a

Baisc reference
Basic reference
---------------

First start the session via :
Expand Down
13 changes: 8 additions & 5 deletions include.nmml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@

<!-- iOS -->
<ndll name="HypGA" if="ios"/>
<dependency name="CFNetwork.framework" if="ios" />
<dependency name="CoreData.framework" if="ios" />
<dependency name="SystemConfiguration.framework" if="ios" />
<dependency name="sqlite3" if="ios"/>
<dependency name="CFNetwork.framework" if="ios" />
<dependency name="CoreData.framework" if="ios" />
<dependency name="SystemConfiguration.framework" if="ios" />
<dependency name="sqlite3" if="ios"/>
<dependency name="AdSupport.framework" if="ios"/>
<dependency name="project/iPhone/libs/libAdIdAccess.a" if="ios"/>
<dependency name="project/iPhone/libs/libGoogleAnalyticsServices.a" if="ios"/>

<!-- HaxeLib -->
<haxelib name="inthebox-macros" />
Expand All @@ -24,4 +27,4 @@

</section>

</extension>
</extension>
Binary file modified ndll/iPhone/libHypGA.iphoneos-v7.a
100755 → 100644
Binary file not shown.
Binary file modified ndll/iPhone/libHypGA.iphoneos.a
100755 → 100644
Binary file not shown.
Binary file modified ndll/iPhone/libHypGA.iphonesim.a
100755 → 100644
Binary file not shown.
Binary file removed project/.DS_Store
Binary file not shown.
26 changes: 20 additions & 6 deletions project/iPhone/HypGA.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#import <UIKit/UIKit.h>
#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIFields.h"
#import "GAITracker.h"

namespace hypga {
Expand All @@ -18,40 +20,52 @@ void startNewSession( const char *sUID , int iPeriod ){
void sendView( const char *sPage ){
NSString *NSPage = [[NSString alloc] initWithUTF8String:sPage];
NSLog( @"sendView %@" , NSPage );
[tracker sendView:NSPage];
[tracker set:kGAIScreenName value:NSPage];
[tracker send:[[GAIDictionaryBuilder createAppView] build]];
}

void sendEvent( const char *sCat , const char *sAction , const char *sLabel , int iValue ){
NSString *NS_Cat = [ [NSString alloc] initWithUTF8String:sCat];
NSString *NS_Act = [ [NSString alloc] initWithUTF8String:sAction];
NSString *NS_Lab = [ [NSString alloc] initWithUTF8String:sLabel];
NSLog( @"SendEvent cat:%@ act:%@ label:%@ val%i" , NS_Cat , NS_Act , NS_Lab , iValue );
[tracker sendEventWithCategory:NS_Cat withAction:NS_Act withLabel:NS_Lab withValue:[NSNumber numberWithInt:iValue]];
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:NS_Cat
action:NS_Act
label:NS_Lab
value:[NSNumber numberWithInt:iValue]]
build]];
}

void setCustom_dimension( int iIndex , const char *sValue ){
NSString *NS_Val = [[NSString alloc] initWithUTF8String:sValue];
NSLog( @"setCustom_dimension index:%i value:%s" , iIndex , sValue );
[tracker setCustom:iIndex dimension:NS_Val];
[tracker set:[GAIFields customDimensionForIndex:iIndex] value:NS_Val];
}

void setCustom_metric( int iIndex , int iMetric ){
NSLog( @"setCustom_metric index:%i metrid:%i",iIndex,iMetric);
[tracker setCustom:iIndex metric:[NSNumber numberWithInt:iMetric]];
[tracker set:[GAIFields customMetricForIndex:iIndex] value:[NSString stringWithFormat:@"%d", iMetric]];
}

void sendTiming( const char *sCat , int iInterval , const char *sName , const char *sLabel ){
NSString *NS_Cat = [ [NSString alloc] initWithUTF8String:sCat];
NSString *NS_Name = [ [NSString alloc] initWithUTF8String:sName];
NSString *NS_Label = [ [NSString alloc] initWithUTF8String:sLabel];
[tracker sendTimingWithCategory:NS_Cat withValue:iInterval withName:NS_Name withLabel:NS_Label];
[tracker send:[[GAIDictionaryBuilder createTimingWithCategory:NS_Cat
interval:[NSNumber numberWithInt:iInterval]
name:NS_Name
label:NS_Label]
build]];
}

void sendSocial( const char *sSocial_network , const char *sAction , const char *sTarget ){
NSString *NS_Net = [ [NSString alloc] initWithUTF8String:sSocial_network];
NSString *NS_Act = [ [NSString alloc] initWithUTF8String:sAction];
NSString *NS_Tgt = [ [NSString alloc] initWithUTF8String:sTarget];
[tracker sendSocial:NS_Net withAction:NS_Act withTarget:NS_Tgt];
[tracker send:[[GAIDictionaryBuilder createSocialWithNetwork:NS_Net
action:NS_Act
target:NS_Tgt]
build]];
}

void stopSession( ){
Expand Down
89 changes: 62 additions & 27 deletions project/iPhone/include/GAI.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*!
@header GAI.h
@abstract Google Analytics iOS SDK Header
@version 2.0
@copyright Copyright 2011 Google Inc. All rights reserved.
@version 3.0
@copyright Copyright 2013 Google Inc. All rights reserved.
*/

#import <Foundation/Foundation.h>
#import "GAILogger.h"
#import "GAITracker.h"
#import "GAITrackedViewController.h"

Expand Down Expand Up @@ -49,11 +50,9 @@ typedef enum {
@property(nonatomic, assign) id<GAITracker> defaultTracker;

/*!
If true, Google Analytics debug messages will be logged with `NSLog()`. This is
useful for debugging calls to the Google Analytics SDK.

By default, this flag is set to `NO`. */
@property(nonatomic, assign) BOOL debug;
The GAILogger to use.
*/
@property(nonatomic, retain) id<GAILogger> logger;

/*!
When this is true, no tracking information will be gathered; tracking calls
Expand All @@ -69,14 +68,9 @@ typedef enum {
@property(nonatomic, assign) BOOL optOut;

/*!
If this value is negative, tracking information must be sent manually by
calling dispatch. If this value is zero, tracking information will
automatically be sent as soon as possible (usually immediately if the device
has Internet connectivity). If this value is positive, tracking information
will be automatically dispatched every dispatchInterval seconds.

When the dispatchInterval is non-zero, setting it to zero will cause any queued
tracking information to be sent immediately.
If this value is positive, tracking information will be automatically
dispatched every dispatchInterval seconds. Otherwise, tracking information must
be sent manually by calling dispatch.

By default, this is set to `120`, which indicates tracking information should
be dispatched automatically every 120 seconds.
Expand All @@ -94,31 +88,72 @@ typedef enum {
*/
@property(nonatomic, assign) BOOL trackUncaughtExceptions;

/*!
When this is 'YES', no tracking information will be sent. Defaults to 'NO'.
*/
@property(nonatomic, assign) BOOL dryRun;

/*! Get the shared instance of the Google Analytics for iOS class. */
+ (GAI *)sharedInstance;

/*!
Create or retrieve a GAITracker implementation with the specified tracking
ID. If the tracker for the specified tracking ID does not already exist, then
Creates or retrieves a GAITracker implementation with the specified name and
tracking ID. If the tracker for the specified name does not already exist, then
it will be created and returned; otherwise, the existing tracker will be
returned. If defaultTracker is not set, it will be set to the tracker instance
returned here.
returned. If the existing tracker for the respective name has a different
tracking ID, that tracking ID is not changed by this method. If defaultTracker
is not set, it will be set to the tracker instance returned here.

@param name The name of this tracker. Must not be `nil` or empty.

@param trackingId The tracking ID (a string that begins with "UA-"). Must not
be `nil` or empty.
@param trackingID The tracking ID to use for this tracker. It should be of
the form `UA-xxxxx-y`.

@return A GAITracker associated with the specified tracking ID. The tracker
@return A GAITracker associated with the specified name. The tracker
can be used to send tracking data to Google Analytics. The first time this
method is called with a particular tracking ID, the tracker for that tracking
ID will be returned, and subsequent calls with the same tracking ID will return
the same instance. It is not necessary to retain the tracker because the
tracker will be retained internally by the library.
method is called with a particular name, the tracker for that name will be
returned, and subsequent calls with the same name will return the same
instance. It is not necessary to retain the tracker because the tracker will be
retained internally by the library.

If an error occurs or the tracker ID is not valid, this method will return
If an error occurs or the name is not valid, this method will return
`nil`.
*/
- (id<GAITracker>)trackerWithName:(NSString *)name
trackingId:(NSString *)trackingId;

/*!
Creates or retrieves a GAITracker implementation with name equal to
the specified tracking ID. If the tracker for the respective name does not
already exist, it is created, has it's tracking ID set to |trackingId|,
and is returned; otherwise, the existing tracker is returned. If the existing
tracker for the respective name has a different tracking ID, that tracking ID
is not changed by this method. If defaultTracker is not set, it is set to the
tracker instance returned here.

@param trackingID The tracking ID to use for this tracker. It should be of
the form `UA-xxxxx-y`. The name of the tracker will be the same as trackingID.

@return A GAITracker associated with the specified trackingID. The tracker
can be used to send tracking data to Google Analytics. The first time this
method is called with a particular trackingID, the tracker for the respective
name will be returned, and subsequent calls with the same trackingID
will return the same instance. It is not necessary to retain the tracker
because the tracker will be retained internally by the library.

If an error occurs or the trackingId is not valid, this method will return
`nil`.
*/
- (id<GAITracker>)trackerWithTrackingId:(NSString *)trackingId;

/*!
Remove a tracker from the trackers dictionary. If it is the default tracker,
clears the default tracker as well.

@param name The name of the tracker.
*/
- (void)removeTrackerByName:(NSString *)name;

/*!
Dispatches any pending tracking information.

Expand Down
Loading