Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates group to accept new group settings #43

Merged
merged 5 commits into from Oct 25, 2017
Merged

Conversation

ladanazita
Copy link
Contributor

Amplitude allows customers to send multiple types of groups on the same event, for example
group_type: org name
group_value: engineering

group_type: org id
group_value: 1234

The new Segment settings groupTypeTrait (group type) and groupTypeValue (group value) allow the user to set which keys the Segment integration will look for to determine what to set for group name and group values in Amplitude.

We will default to legacy behavior, which was incorrect prior to this PR (incorrectly setting group type as [Segment] Group and group.id to group name)

@SegmentBot
Copy link

By analyzing the blame information on this pull request, we identified and undefined to be a potential reviewer.

if ([payload.traits objectForKey:groupTypeTrait] && [payload.traits objectForKey:groupTypeValue]) {
groupName = [payload.traits objectForKey:groupTypeTrait];
groupValue = [payload.traits objectForKey:groupTypeValue];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line?

}

[self.amplitude setGroup:groupValue groupName:groupName];
SEGLog(@"[Amplitude setGroup:%@' groupName:%@]", groupValue, groupName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra '?

NSString *groupName;
NSString *groupValue = payload.groupId;

NSString *groupTypeTrait = self.settings[@"groupTypeTrait"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if groupTypeTrait is not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will default to the old behavior. Or are you saying to check if the value for this setting exists?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. I was wondering what would happen at payload.traits objectForKey:groupTypeTrait if groupTypeTrait is null here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will just default to the original behavior


NSString *groupName;
NSString *groupValue;
if ([payload.traits objectForKey:groupTypeTrait] && [payload.traits objectForKey:groupTypeValue]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be payload.traits[groupTypeTrait]?

[self.amplitude setGroup:@"[Segment] Group" groupName:groupId];
SEGLog(@"[Amplitude setGroup:@'[Segment] Group' groupName:%@]", groupId);
NSString *groupTypeTrait;
if (self.settings[@"groupTypeTrait"]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this is an if check.

What's the difference between these two pieces of code:

NSString *groupTypeTrait = self.settings[@"groupTypeTrait"];
NSString *groupTypeTrait;
if (self.settings[@"groupTypeTrait"]) {
  groupTypeTrait = self.settings[@"groupTypeTrait"];
}

They seem functionally equivalent to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misunderstood your original question then about "What happens if groupTypeTrait is not set?"

will revert

andAmpRevenue:amprevenue];
SEGGroupPayload *payload = [[SEGGroupPayload alloc] initWithGroupId:@"32423084" traits:@{
@"company" : @"Segment",
@"industry" : @"Technology"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks ok, but I think it's a bit confusing since groupType:groupTrait should follow the pattern general:specific. Here, looks like specific:general (i.e. Segment:Technology).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, changed 👇

@ladanazita ladanazita merged commit 2568f8f into master Oct 25, 2017
@ladanazita ladanazita deleted the update/group branch October 25, 2017 19:13
if (groupId) {
[self.amplitude setGroup:@"[Segment] Group" groupName:groupId];
SEGLog(@"[Amplitude setGroup:@'[Segment] Group' groupName:%@]", groupId);
NSString *groupTypeTrait = self.settings[@"groupTypeTrait"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block:

    NSString *groupTypeTrait = self.settings[@"groupTypeTrait"];
    NSString *groupTypeValue = self.settings[@"groupTypeValue"];
    NSString *groupName;
    NSString *groupValue;

    if (payload.traits[groupTypeTrait] && payload.traits[groupTypeValue]) {
        groupName = payload.traits[groupTypeTrait];
        groupValue = payload.traits[groupTypeValue];
    } else {
        groupName = payload.traits[@"name"] ?: @"[Segment] Group";
        groupValue = payload.groupId;
    }

Is likely more readable and less error prone as:

    NSString *groupTypeTrait = self.settings[@"groupTypeTrait"];
    NSString *groupTypeValue = self.settings[@"groupTypeValue"];
    NSString *groupName = payload.traits[groupTypeTrait];
    NSString *groupValue = payload.traits[groupTypeValue];

    if (!groupName || !groupValue) {
        groupName = payload.traits[@"name"] ?: @"[Segment] Group";
        groupValue = payload.groupId;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#47

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants