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

Fix MPConfig.UseIpAddressForGeolocation gets ignored #780

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ public void testSetServerURL() throws Exception {
// default Mixpanel endpoint
assertEquals("https://api.mixpanel.com/track/?ip=1", config.getEventsEndpoint());
assertEquals("https://api.mixpanel.com/engage/?ip=1", config.getPeopleEndpoint());
assertEquals("https://api.mixpanel.com/groups/", config.getGroupsEndpoint());
assertEquals("https://api.mixpanel.com/groups/?ip=1", config.getGroupsEndpoint());
assertEquals("https://api.mixpanel.com/decide", config.getDecideEndpoint());

mixpanelAPI.setServerURL("https://api-eu.mixpanel.com");
assertEquals("https://api-eu.mixpanel.com/track/?ip=1", config.getEventsEndpoint());
assertEquals("https://api-eu.mixpanel.com/engage/?ip=1", config.getPeopleEndpoint());
assertEquals("https://api-eu.mixpanel.com/groups/", config.getGroupsEndpoint());
assertEquals("https://api-eu.mixpanel.com/groups/?ip=1", config.getGroupsEndpoint());
assertEquals("https://api-eu.mixpanel.com/decide", config.getDecideEndpoint());
}

@Test
public void testSetUseIpAddressForGeolocation() throws Exception {
public void testSetUseIpAddressForGeolocation() {
final Bundle metaData = new Bundle();
metaData.putString("com.mixpanel.android.MPConfig.EventsEndpoint", "https://api.mixpanel.com/track/?ip=1");
metaData.putString("com.mixpanel.android.MPConfig.EventsEndpoint", "https://api.mixpanel.com/track/?ip=1");
Expand All @@ -48,19 +48,18 @@ public void testSetUseIpAddressForGeolocation() throws Exception {
mixpanelAPI.setUseIpAddressForGeolocation(false);
assertEquals("https://api.mixpanel.com/track/?ip=0", config.getEventsEndpoint());
assertEquals("https://api.mixpanel.com/engage/?ip=0", config.getPeopleEndpoint());
assertEquals("https://api.mixpanel.com/groups/", config.getGroupsEndpoint());
assertEquals("https://api.mixpanel.com/groups/?ip=0", config.getGroupsEndpoint());
assertEquals("https://api.mixpanel.com/decide", config.getDecideEndpoint());

mixpanelAPI.setUseIpAddressForGeolocation(true);

assertEquals("https://api.mixpanel.com/track/?ip=1", config.getEventsEndpoint());
assertEquals("https://api.mixpanel.com/engage/?ip=1", config.getPeopleEndpoint());
assertEquals("https://api.mixpanel.com/groups/", config.getGroupsEndpoint());
assertEquals("https://api.mixpanel.com/groups/?ip=1", config.getGroupsEndpoint());
assertEquals("https://api.mixpanel.com/decide", config.getDecideEndpoint());
}

@Test
public void testSetUseIpAddressForGeolocationOverwrite() throws Exception {
public void testSetUseIpAddressForGeolocationOverwrite() {
final Bundle metaData = new Bundle();
metaData.putString("com.mixpanel.android.MPConfig.EventsEndpoint", "https://api.mixpanel.com/track/?ip=1");
metaData.putString("com.mixpanel.android.MPConfig.PeopleEndpoint", "https://api.mixpanel.com/engage/?ip=1");
Expand Down Expand Up @@ -88,6 +87,51 @@ public void testSetUseIpAddressForGeolocationOverwrite() throws Exception {
assertEquals("https://api.mixpanel.com/engage/?ip=1", config2.getPeopleEndpoint());
}

@Test
public void testEndPointAndGeoSettingBothReadFromConfigTrue() {
final Bundle metaData = new Bundle();
metaData.putString("com.mixpanel.android.MPConfig.EventsEndpoint", "https://api.mixpanel.com/track/");
metaData.putString("com.mixpanel.android.MPConfig.PeopleEndpoint", "https://api.mixpanel.com/engage/");
metaData.putString("com.mixpanel.android.MPConfig.GroupsEndpoint", "https://api.mixpanel.com/groups/");
metaData.putBoolean("com.mixpanel.android.MPConfig.UseIpAddressForGeolocation", true);

MPConfig config = mpConfig(metaData);
final MixpanelAPI mixpanelAPI = mixpanelApi(config);
assertEquals("https://api.mixpanel.com/track/?ip=1", config.getEventsEndpoint());
assertEquals("https://api.mixpanel.com/engage/?ip=1", config.getPeopleEndpoint());
assertEquals("https://api.mixpanel.com/groups/?ip=1", config.getGroupsEndpoint());
}

@Test
public void testEndPointAndGeoSettingBothReadFromConfigFalse() {
final Bundle metaData = new Bundle();
metaData.putString("com.mixpanel.android.MPConfig.EventsEndpoint", "https://api.mixpanel.com/track/");
metaData.putString("com.mixpanel.android.MPConfig.PeopleEndpoint", "https://api.mixpanel.com/engage/");
metaData.putString("com.mixpanel.android.MPConfig.GroupsEndpoint", "https://api.mixpanel.com/groups/");
metaData.putBoolean("com.mixpanel.android.MPConfig.UseIpAddressForGeolocation", false);

MPConfig config = mpConfig(metaData);
final MixpanelAPI mixpanelAPI = mixpanelApi(config);
assertEquals("https://api.mixpanel.com/track/?ip=0", config.getEventsEndpoint());
assertEquals("https://api.mixpanel.com/engage/?ip=0", config.getPeopleEndpoint());
assertEquals("https://api.mixpanel.com/groups/?ip=0", config.getGroupsEndpoint());
}

@Test
public void testEndPointAndGeoSettingBothReadFromConfigFalseOverwrite() {
final Bundle metaData = new Bundle();
metaData.putString("com.mixpanel.android.MPConfig.EventsEndpoint", "https://api.mixpanel.com/track/?ip=1");
metaData.putString("com.mixpanel.android.MPConfig.PeopleEndpoint", "https://api.mixpanel.com/engage/?ip=1");
metaData.putString("com.mixpanel.android.MPConfig.GroupsEndpoint", "https://api.mixpanel.com/groups/?ip=1");
metaData.putBoolean("com.mixpanel.android.MPConfig.UseIpAddressForGeolocation", false);

MPConfig config = mpConfig(metaData);
final MixpanelAPI mixpanelAPI = mixpanelApi(config);
assertEquals("https://api.mixpanel.com/track/?ip=0", config.getEventsEndpoint());
assertEquals("https://api.mixpanel.com/engage/?ip=0", config.getPeopleEndpoint());
assertEquals("https://api.mixpanel.com/groups/?ip=0", config.getGroupsEndpoint());
}

@Test
public void testSetEnableLogging() throws Exception {
final Bundle metaData = new Bundle();
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/mixpanel/android/mpmetrics/MPConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,24 +210,25 @@ public synchronized void setOfflineMode(OfflineMode offlineMode) {
}
}
mDataExpiration = dataExpirationLong;
boolean noUseIpAddressForGeolocationSetting = !metaData.containsKey("com.mixpanel.android.MPConfig.UseIpAddressForGeolocation");

String eventsEndpoint = metaData.getString("com.mixpanel.android.MPConfig.EventsEndpoint");
if (eventsEndpoint != null) {
setEventsEndpoint(eventsEndpoint);
setEventsEndpoint(noUseIpAddressForGeolocationSetting ? eventsEndpoint : getEndPointWithIpTrackingParam(eventsEndpoint, getUseIpAddressForGeolocation()));
} else {
setEventsEndpointWithBaseURL(MPConstants.URL.MIXPANEL_API);
}

String peopleEndpoint = metaData.getString("com.mixpanel.android.MPConfig.PeopleEndpoint");
if (peopleEndpoint != null) {
setPeopleEndpoint(peopleEndpoint);
setPeopleEndpoint(noUseIpAddressForGeolocationSetting ? peopleEndpoint : getEndPointWithIpTrackingParam(peopleEndpoint, getUseIpAddressForGeolocation()));
} else {
setPeopleEndpointWithBaseURL(MPConstants.URL.MIXPANEL_API);
}

String groupsEndpoint = metaData.getString("com.mixpanel.android.MPConfig.GroupsEndpoint");
if (groupsEndpoint != null) {
setGroupsEndpoint(groupsEndpoint);
setGroupsEndpoint(noUseIpAddressForGeolocationSetting ? groupsEndpoint : getEndPointWithIpTrackingParam(groupsEndpoint, getUseIpAddressForGeolocation()));
} else {
setGroupsEndpointWithBaseURL(MPConstants.URL.MIXPANEL_API);
}
Expand Down Expand Up @@ -316,7 +317,7 @@ public String getGroupsEndpoint() {
}

private void setGroupsEndpointWithBaseURL(String baseURL) {
setGroupsEndpoint(baseURL + MPConstants.URL.GROUPS);
setGroupsEndpoint(getEndPointWithIpTrackingParam(baseURL + MPConstants.URL.GROUPS, getUseIpAddressForGeolocation()));
}

private void setGroupsEndpoint(String groupsEndpoint) {
Expand Down Expand Up @@ -360,6 +361,7 @@ public void setUseIpAddressForGeolocation(boolean useIpAddressForGeolocation) {
mUseIpAddressForGeolocation = useIpAddressForGeolocation;
setEventsEndpoint(getEndPointWithIpTrackingParam(getEventsEndpoint(), useIpAddressForGeolocation));
setPeopleEndpoint(getEndPointWithIpTrackingParam(getPeopleEndpoint(), useIpAddressForGeolocation));
setGroupsEndpoint(getEndPointWithIpTrackingParam(getGroupsEndpoint(), useIpAddressForGeolocation));
}

public void setEnableLogging(boolean enableLogging) {
Expand Down