LinkContextWrapper
Wraps its children in a LinkContext.
Children can be a ReactNode or a Render Props function receiving TrackingContext.
LinkContextWrapper: (props: {
children: ReactNode | ((parameters: TrackingContext) => ReactNode),
id: string,
href: string,
}) => ReactElement
Parameters
type | ||
---|---|---|
required | children | ReactNode | ((parameters: TrackingContext) => ReactNode) |
required | id | string |
required | href | string |
Returns
ReactElement
Usage example
Enrich Locations
import { LinkContextWrapper } from '@objectiv/tracker-react';
const href = '/privacy';
<LinkContextWrapper id={'privacy'} href={href}>
<a href={href}>Privacy</a>
</LinkContextWrapper>
Tracking via Render Props
import {
LinkContextWrapper,
trackPressEvent
} from '@objectiv/tracker-react';
const href = '/privacy';
<LinkContextWrapper id={'privacy'} href={href}>
{(trackingContext) => (
<a
href={href}
onClick={() => trackPressEvent(trackingContext)}
>
Privacy
</a>
)}
</LinkContextWrapper>
info
The above is just an example to illustrate the Render Props functionality.
Check out our Tracked Elements for a ready-to-use TrackedAnchor component.
Did you know ?
LinkContextWrapper
internally uses LocationContextWrapper.