将Google跟踪代码管理器添加到项目后,我在控制台中看到了很多日志条目。有没有办法禁用它?控制台日志充满了噪音:
GoogleTagManager info: Processing logged event: _vs with parameters: {
"_o" = auto;
"_pc" = UIViewController;
"_pi" = "-3988739357756819671";
"_sc" = "Bubbie.MamboBamboViewController";
"_si" = "-3988739357756819670";
}
2017-07-27 12:01:09.744 BubbieHuff[77205:6894827] GoogleTagManager info: Processing logged event: show_view with parameters: {
"_sc" = "Bubbie.MamboBamboViewController";
"_si" = "-3988739357756819670";
name = Mambo;
}
我刚刚在一个结合了Google跟踪代码管理器和Firebase的项目中遇到了这个问题。由于没有关于日志记录的标题暴露,我无法找到关闭它的方法。
这是我提出的一个猴子补丁,可以让你控制GTM的信息日志。
+ (void)patchGoogleTagManagerLogging {
Class class = NSClassFromString(@"TAGLogger");
SEL originalSelector = NSSelectorFromString(@"info:");
SEL detourSelector = @selector(detour_info:);
Method originalMethod = class_getClassMethod(class, originalSelector);
Method detourMethod = class_getClassMethod([self class], detourSelector);
class_addMethod(class,
detourSelector,
method_getImplementation(detourMethod),
method_getTypeEncoding(detourMethod));
method_exchangeImplementations(originalMethod, detourMethod);
}
+ (void)detour_info:(NSString*)message {
return; // Disable logging
}
Swift 3版Scoud的解决方案:
static func hideGTMLogs() {
let tagClass: AnyClass? = NSClassFromString("TAGLogger")
let originalSelector = NSSelectorFromString("info:")
let detourSelector = #selector(AppDelegate.detour_info(message:))
guard let originalMethod = class_getClassMethod(tagClass, originalSelector),
let detourMethod = class_getClassMethod(AppDelegate.self, detourSelector) else { return }
class_addMethod(tagClass, detourSelector,
method_getImplementation(detourMethod), method_getTypeEncoding(detourMethod))
method_exchangeImplementations(originalMethod, detourMethod)
}
@objc
static func detour_info(message: String) {
return
}
您没有指定语言。在你的情况下,警告水平似乎足够了。
// Optional: Change the LogLevel to Verbose to enable logging at VERBOSE and higher levels.
[self.tagManager.logger setLogLevel:kTAGLoggerLogLevelVerbose];
可用等级(docs):
来自官方文档:https://developers.google.com/tag-manager/ios/v3/#logger(不赞成使用Firebase Analytics)