useSuccessEventTracker

Returns a ready-to-trigger trackSuccessEvent by retrieving ReactNativeTracker instance and LocationStack automatically.

useSuccessEventTracker = (
hookParameters: {
tracker?: Tracker,
locationStack?: LocationStack,
globalContexts?: GlobalContexts
} = {}
) => (
callbackParameters: {
message: string,
tracker?: Tracker,
locationStack?: LocationStack,
globalContexts?: GlobalContexts
} = {}
) => Promise<TrackerEvent>

Parameters

The hook and callback share tracker, locationStack and globalContexts parameters.

This allows composing the Event's payload by combining parameters provided to the hook and/or the callback:

  • tracker: Custom tracker instance. By default, useTracker() is used, which can be overridden by providing this parameter to the hook, or later to the callback. If both hook and callback have tracker parameters, the callback takes precedence.

  • locationStack: The callback and hook LocationStack are merged with the result of useLocationStack(). This allows to combine the LocationStack of parent components with the virtual Locations provided to either the hook or callback, or both.

  • globalContexts: The callback and hook GlobalContexts items are simply merged together.


Hook Parameters

typedefault value
optionaltrackerReactTrackeruseTracker()
optionallocationStackLocationStackuseLocationStack()
optionalglobalContextsGlobalContexts

Callback Parameters

typedefault value
requiredmessagestring
optionaltrackerReactTracker
optionallocationStackLocationStack
optionalglobalContextsGlobalContexts

Returns

A callback with the same parameters of the hook itself and an extra message parameter.

(callbackParameters: {
message: string,
tracker?: Tracker,
locationStack?: LocationStack,
globalContexts?: GlobalContexts
} = {}) => Promise<TrackerEvent>

Usage

Scenario: form submit success
import { useSuccessEventTracker } from "@objectiv/tracker-react-native";

const trackSuccessEvent = useSuccessEventTracker();

submitFormData(formData)
.then((response) => {
if (response.ok) {
trackSuccessEvent({
message: response.statusText
});
}
});
Scenario: virtual location wrapper
import { makeContentContext } from "@objectiv/tracker-core";
import { useSuccessEventTracker } from "@objectiv/tracker-react-native";

const trackSuccessEvent = useSuccessEventTracker();

submitFormFields(formFields)
.then((response) => {
trackSuccessEvent({
locationStack: [
makeContentContext({
id: 'subscribe-view'
})
],
message: response.statusText
});
});
Scenario: additional global context representing the search term
import { makeInputValueContext } from "@objectiv/tracker-core";
import { useSuccessEventTracker } from "@objectiv/tracker-react-native";

const trackSuccessEvent = useSuccessEventTracker();

submitSearchQuery(searchQuery)
.then((queryResponse) => {
trackSuccessEvent({
globalContexts: [
makeInputValueContext({
id: 'search-term',
value: searchQuery.term
})
],
message: queryResponse.statusText
});
});
Scenario: identity context after successful login
import { makeIdentityContext } from "@objectiv/tracker-core";
import { useSuccessEventTracker } from "@objectiv/tracker-react-native";

const trackSuccessEvent = useSuccessEventTracker();

backendLogin(credentials)
.then((authResponse) => {
trackSuccessEvent({
globalContexts: [
makeIdentityContext({
id: 'backend',
value: authResponse.userId
})
],
message: authResponse.statusText
});
});