guillaumeparis2000 / react-piwik

Library that allow to connect piwik with the react-router and track custom events
31 stars 17 forks source link

Remove initial slash from current Path #6

Closed regdos closed 7 years ago

regdos commented 7 years ago

I use hashHistory in react app. The page url is https://domain.com/context/#/form?lang=en

react-piwik calculate currentPath

const currentPath = loc.path || (loc.pathname + loc.search);

for my url currentPath is /form?lang=en

Next piwik.js calculate full url after use

push(['setCustomUrl', currentPath])

in https://github.com/piwik/piwik/blob/3.x-dev/js/piwik.js#L3275 When url is absolute (first char is slash) add only schema and host

if (url.slice(0, 1) === '/') {
    return getProtocolScheme(baseUrl) + '://' + getHostName(baseUrl) + url;
}

so url reported to piwik.php is not correct https://domain.com/form?lang=en (not contain context and hash)

My change remove initial slash from currentPath so piwik.js calculates the correct url (contain context and hash)