Skip to content

Commit

Permalink
fix(sdk): page view event trigger (#2586)
Browse files Browse the repository at this point in the history
## What's the purpose of this pull request?

Change the moment in which the page_view event is sent. It was
previously being sent only during a page change, so it wasn't sent on
the initialization of the page.

## How it works?

Instead of watching the `routeChangeComplete` route event, now it sends
the page_view event when the page is loaded.

## How to test it?

Check on the starter preview that the store is working as expected.
The real impact of this change will be tested in the next PR, in which
the RC events will start to be sent.

### Starters Deploy Preview

https://sfj-59f6820--starter.preview.vtex.app/
([PR](vtex-sites/starter.store#631))

## References

- [GA page
view](https://developers.google.com/analytics/devguides/collection/ga4/views)
- [Jira task](https://vtex-dev.atlassian.net/browse/SFS-1798)
- [Slack
thread](https://vtex.slack.com/archives/C03L3CRCDC4/p1733837843137469)
  • Loading branch information
lariciamota authored Dec 11, 2024
1 parent 632f3d6 commit 3988760
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions packages/core/src/sdk/analytics/hooks/usePageViewEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ export const usePageViewEvent = () => {
const router = useRouter()

useEffect(() => {
router.events.on('routeChangeComplete', sendPageViewEvent)

return () => {
router.events.off('routeChangeComplete', sendPageViewEvent)
}
sendPageViewEvent()
}, [router, sendPageViewEvent])

return { sendPageViewEvent }
Expand Down

0 comments on commit 3988760

Please sign in to comment.