The reason is because the sendFormData() functions runs before the value of path is retrieved. You can try using async/ await promise to make sure that the value of the path is returned from the wixLocation.onChange event.
Also, please note that path returns just the last part of the URL. To return full URL, you better use wixLocation.url .
Should you need further assistance, please paste your code with the modifications into the thread.
Regards.