segmentio/analytics.js-core

Page overrides aren't being passed through on .track calls

Closed this issue ยท 4 comments

I have a use case for wanting to change the referrer on all calls to segment, this is due to sensitive data being in there.

So this works great on the .page call, if I supply a properties object containing some of the reserved page keywords, namely url and referrer, they get overridden, however it falls over on any other calls, namely the .track call in my case.

Looking into the code, it seems .page is unique in that it overrides options.context if there are supplied properties that fit the overrides (

var overrides = pick(keys(defs), properties);
), .track does not do this, and I was wondering if there was a reason for this?

I'm happy to do a PR if this is desired functionality, just need a thumbs up from the team. ๐Ÿ˜„

(I'm also wondering if all calls should have a way to override context?)

Hmm, it seems that you can override them by passing through { context: { page: {} } } as the options parameter to .track. Which is somewhat different to what .page does.

Happy workaround has been found ๐Ÿ’ƒ

sorry for the frustration! โ€” we'll document that. ๐Ÿ‘ฏ

Hello, I know the issue was closed but just to clarify, if I called
.track('myeventname', propertiesObject, {context: {page: {url: 'myurl', referrer: 'myreferrer' ...}}}) it should work then? I need to specify the url and path instead of track automatically setting them for me

Hello everyone,
I tried the solution described above and it didn't work.
Can somebody confirm this solution has been tested successfully?

Hmm, it seems that you can override them by passing through { context: { page: {} } } as the options parameter to .track. Which is somewhat different to what .page does.

Happy workaround has been found ๐Ÿ’ƒ