Comments (7)
Ah I see. You want to create multiple events based on information in your actions. You aren't the first to ask for this. The eventSchema
property is problematic. We added the eventSchema
property to validate events returned by eventFields
. If eventFields
is augmented to return multiple event definitions then the eventSchema
property isn't too useful unless every event has a similar shape.
I'm going to have to think on this, and maybe rethink whether or not we even need eventSchema
. I've only seen eventSchema
being used to suppress events from being pushed to a target, but that can also be achieved by returning a null from eventFields
. eventSchema
also doesn't add any value to TypeScript or Flow users.
If we were to get rid of eventSchema
an event definition could be a function instead of an object:
// Event Definition
const pageView = (action): PageView => ({
hitType: 'pageview',
page: action.payload,
});
// Event Definitions Map
const eventsMap = {
LOCATION_CHANGE: pageView,
}
And your example would look like:
dispatch(setFiltersAction({
foo: 1,
bar: 2,
xyz: 3,
}))
const filtersChange = (action) => {
const events = [];
Object.entries(action.data).forEach(([key, value]) => {
events.push({
hitType: 'event',
eventCategory: 'filters',
eventAction: 'set',
eventLabel: key,
eventValue: value,
})
});
return events;
};
const eventsMap = {
SET_FILTERS: filtersChange,
};
This could be done in a non-breaking way. That is, we could support both forms of event definitions (object and function) until we're ready to deprecate the object syntax.
Thoughts @bertrandk?
from redux-beacon.
Great! I'm not sure when I'll be able to do it (I'm now fighting with some more prioritary issues), but I'll try t do it the soonest possible.
Enjoy your traveling!
from redux-beacon.
Hi @coluccini. Great question. Yes! You can do that, sort of. You can provide an array of event definitions when mapping to an action. Here's how it would look with your example:
dispatch(setFiltersAction({
foo: 1,
bar: 2,
}));
const filter1 = {
eventFields: action => ({
hitType: 'event',
eventCategory: 'filters',
eventAction: 'set',
eventLabel: 'foo',
eventValue: action.data.foo,
});
};
const filter2 = {
eventFields: action => ({
hitType: 'event',
eventCategory: 'filters',
eventAction: 'set',
eventLabel: 'bar',
eventValue: action.data.bar,
});
};
const eventsMap = {
SET_FILTERS: [filter1, filter2],
};
https://rangle.github.io/redux-beacon/docs/api/event-definitions-map.html
from redux-beacon.
Oh, nice. But I was thinking in a more dynamic scenario. Somethings like this (asume that you don't know how many values you are changing on the dispatch):
dispatch(setFiltersAction({
foo: 1,
bar: 2,
xyz: 3,
}))
const filtersChange = {
eventFields: action => {
const events = [];
Object.entries(action.data).forEach(([key, value]) => {
events.push({
hitType: 'event',
eventCategory: 'filters',
eventAction: 'set',
eventLabel: key,
eventValue: value,
})
});
return events;
)
},
};
const eventsMap = {
SET_FILTERS: filtersChange,
};
Do you think this makes sense? If so, I can try to submit a PR with the changes
from redux-beacon.
I'm not sure if removing eventSchema is completely necessary. I mean, eventSchema is optional. So you can just use it if does make sense in each definition. But yes, if eventDefinition is a function instead of an object you can achieve what eventSchema does programmatically.
from redux-beacon.
Sorry for the late reply @coluccini, I'm doing a bit of travelling at the moment.
You're right, removing eventSchema
isn't necessary for the moment. I will accept a PR adding the functionality to return an array of events from eventFields
. Let me know if you'll have time to work on it.
If so, here's what I'm thinking will need to be changed.
- create-events.test.js
- Add a test:event definition returns an array of events
.
- Add a test:event definition returns an array of events with some failing the eventSchema
. - create-events.js
- Make the two tests pass. - event-definition.md
- Add aNotes
section and mention that you can return an array of events fromeventFields
.
from redux-beacon.
Fixed by #103
from redux-beacon.
Related Issues (20)
- Angular AOT - GA or Amplitude Targets - Uncaught TypeError: e is not a function HOT 1
- Redux Beacon Google Tag Manager docu down HOT 2
- trackException() sending incorrect fields object HOT 2
- Support for react-native-google-analytics-bridge version 6 HOT 1
- How are we meant to test this? HOT 1
- [TypeScript] Add support for typings in EventDefinition HOT 3
- Documentation request: please remove the Github Pages docs HOT 3
- Documentation Bug: Broken links on readme.md HOT 1
- How to track external link when each link has its own metadata? HOT 3
- trackEvent eventDefinition not showing the correct parameters HOT 1
- Gtag, access user-id config inside redux-beacon, React HOT 3
- [Typescript] combineEvents forces invalid type HOT 1
- Error when trying to track e-commerce items in GA following documentation HOT 1
- Update docs for usage with React Native + Segment HOT 1
- Add Matomo (formerly Piwik) support HOT 2
- Integration with Redux Dynamic Modules HOT 1
- Distribute as ES module HOT 1
- IP anonymization with Google Analytics (gtag) HOT 2
- Any Event [*] is invoked for all events even though the exact key match present HOT 1
- @amplitude/analytics-browser support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-beacon.