谷歌分析没有在iOS发送任何点击?

时间:2015-09-23 08:58:59

标签: ios objective-c google-analytics analytics

我创建了示例项目并添加了基于Google教程的Google Analytics。 但是当我运行这个应用程序时,我看不到从应用程序发送的任何点击。

I have added all these libraries
1.libsqlite3.0.tbd
2.libGoogleAnalyticsServices.a
3.libsqlite3.dylib
4.libz.dylibs
5.CoreData.framework
6.SystemConfiguration.framework

也添加了这些库文件

1.GAI.h
2.GAIDictionaryBuilder.h
3.GAIEcommerceFields.h
4.GAIEcommerceProduct.h
5.GAIEcommerceProductAction.h
6.GAIEcommercePromotion.h
7.GAIFields.h
8.GAILogger.h
9.GAITrackedViewController.h
10.GAITracker.h

在我的AppDelegate.h中

#import <UIKit/UIKit.h>
#import "GAI.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) id<GAITracker> tracker;

@property (strong, nonatomic) UIWindow *window;


@end

在我的AppDelegate.m文件中

#import "GAIDictionaryBuilder.h"
#import "AppDelegate.h"
#import "GAI.h"
#import "GAIFields.h"
/** Google Analytics configuration constants **/
static NSString *const kGaPropertyId = @"UA-000000-1"; // Placeholder property ID.
static NSString *const kTrackingPreferenceKey = @"allowTracking";
static BOOL const kGaDryRun = NO;
static int const kGaDispatchPeriod = 30;
@interface AppDelegate ()

@end

@implementation AppDelegate


- (void)applicationDidBecomeActive:(UIApplication *)application {
    [GAI sharedInstance].optOut =
    ![[NSUserDefaults standardUserDefaults] boolForKey:kTrackingPreferenceKey];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Do other work for customization after application launch
    // then initialize Google Analytics.
    [self initializeGoogleAnalytics];

    return YES;
}

- (void)initializeGoogleAnalytics {

    [[GAI sharedInstance] setDispatchInterval:kGaDispatchPeriod];
    [[GAI sharedInstance] setDryRun:kGaDryRun];
    self.tracker = [[GAI sharedInstance] trackerWithTrackingId:kGaPropertyId];
}

在我的ViewController.h中

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController


@end

在我的ViewController.m

#import "ViewController.h"
#import "GAI.h"
#import "GAIFields.h"
#import "GAITracker.h"
#import "GAIDictionaryBuilder.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewDidAppear {
    // 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.
    [[GAI sharedInstance].defaultTracker set:kGAIScreenName
                                       value:@"Home Screen"];

    // Send the screen view.
    // Previous V3 SDK versions.
    // [[GAI sharedInstance].defaultTracker
    //     send:[[GAIDictionaryBuilder createAppView] build]];

    // SDK Version 3.08 and up.
    [[GAI sharedInstance].defaultTracker
     send:[[GAIDictionaryBuilder createScreenView] build]];
}

我无法向谷歌分析发送屏幕名称请帮助我......

1 个答案:

答案 0 :(得分:0)

将此项用于viewdidload

- (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];

        id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
        [tracker set:kGAIScreenName value:kBookingConfirmation];
        [tracker send:[[GAIDictionaryBuilder createAppView] build]];
    }
相关问题