Skip to content

Commit 1257a7f

Browse files
committed
Added check for mixpanel default properties
1 parent 56e16a1 commit 1257a7f

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

src/main/java/io/fi0x/javalogger/mixpanel/MixpanelHandler.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import org.json.JSONObject;
1111

1212
import java.io.IOException;
13-
import java.util.HashMap;
14-
import java.util.Map;
13+
import java.util.*;
1514

1615
public class MixpanelHandler
1716
{
@@ -70,6 +69,21 @@ public static boolean addMessage(String eventName, Map<String, String> propertie
7069

7170
if(properties == null)
7271
properties = new HashMap<>();
72+
73+
for(String prop : properties.keySet())
74+
{
75+
if(MIXPANEL_PROPERTIES.contains(prop.toLowerCase(Locale.ROOT)))
76+
{
77+
LogEntry l = new LogEntry("Could not add Mixpanel-event to queue. Property '" + prop + "' is a property mixpanel uses itself")
78+
.COLOR(LogColor.RED)
79+
.LEVEL("ERR")
80+
.CODE(0)
81+
.FILE_ENTRY(false);
82+
Logger.log(l);
83+
return false;
84+
}
85+
}
86+
7387
properties.putAll(defaultProperties);
7488

7589
JSONObject props = new JSONObject();
@@ -103,6 +117,9 @@ public static boolean addDefaultProperty(String propertyName, String propertyVal
103117
if(defaultProperties.containsKey(propertyName))
104118
return false;
105119

120+
if(MIXPANEL_PROPERTIES.contains(propertyName.toLowerCase(Locale.ROOT)))
121+
return false;
122+
106123
defaultProperties.put(propertyName, propertyValue);
107124
return true;
108125
}
@@ -194,4 +211,14 @@ private static IOException sendDelivery()
194211
delivery = null;
195212
return null;
196213
}
214+
private static final ArrayList<String> MIXPANEL_PROPERTIES = new ArrayList<>()
215+
{{
216+
add("api endpoint");
217+
add("api timestamp");
218+
add("distinct id");
219+
add("insert id");
220+
add("mixpanel library");
221+
add("time");
222+
add("time processed");
223+
}};
197224
}

0 commit comments

Comments
 (0)