Amplitude event is not added when navigating to a new URL

95 views Asked by At

I am calling amplitude.track(...) in the function handleClick that is called when the user clicks on the button. In the debugger, this function is called but I can't find my events in amplitude. I am not sure why the amplitude event is not added.

amplitude.js

import * as amplitude from '@amplitude/analytics-browser';

amplitude.init(process.env.REACT_APP_AMPLITUDE_API_KEY, {
  defaultTracking: false,
});

export default amplitude;

Component.js

  import * as React from 'react';
  import * as amplitude from '@amplitude/analytics-browser';
  import { Button } from '@mui/material';

  export const Component = () => {

    const handleClick = () => {
      amplitude.track('gotoURLClick');
      window.location.assign('https://www.google.com/');
   };

  return (
    <Button
      onClick={handleClick}
    >
      Button
    </Button>
  );
}
0

There are 0 answers