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

Add optional actions parameter for validating action names. #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions packages/analytics-plugin-event-validation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,20 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.1.2](https://github.com/DavidWells/analytics/compare/analytics-plugin-event-validation@[email protected]) (2020-12-23)

**Note:** Version bump only for package analytics-plugin-event-validation

## [0.2.0](https://github.com/DavidWells/analytics/compare/analytics-plugin-event-validation@[email protected]) (2022-08-30)

Added optional actions parameter for validating action names.

## [0.1.2](https://github.com/DavidWells/analytics/compare/analytics-plugin-event-validation@[email protected]) (2020-12-23)

**Note:** Version bump only for package analytics-plugin-event-validation

## [0.1.1](https://github.com/DavidWells/analytics/compare/analytics-plugin-event-validation@[email protected]) (2019-08-26)

**Note:** Version bump only for package analytics-plugin-event-validation





# 0.1.0 (2019-08-26)


### Features

* **event-validation:** add event validation plugin ([6896561](https://github.com/DavidWells/analytics/commit/6896561))
6 changes: 6 additions & 0 deletions packages/analytics-plugin-event-validation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ const analytics = Analytics({
'sites', // example app:sites_cdConfigured
'user', // example app:user_signup
'widget' // example app:widget_created
],
// Allowed actions (optional)
actions: [
'cdConfigured', // example app:sites_cdConfigured
'signup', // example app:user_signup
'created' // example app:widget_created
]
}),
customerIOPlugin({
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics-plugin-event-validation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "analytics-plugin-event-validation",
"version": "0.1.2",
"version": "0.2.0",
"description": "Event validation plugin for analytics",
"keywords": [
"analytics",
Expand Down
12 changes: 10 additions & 2 deletions packages/analytics-plugin-event-validation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const defaultConfig = {
* @link https://getanalytics.io/plugins/event-validation/
* @param {object} pluginConfig - Plugin settings
* @param {string} pluginConfig.context - Name of app event is in. Example 'api', 'app', 'site', 'cli'
* @param {boolean} pluginConfig.objects - Objects events can effect
* @param {boolean} [pluginConfig.throwOnInvalid] - Objects events can effect
* @param {string[]} pluginConfig.objects - Objects events can affect
* @param {string[]} [pluginConfig.actions] - Name of event action (clicked, viewed, created, etc)
* @param {boolean} [pluginConfig.throwOnInvalid] - Throw error if validation fails
* @return {object} Analytics plugin
* @example
*
Expand Down Expand Up @@ -40,6 +41,7 @@ export default function eventValidationPlugin(pluginConfig = {}) {
function isValidEventName(event, config) {
const validProject = [config.context] || []
const validObjects = config.objects || []
const validActions = config.actions || []
const invalid = formatError(event)
const underscoreCount = contains(event, '_')
if (underscoreCount !== 1) {
Expand Down Expand Up @@ -67,6 +69,12 @@ function isValidEventName(event, config) {
if (validObjects.indexOf(object) === -1) {
return invalid(`Invalid object "${object}". Must be 1 of ${JSON.stringify(validObjects)}`)
}
/* Validate action */
if (validActions.length) {
if (validActions.indexOf(action) === -1) {
return invalid(`Invalid action "${action}". Must be 1 of ${JSON.stringify(validActions)}`)
}
}
return true
}

Expand Down
6 changes: 6 additions & 0 deletions site/main/source/plugins/event-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ const analytics = Analytics({
'sites', // example app:sites_cdConfigured
'user', // example app:user_signup
'widget' // example app:widget_created
],
// Allowed actions (optional)
actions: [
'cdConfigured', // example app:sites_cdConfigured
'signup', // example app:user_signup
'created', // example app:widget_created
]
}),
customerIOPlugin({
Expand Down