Closed regdos closed 7 years ago
have you seen and applied the post in the piwik faq? https://piwik.org/faq/how-to/faq_188/
Yes, but this is not my case because url sended to piwik not contain hash.
After analyze code and testing when i add remove initial slash
currentPath = currentPath.replace(/^\//, '');
before line https://github.com/joernroeder/piwik-react-router/blob/master/index.js#L58 url send to piwik is correct (contain context and hash)
if i understand you right, your main problem is the loos of the context
path. is that correct?
You could add the basename
(in your case context
) to the history object to prefix the app path.
If all the URLs in your app are relative to some other "base" URL, use the basename option. This option transparently adds the given string to the front of all URLs you use.
https://github.com/ReactTraining/history#using-a-base-url
Alternatively you could proxy the history.listen
callback and pass down your modified path via loc.path
to set the currentPath
via https://github.com/joernroeder/piwik-react-router/blob/master/index.js#L51
hope that helps!
cheers jörn
@regdos after thinking about the proxy/modifier today i found other use cases to modify the location (e.g. to add campain parameters or state from outside react). I've ended up adding the functionality of History Modifiers directly into .connectToHistory
. Please head over to the docs to see if it works well for you. I am excited about your feedback.
@regdos could you resolve the issue? I'm closing this issue for now as the possibility to manipulate the current location before it gets passed to the tracker exists in the module since this version (v0.9.0
).
Thanks for opening this issue as it leaded to a new useful feature of this module and feel free to reopen it if you need any help. cheers
Come across the same problem, as @joernroeder said, I just pass a modifier to .connectToHistory
:
const modifier = function (location) {
const loc = window.location;
location.path = `${loc.origin}${loc.pathname}${loc.hash}`;
return location;
};
Page url address - https://domain.com/context/#/form?lang=en
In Piwik url register as https://domain.com/form?lang=en
I use hashHistory from react-router in my app. piwik-react-router send
push(['setCustomUrl', currentPath])
, currentPath is calculate ascurrentPath = urljoin(loc.pathname, loc.search)
and for my url currentPath is /form?lang=enPiwik calculate url https://github.com/piwik/piwik/blob/3.x-dev/js/piwik.js#L3275 and when url is absolute add only schema and host
and i get my incorrect url https://domain.com/form?lang=en
Solving the problem would be for example remove initial slash depending on the parameter.
What do You think about it?