Amplitude
To capture an event you must follow these steps:
You must initialize amplitude first, for this you need to import the hook useInitAnalytics from the hooks folder.
import {useInitAnalytics} from 'LinkerStudio/modules/analytics/amplitude/hooks';
Then add the initialization by adding the following code block, which can receive a user identifier as a parameter. This parameter is optional.
useInitAnalytics();
Now you must import the following code block in the file where it is required so the event can be captured.
import {trackAnalyticsOfClick} from 'LinkerStudio/modules/analytics/amplitude/utils/trackAnalytics/trackAnalytics';
The function trackAnalyticsOnClick
will receive an object of type ParamsTrackAnalytic
Update --02/08/2023--
/**
* This params should be used to track error events.
* For Success events it is recommended to use Record<string, string>
*/
interface TrackParams {
success?: boolean; //Determines the successful or failure of the event
eventInfo?: {
message: string;
};
}
/**
* TrackParams should be used to track error events.
* For Success events it is recommended to use Record<string, string>
*/
export interface ParamsTrackAnalytics {
eventName: string; //Name of event
params?: TrackParams | Record<string, string>;
}
eventName: Is the name of the event that is running (required)
params: Object with typeof Record<string, string>.
These params are used to send a pair of string values defined in the analytics document. The pair is composed by a PropertyName and PropertyValue, the properties will be attached to the event.
Here's an example
You can use convertPropertiesToRecord
helper method to convert an array of properties to the expected format Record<string, string>
{
eventName: ANALYTICS_EVENT_NAMES.overflowStepCompleted,
params: convertPropertiesToRecord([
{
name: ANALYTICS_EVENT_PROPERTY_NAMES.stepName,
value: ANALYTICS_EVENT_PROPERTY_VALUES.accountSelection,
},
]),
}
For the errors it is preferred to call the helper method evaluateErrorMessage
because this method will parsed the data and will call the trackAnalyticsOnClick
internally.
Here's an example
evaluateErrorMessage(error, ANALYTICS_EVENT_NAMES.unlinkAccountConfirmed);
Calling trackAnalyticsOnClick
with the old structure will still supported for the events implemented before.
Before --02/03/2023--
interface TrackParams {
success?: boolean; //Determines the successful or failure of the event
eventInfo?: {
message: string;
};
}
interface ParamsTrackAnalytics {
eventName: string; //Name of event
params?: TrackParams;
}
eventName: Is the name of the event that is running (required)
params: Object composed of
success
and another object calledeventInfo
wheresuccess: Represents the success or failure of the event
eventInfo: Represents values that allow identifying the reason for the event
Here's an example
trackAnalyticsOnClick({
eventName: ANALYTICS_EVENT_NAMES.addExternalAccountClicked,
params: {
success: true,
},
});
Last updated
Was this helpful?