How to disable Google Tag Manager console logging

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
}

Swift 3 version of Scoud's solution:

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
}

You didn't specify the language. Warning level would seem enough in your case.

// Optional: Change the LogLevel to Verbose to enable logging at VERBOSE and higher levels.
[self.tagManager.logger setLogLevel:kTAGLoggerLogLevelVerbose];

Available levels (docs):

  • kTAGLoggerLogLevelVerbose
  • kTAGLoggerLogLevelDebug
  • kTAGLoggerLogLevelInfo
  • kTAGLoggerLogLevelWarning
  • kTAGLoggerLogLevelError
  • kTAGLoggerLogLevelNone

From the official docs: https://developers.google.com/tag-manager/ios/v3/#logger (deprecated in favor of Firebase Analytics)