如何禁用Google跟踪代码管理器控制台记录

Raf*_*fAl 7 ios google-tag-manager

在我将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;
}
Run Code Online (Sandbox Code Playgroud)

小智 13

我刚刚在一个结合了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
}
Run Code Online (Sandbox Code Playgroud)

  • @Scoud我们需要在哪里实现此代码?我在AppDelegate类中尝试过,但仍在获取日志。 (2认同)

小智 5

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
}
Run Code Online (Sandbox Code Playgroud)