@movidesk/ampltiude
v1.0.0
Published
``` yarn add @movidesk/amplitude ```
Downloads
5
Keywords
Readme
Amplitude
Essa lib depende da global da movidesk window.eventTracker
e de informações do usuário encontradas nos cookies
Instalando
yarn add @movidesk/amplitude
Usando a lib
// No entry point da sua aplicação
import { AmplitudeProvider } from "@movidesk/amplitude"
render(
<AmplitudeProvider>
<MyApp>
</AmplitudeProvder>
)
// Dentro de MyApp.js
import { useAmplitude } from "@movidesk/amplitude"
function MyApp() {
const track = useAmplitude()
return (
<Button onClick={() => track("MyProduct.MyScreenOrFeature.ClickedButton")}>
Click me
</Button>
)
}
Testando
import { render, fireEvent } from "@testing-library/react"
import { AmplitudeProvider } from "@movidesk/amplitude"
import { MyApp } from "./myapp.js"
test("calls the track function when the user clicks the button", () => {
const spy = jest.fn()
const { queryByText } = render(
<AmplitudeProvider tracker={{ trackEvent: spy }}>
<MyApp/>
</AmplitudeProvider>
)
fireEvent.click(queryByText("Click me"))
expect(spy).toHaveBeenCalledWith("MyProduct.MyScreenOrFeature.ClickedButton")
})