Skip to content

Commit

Permalink
change properties param name
Browse files Browse the repository at this point in the history
add comment
format
  • Loading branch information
NicolasMassart committed Aug 26, 2024
1 parent 7f1cce6 commit 64e5a39
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions app/util/events/convertLegacyProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,42 @@ function isEventProperties(
/**
* Convert legacy properties to the new EventProperties type if needed
*
* There are two types of legacy properties:
* - properties with the new structure (properties and sensitiveProperties) but with anonymous properties inside properties
* - properties with the old structure (just a JsonMap) and possibly anonymous properties inside
*
* If the properties are already of the new type, they are returned as is
* @param properties
* @param propertiesParam the properties to check for conversion and convert if needed
*/
function convertLegacyProperties(
properties: CombinedProperties,
propertiesParam: CombinedProperties,
): EventProperties {
if (isEventProperties(properties)) {
if (isEventProperties(propertiesParam)) {
// EventProperties non-anonymous properties could have anonymous properties inside
// so we need to process them separately
if (properties.properties && Object.keys(properties.properties).length) {
if (
propertiesParam.properties &&
Object.keys(propertiesParam.properties).length
) {
const [nonAnonymousProperties, anonymousProperties] =
preProcessAnalyticsEvent(properties.properties);
preProcessAnalyticsEvent(propertiesParam.properties);
return {
properties: nonAnonymousProperties,
// and concatenate all the anon props in sensitiveProperties
sensitiveProperties: {
...anonymousProperties,
...properties.sensitiveProperties,
...propertiesParam.sensitiveProperties,
},
};
}
// If there are no non-anonymous properties, we don't need to process them
// and we can return the object as is
return properties;
return propertiesParam;
}

// if the properties are not of the new type, we need to process them
const [nonAnonymousProperties, anonymousProperties] =
preProcessAnalyticsEvent(properties);
preProcessAnalyticsEvent(propertiesParam);
return {
properties: nonAnonymousProperties,
sensitiveProperties: anonymousProperties,
Expand Down

0 comments on commit 64e5a39

Please sign in to comment.