segment-integrations / analytics-ios-integration-amplitude

The Amplitude analytics-ios integration.
MIT License
11 stars 45 forks source link

Traits don't update when using certain settings #102

Open cerupcat opened 3 years ago

cerupcat commented 3 years ago

When using traitsToIncrement or traitsToSetOnce, the traits that aren't incremental or set once don't override the current user properties in amplitude.

I've testing by calling [self.amplitude setUserProperties:payload.traits]; directly and the traits correctly update/override. However, when a incremental or setOnce trait is used (via Segment dashboard settings), this call isn't used an instead it calls:

- (void)incrementOrSetTraits:(NSDictionary *)traits
{
    for (NSString *trait in traits) {
        id value = [traits valueForKey:trait];
        if ([self.traitsToIncrement member:trait]) {
            [self.amplitude identify:[self.identify add:trait value:value]];
            SEGLog(@"[Amplitude add:%@ value:%@]", trait, value);
        } else if ([self.traitsToSetOnce member:trait]) {
            [self.amplitude identify:[self.identify setOnce:trait value:value]];
        } else {
            [self.amplitude identify:[self.identify set:trait value:value]]; // don't override traits and is essentially a set once
            SEGLog(@"[Amplitude set:%@ value:%@]", trait, value);
        }
    }
}

[self incrementOrSetTraits:payload.traits]; is called and the function will fail to override traits that already exist rather than calling [self.amplitude setUserProperties:payload.traits]; which appears to work as expected.

The error amplitude will log:

        AMPLITUDE_LOG(@"Already used property '%@' in previous operation, ignoring for operation '%@'", property, operation);