繁体   English   中英

Google Analytics(分析)自定义变量无法在ios上正常运行

[英]Google Analytics custom Variable is not working fine with ios

我在iOS上使用Google Analytics(分析),并且我想在调用viewDidAppear后立即更新自定义变量的数量,这是我的代码。

for (int i = 0 ; i < [KeyArray count]; i++) {
        error = nil;
        if ([KeyArray objectAtIndex:i] == @"Carat") {
            NSDictionary *caratDict = [selectedDiamondsFilter objectForKey:[KeyArray objectAtIndex:i]];
            NSString *value = [NSString stringWithFormat:@"Carat From %@ to %@",[caratDict objectForKey:@"caratfrom"],[caratDict objectForKey:@"caratto"]];
            NSLog(@"%@",value);
            if (![[GANTracker sharedTracker] setCustomVariableAtIndex:1 name:@"Carat" value:value scope:kGANVisitorScope withError:&error]) {
                NSLog(@"carat =%@",error);
            }

            if(![[GANTracker sharedTracker] trackEvent:@"Diamond Sort" action:@"Sort selected" label:@"sort" value:-1 withError:nil]){
                NSLog(@"Not able to track for Diamonds Section");
            }
            [[GANTracker sharedTracker] dispatch];

        }
        else if ([KeyArray objectAtIndex:i] == @"Clarity") {
            NSDictionary *caratDict = [selectedDiamondsFilter objectForKey:[KeyArray objectAtIndex:i]];
            NSString *value = [NSString stringWithFormat:@"Clarity From %@ to %@",[caratDict objectForKey:@"clarityfrom"],[caratDict objectForKey:@"clarityto"]];
            NSLog(@"%@",value);
            [[GANTracker sharedTracker] setCustomVariableAtIndex:1 name:@"Clarity" value:value scope:kGANVisitorScope withError:&error];
            if(![[GANTracker sharedTracker] trackEvent:@"Diamond Sort" action:@"Sort selected" label:@"sort" value:-1 withError:nil]){
                NSLog(@"Not able to track for Diamonds Section");
            }

        }
        else if ([KeyArray objectAtIndex:i] == @"Color") {
            NSDictionary *caratDict = [selectedDiamondsFilter objectForKey:[KeyArray objectAtIndex:i]];
            NSString *value = [NSString stringWithFormat:@"Color From %@ to %@",[caratDict objectForKey:@"colorfrom"],[caratDict objectForKey:@"colorto"]];
            NSLog(@"%@",value);
            [[GANTracker sharedTracker] setCustomVariableAtIndex:1 name:@"Color" value:value scope:kGANVisitorScope withError:&error];
            if(![[GANTracker sharedTracker] trackEvent:@"Diamond Sort" action:@"Sort selected" label:@"sort" value:-1 withError:nil]){
                NSLog(@"Not able to track for Diamonds Section");
            }

        }
        else if ([KeyArray objectAtIndex:i] == @"Price") {
            NSDictionary *caratDict = [selectedDiamondsFilter objectForKey:[KeyArray objectAtIndex:i]];
            NSString *value = [NSString stringWithFormat:@"Price From %@ to %@",[caratDict objectForKey:@"pricefrom"],[caratDict objectForKey:@"priceto"]];
            NSLog(@"%@",value);
            [[GANTracker sharedTracker] setCustomVariableAtIndex:1 name:@"Price" value:value scope:kGANVisitorScope withError:&error];
            if(![[GANTracker sharedTracker] trackEvent:@"Diamond Sort" action:@"Sort selected" label:@"sort" value:-1 withError:nil]){
                NSLog(@"Not able to track for Diamonds Section");
            }

        }
        else if ([KeyArray objectAtIndex:i] == @"Shape") {
            NSArray *shapes = [selectedDiamondsFilter objectForKey:[KeyArray objectAtIndex:i]];
            for (int i = 0; i<[shapes count]; i++) {
                [[GANTracker sharedTracker] setCustomVariableAtIndex:1 name:@"Shape" value:[shapes objectAtIndex:i] scope:kGANVisitorScope withError:&error];
                NSLog(@"%@",[shapes objectAtIndex:i]);
                if(![[GANTracker sharedTracker] trackEvent:@"Diamond Sort" action:@"Sort selected" label:@"sort" value:-1 withError:nil]){
                    NSLog(@"Not able to track for Diamonds Section");
                }

            }
            NSLog( @"%@",shapes);

        }
        else if ([KeyArray objectAtIndex:i] == @"Type") {
            NSArray *types = [selectedDiamondsFilter objectForKey:[KeyArray objectAtIndex:i]];
            for (int i = 0; i<[types count]; i++) {
                NSLog(@"%@",[types objectAtIndex:i]);
                [[GANTracker sharedTracker] setCustomVariableAtIndex:1 name:@"Type" value:[types objectAtIndex:i] scope:kGANVisitorScope withError:&error];
                if(![[GANTracker sharedTracker] trackEvent:@"Diamond Sort" action:@"Sort selected" label:@"sort" value:-1 withError:nil]){
                    NSLog(@"Not able to track for Diamonds Section");
                }                   
            }

        }

        [[GANTracker sharedTracker] dispatch];

        if (error != nil) {
            NSLog(@"Custom Variable HAS ERROR");
        }

        NSLog(@"%@",selectedDiamondsFilter);
    }

但是问题在于它有时在“类型”有时在“克拉”的情况下进行更新。

请帮助我在哪里我犯错了。

提前致谢

您的比较指针,不好。

所有这些都需要更改为:

if([KeyArray objectAtIndex:i] isEqualToString:@"Carat"]])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM