Rename the analytics API #19
Labels
📦 analytics
Relative to the `@farfetch/blackout-analytics` package
postponed
If for some reason this issue lost priority and was postponed to be implemented/fixed in the future.
🚨 BREAKING CHANGE
Something that introduces a breaking API change
status: accepted
It's clear what the subject of the issue is about, and what the resolution should be
type: feature
New feature
Milestone
Is your proposal related to a problem?
To make the analytics API more consistent and easier to understand.
Describe the solution you'd like
Lifecycle events
The
Integration
class methodsetConsent
should be renamed toonSetConsent
to be consistent withonSetUser
method.The
loadIntegration
event type should be dropped in favour of theonSetUser
event that should be called automatically by analytics if the user was set in analytics through theanalytics.setUser
method.Analytics
analytics.user
method toanalytics.getCurrentUserData
. CurrentUser was chosen to clear some ambiguity thatanalytics.user
could bring as, without looking at the documentation of its only argument, we could think that this function accepts a user id and retrieves the instance of the user associated with that id. Also, this name makes it clear it will only get the data that was set and not a user instance that can manipulate the user data.analytics.consent
method toanalytics.getConsentData
. Same reasoning as the one used inanalytics.getCurrentUserData
except that there was no need to use 'current' in the name as there is no ambiguity in that case.analytics.context
method toanalytics.getContextData
(same reasoning as explained before)analytics.integration
method toanalytics.getIntegrationInstance
to make it clear that it will return the fully instantiated instance of the integration associated with its name argument.analytics.setUser
andanalytics.setConsent
methods as we could imply by their names that the previous set values are completely overridden by the values passed on the call to these methods. However, that is not the case as they are only merged with the previous values. For example, if a call tosetUser
method is made with10
as theuserId
and{ isGuest: true, email: [email protected] }
as itsproperties
and then another call is made tosetUser
with20
as theuserId
and{ isGuest: false }
, it could be expected that the email property would be dropped, which is not the case. However, other analytics libraries that have the same nomenclature (ga/firebaseset
methods for example) works the same way, so it is ok to keep using the same names, while also documenting this behaviour and indicating alternative methods to clear all the data. ForsetUser
we have theanonymize
method but forsetConsent
there is nothing available that clears all data, so it might make sense to add one as well.Describe alternatives you've considered
About the
loadIntegration
event type, there are some integrations that access it to get other data set in analytics. However, none of them is looking at theloadIntegration
event type specifically. They are either accessing thecontext
orconsent
variables, which probably means that theloadData
parameter is used not as an event but as a shortcut to get some analytics values, so we could ditch theevent
property altogether from theloadData
parameter as it is not an event per see.Regarding the changes for
analytics.user
,analytics.consent
andanalytics.integration
method names, maybe there is no need to have such verbose method names. Since we'll not change what data they return, it will continue to be clear for the developers what these methods are for, and we could simplify the naming a bit by just adding the prefixget{MethodName}
, to match the opposite methods we have that have the prefixset{MethodName}
for setting those values.Additional information
Decision log 19 Feb:
@onIntegrationInit
both for thetype
and forevent
(and export these constants for reusability);get{MethodName}
andset{MethodName}
. (addIntegration
will continue the same, but the getter will be changed togetIntegration
);The text was updated successfully, but these errors were encountered: