1

I have in my widget a few buttons and I want to track clicks.

Is this possible or even allowed by Apple? I'm have been looking for information but can't find any.

Daniel Casserly
  • 3,552
  • 2
  • 29
  • 60
FreeGor
  • 615
  • 13
  • 26

2 Answers2

2

It's really simple. In the navigator panel of your containing app select libGoogleAnalyticsServices.a file and in File Inspector check it for your extension target: File Inspector

I did it for libAdIdAccess.a too and for all frameworks needed for GA:

  • CoreData.framework
  • SystemConfiguration.framework
  • libz.dylib
  • libsqlite3.dylib
  • libGoogleAnalyticsServices.a

Next go to viewDidLoad of your Widget ViewController and do an ordinarily implementation for GA SDK: import headers, init tracker, send events. You can immediately check how it work in Real-Time section of GA interface.

FreeGor
  • 615
  • 13
  • 26
  • I get a warning: "linking against dylib not safe for use in application extensions" but it appears to be working – Fraser Jun 10 '15 at 03:07
  • 1
    To configure an app extension target to use an embedded framework, set the target’s “Require Only App-Extension-Safe API” build setting to Yes. If you don’t, Xcode reminds you to do so by displaying the warning “linking against dylib not safe for use in application extensions”. – FreeGor Jun 10 '15 at 08:54
  • Thanks FreeGor! It was set to YES but changing to NO removed the warning – Fraser Jun 10 '15 at 21:51
  • Has anyone had any experience with using the same tracking ID for both the iOS app and its extension? Is there a risk in doing so? – Ricky Mar 20 '17 at 04:49
  • @Ricky I do not think there is any risk, but why mix it? This can affect the statistics of launching applications events, users sessions, etc. – FreeGor Mar 20 '17 at 12:01
  • @FreeGor Good point, I didn't consider that, especially launch. I have ~18 apps with extensions so was trying to avoid creating new tracking IDs. – Ricky Mar 20 '17 at 12:34
2

A small addition to the answer from @FreeGor. Tracker in the Widget Controller should be initialized using:

id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:@"UA-XXX-XX"];

in order to send properly events to GA

Alessandro
  • 21
  • 3