GAITrackedViewController 및 UITableViewController
iOS v2 용 Google 웹 로그 분석을 통해 Google GAITrackedViewController
은 UIViewController
. UITableViewController의 경우 우리는 무엇을합니까?
#import "GAITrackedViewController.h"
@interface AboutViewController : GAITrackedViewController
수동 화면 추적
GAITrackedViewController를 확장하는 것은 화면보기를 추적하는 한 가지 방법 일뿐입니다. 수동 방식도 마찬가지로 쉽습니다.
SDK v2
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// returns the same tracker you created in your app delegate
// defaultTracker originally declared in AppDelegate.m
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
// manual screen tracking
[tracker sendView:@"Home Screen"];
}
SDK v3
#import "GAI.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"
...
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// returns the same tracker you created in your app delegate
// defaultTracker originally declared in AppDelegate.m
id tracker = [[GAI sharedInstance] defaultTracker];
// This screen name value will remain set on the tracker and sent with
// hits until it is set to a new value or to nil.
[tracker set:kGAIScreenName
value:@"Home Screen"];
// manual screen tracking
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
}
참고
https://developers.google.com/analytics/devguides/collection/ios/v2/screens#manual https://developers.google.com/analytics/devguides/collection/ios/v3/screens#manual
Swift 프로젝트에서 수동 추적 코드를 정리하기 위해 다음 UIViewController
확장을 만들었습니다 .
extension UIViewController {
func trackScreenView(screenName: String) {
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: screenName)
tracker.send(GAIDictionaryBuilder.createAppView().build())
}
}
UIViewController의 속성을 사용하지 않기 때문에 이러한 방식으로 확장을 사용하는 것은 적절하지 않지만 전역 메서드보다 기분이 좋은 편리한 방법입니다. 멋진 형식의 이름 대신 클래스 이름을 사용해도 괜찮다면를 사용하여 다음 NSStringFromClass(self.dynamicType)
과 같이 ViewController 클래스 이름을 가져올 수도 있습니다 .
extension UIViewController {
func trackScreenView() {
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(kGAIScreenName, value: NSStringFromClass(self.dynamicType))
tracker.send(GAIDictionaryBuilder.createAppView().build())
}
}
이를 통해 다음 코드만으로 UITableViewController에서 수동 추적을 추가 할 수 있습니다.
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
trackScreenView("Detail View") //Or call this without any arguments if using the NSStringFromClass idea
}
좋고 깨끗합니다. 즐겨!
Sdk에 GAITrackedTableViewController가 누락 된 결과 수동 화면 viev 추적의 간단한 깔끔한 구현을 만들었습니다.
이미 싱글 톤이고 쉽게 액세스 할 수 있으므로 GAI 클래스에 대한 카테고리를 작성하십시오.
#import "GAI+Tracking.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"
@implementation GAI (Tracking)
- (void)trackScreenView:(NSString *)screenName
{
[self.defaultTracker set:kGAIScreenName value:screenName];
[self.defaultTracker send:[[GAIDictionaryBuilder createAppView] build]];
}
@end
이제 다음과 같은 화면보기를 추적하십시오.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[GAI sharedInstance] trackScreenView:@"Counts map screen"];
}
This kind of overules Googles idea of having more than one tracking at the same time. (I haven't had the need yet). To acommodate this just rename your tracking method after which tracker it uses, and use what ever tracker you want.
#import "GAI+Tracking.h"
#import "GAIFields.h"
#import "GAIDictionaryBuilder.h"
@implementation GAI (Tracking)
- (void)trackDefaultScreenView:(NSString *)screenName
{
[self.defaultTracker set:kGAIScreenName value:screenName];
[self.defaultTracker send:[[GAIDictionaryBuilder createAppView] build]];
}
@end
Make sure all your viewDidAppear call [super viewDidAppear]
Then make sure every single one of your subclass of UITableViewController is also a subclass of myTableViewController
in [myTableViewController viewDidAppear], implement all those other answers.
Just complementing all the other good answers out there. That way you get something as good as GAITrackedViewController.h
The same way I make sure all of my other UIViewController subclass is also a subclass of super UIViewController and then I do the same thing.
For Swift you can use
AppDelegate.appDelegateIns.defTrackerIns?.set(kGAIScreenName, value: "Enter Your Screen Name")
AppDelegate.appDelegateIns.defTrackerIns?.send(GAIDictionaryBuilder.createScreenView().build() as [NSObject : AnyObject])
Include This in your App Delegate
static let appDelegateIns = AppDelegate()
let gai = GAI.sharedInstance()
let defTrackerIns = GAI.sharedInstance().tracker(withTrackingId: "Your Tracking Id")
let gaDefTargetURL = "https://developers.google.com/analytics"
Assuming they don't have a subclass of UITableViewController themselves, I don't see why you couldn't use their GAITrackedViewController, and then implement the UITableViewDataSource and UITableViewDelegate protocols yourself.
UITableViewController Inherits from UIViewController : UIResponder : NSObject
On can subclass GAITrackedViewController and not do anything extra for virtually any kind of ViewController that inherits fro UIViewController.
참고URL : https://stackoverflow.com/questions/16289581/gaitrackedviewcontroller-and-uitableviewcontroller
'code' 카테고리의 다른 글
.ToString ()이 null 값이있는 nullable int에서 제대로 작동 할 때 null 문자열의 .ToString ()이 null 오류를 발생시키는 이유는 무엇입니까? (0) | 2020.11.04 |
---|---|
Python 데몬 및 systemd 서비스 (0) | 2020.11.04 |
Tensorflow 텐서 차원 (모양)을 정수 값으로 얻는 방법은 무엇입니까? (0) | 2020.11.04 |
SQL Server에서 날짜 플로어 (0) | 2020.11.04 |
비 활동 클래스에서 활동을 시작하려면 어떻게해야합니까? (0) | 2020.11.04 |