Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect url in Piwik when use hashHistory from react-router #39

Closed
regdos opened this issue Jul 17, 2017 · 6 comments
Closed

Incorrect url in Piwik when use hashHistory from react-router #39

regdos opened this issue Jul 17, 2017 · 6 comments

Comments

@regdos
Copy link

regdos commented Jul 17, 2017

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 as
currentPath = urljoin(loc.pathname, loc.search) and for my url currentPath is /form?lang=en

Piwik 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

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

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?

@joernroeder
Copy link
Owner

have you seen and applied the post in the piwik faq? https://piwik.org/faq/how-to/faq_188/

@regdos
Copy link
Author

regdos commented Jul 18, 2017

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)

@joernroeder
Copy link
Owner

joernroeder commented Jul 19, 2017

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

@joernroeder
Copy link
Owner

@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.

@joernroeder
Copy link
Owner

@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

@LiuuY
Copy link

LiuuY commented Oct 18, 2017

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;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants