Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #19 from HsoiEnterprises/develop
Browse files Browse the repository at this point in the history
versioning
  • Loading branch information
hsoi committed May 26, 2015
2 parents c21941e + 0d612d6 commit 1e5cea5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Example/HEAnalyticsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = HEAnalyticsExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "HEAnalyticsExample/HEAnalyticsExample-Bridging-Header.h";
Expand All @@ -479,6 +480,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = HEAnalyticsExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "HEAnalyticsExample/HEAnalyticsExample-Bridging-Header.h";
Expand All @@ -498,6 +500,7 @@
"$(inherited)",
);
INFOPLIST_FILE = HEAnalyticsExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HEAnalyticsExample.app/HEAnalyticsExample";
Expand All @@ -513,6 +516,7 @@
"$(inherited)",
);
INFOPLIST_FILE = HEAnalyticsExampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HEAnalyticsExample.app/HEAnalyticsExample";
Expand Down
6 changes: 3 additions & 3 deletions Example/HEAnalyticsExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.hsoienterprises.heanalyticssample.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>com.hsoienterprises.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
16 changes: 16 additions & 0 deletions HEAnalytics/HEAnalyticsPlatform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ public class HEAnalyticsPlatform: NSObject {
// No need to call `super`.
}


/**
Internal function for obtaining the app version.

I like using the `CFBundleShortVersionString` as either a semantic or marketing version, such as "x.y.z". The `CFBundleVersion` then is used as a simple forever-incrementing integer build number. We will concatenate the two versions for a more descriptive version that if an analytics SDK supports it, we can use to set it to have a more robust version reporting.

:returns: an app version string.
*/
internal func appVersion() -> String {
let infoDict = NSBundle.mainBundle().infoDictionary!
let shortVersion = infoDict["CFBundleShortVersionString"] as! String
let bundleVersion = infoDict["CFBundleVersion"] as! String
let fullVersion = shortVersion + "." + bundleVersion
return fullVersion
}


/**
A helper for obtaining the UIViewController "title" for use in trackView().
Expand Down
14 changes: 0 additions & 14 deletions HEAnalytics/HEAnalyticsPlatformFlurry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,6 @@ class HEAnalyticsPlatformFlurry: HEAnalyticsPlatform {
}


internal func appVersion() -> String {
// Hsoi 2015-04-04 - Flurry uses the CFBUndleVersion to report versions. I tend to like using the
// CFBundleShortVersionString for marketing version (e.g. "major.minor.bugfix") and the CFBundleVersion
// for a simple incrementing build integer/number. So we'll make our own version number here to
// force into Flurry so I can know exactly what I'm working with.
//
// If you'd like a different approach, subclass and override.
let infoDict = NSBundle.mainBundle().infoDictionary!
let shortVersion = infoDict["CFBundleShortVersionString"] as! String
let bundleVersion = infoDict["CFBundleVersion"] as! String
let flurryVersion = shortVersion + "." + bundleVersion
return flurryVersion
}


override var optOut: Bool {
didSet {
Expand Down
4 changes: 3 additions & 1 deletion HEAnalytics/HEAnalyticsPlatformGAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ class HEAnalyticsPlatformGAI: HEAnalyticsPlatform {
GAI.sharedInstance().defaultTracker.allowIDFACollection = allowIDFACollection
}

// Hsoi 2015-05-23 - https://groups.google.com/forum/#!topic/ga-mobile-app-analytics/U4nqqBnBhjU
GAI.sharedInstance().defaultTracker.set(kGAIAppVersion, value: self.appVersion())

super.initializePlatform(platformData)
}


override var optOut: Bool {
didSet {
GAI.sharedInstance().optOut = self.optOut
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ It enables logic for converting the data-to-track into something the analytics A

Developed with

- Xcode 6.4 beta 2 (should work with Xcode 6.3.1)
- Xcode 6.3.2
- Swift 1.2
- iOS 8

Expand Down Expand Up @@ -135,6 +135,12 @@ Event tracking is performed by filling out an `HEAnalyticsData` object and passi

View tracking can be performed by invoking `HEAnalytics.trackView()`, passing the `UIViewController` you wish to track. Invoking `trackView()` can technically be done anywhere, but makes most sense to be called in your `UIViewController` subclass override of `viewDidAppear()`. To facilitate view tracking, `HEAnalytics` extends `UIViewController` with the `HE_analyticsViewTrackingTitle()` function. This function is intended to provide a stable value for analytics view tracking. By default it returns the `viewController.title` if it is non-nil and non-empty, else returns the name of the `UIViewController` (sub)class. This default behavior is acceptable, but may not always be desired. For example, if your ViewController's title is based upon the contents of the ViewController, that may make it difficult for you to track the view. To counter this, your `UIViewController` subclass can override and implement `HE_analyticsViewTrackingTitle()` and return a known stable title string that is useful for tracking and doesn't interfere with your UI.

## App Version

If the analytics platform supports setting the app's version, HEAnalytics will do so. The version will be synthesized from the `CFBundleShortVersionString` and the `CFBundleVersion` as "`CFBundleShortVersionString`.`CFBundleVersion`". The intention is the `CFBundleShortVersionString` is a public/marketing/semantic version only bumped for releases, and the `CFBundleVersion` is a forever-incrementing build number (integer) which can be bumped during development/testing/releases. Thus you may have a "2.0.1.55" then a "2.0.1.56" and finally "2.0.1.57" is actually what's released to the public, so next version becomes "3.0.0.58".

If you wish to have a different approach, you can subclass the relevant `HEAnalyticsPlatform` and override `appVersion()`.

## Opt-Out

Tracking and privacy are important to users. Many analytics platforms offer a means of opting out, and so `HEAnalytics` provides and API for this.
Expand Down

0 comments on commit 1e5cea5

Please sign in to comment.