I want to propose several changes to the analytics library for the release of the v1 version.
Implementation proposal for v1
Remove send
from action names
Rename actions.analytics.sendPageview()
and actions.analytics.sendEvent()
to just actions.analytics.pageview()
and actions.analytics.event()
.
Rename page
argument to link
The page
is not consistent with the rest of Frontity. We should rename it to link
:
actions.analytics.pageview({
link: "/current-url",
title: "The current title"
});
Refactor event
to use a payload
Events with action
, label
and category
are not used anywhere but in Google Analytics so we should get rid of that and move to the standard event name + payload:
actions.analytics.event({
name: "Some event",
payload: {
someProp: "Some payload"
}
};
Replace namespaces
array by two objects
Right now, the analytics libraries use an array called state.analytics.namespaces
where they can register themselves to be used by the actions.analytics.pageview
and actions.analytics.event
actions.
The problem with arrays is that they cannot be changed from the state
because arrays are merged together. There is no way for a user to deactivate one of the analytics implementation using frontity.settings.js
.
We should change that array for two objects, one for pageviews
and another for events
.
export default {
state: {
analytics: {
pageviews: {},
events: {}
}
}
};
Each analytics package can register itself like this:
export default {
state: {
analytics: {
pageviews: {
googleAnalytics: true
},
events: {
googleAnalytics: true
}
}
},
actions: {
googleAnalytics: {
pageview: () => {
/* ... */
},
event: () => {
/* ... */
}
}
}
};
That way, if a user wants to turn one implementation off, they can do so in their frontity.settings.js
file:
const settings = {
packages: [
{
name: "@frontity/google-analytics",
state: {
events: {
googleAnalytics: false
}
}
}
]
};
In the future, this object structure could be used to add options or priorities to each action (if that ever makes sense).
Issues
- Remove send from action names
- Rename page argument to link
- Refactor event to use a payload
- Replace namespaces array by two objects