Search code examples
iosgoogle-tag-manager

How to disable Google Tag Manager console logging


After I added Google Tag Manager to the project I see lots its log entries in the console. Is there a way to disable it? Console log is full of noise:

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;
}

Solution

  • I just had this problem in a project that combines Google Tag Manager and Firebase. Since no header about logging is exposed I couldn't find a way to turn it off.

    This is a monkey patch I came up with that lets you control the info logs from 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
    }