-
Notifications
You must be signed in to change notification settings - Fork 123
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
Default dispatch function does not appear to work as expected #79
Comments
Thanks @riley -- it's possible you've found a bug. Are you able to create a failing test case and/or create a reproduction in https://codesandbox.io or similar? |
Note that your import track from 'react-tracking'
...
@track(
{},
{
process: ownTrackingData => (ownTrackingData.page ? { event: 'Pageview' } : null),
}
)
class AppWithAuth extends React.Component {}
... Note the additional parens That might be what's going on in your case, can you try that out and confirm @riley-steele-parsons ? |
@tizmagik , could you take a look at this CodeSandbox? I am now seeing data within the dataLayer property (without manually duplicating the dispatch function). However, instead of having the process function inject properties into each new track object, a single object containing the process data is added to the beginning of the dataLayer. |
Hey @riley-steele-parsons thanks for the CodeSandbox repro -- I think I see what you're saying now. However, this is actually expected behavior. The
The main use case for this is to dispatch an additional "pageview event" for Page components. Perhaps To do what I think you want to do, which is to append additional tracking data for every tracking dispatch, you would actually want to define this in a custom For example: @track(
{},
{
dispatch: d => (window.dataLayer = window.dataLayer || []).push({
...d,
time: new Date()
})
}
)
class App extends React.Component { ... } Updated codesandbox example: https://codesandbox.io/s/qqxqzqp5l6 |
I've attempted to setup a
track
decorator on a high level component which contains an option object as a second argument, like so:Based on the docs, I gathered that when a lower level
track
decorator dispatches an event, the default dispatch function pushes the event object onto thewindow.dataLayer
array which is subsequently sent to Google Analytics. I am not seeing this behavior.window.dataLayer
does not update when the event is fired.However, if I replace the
track
decorator on the high level component withI am able to see the event objects pushed onto the
window.dataLayer
array through Chrome's javascript console. I also am able to see the Pageview event on my Google Analytics dashboard.The text was updated successfully, but these errors were encountered: