From b059243bbe94506a65ac252aaf484e6c717ed877 Mon Sep 17 00:00:00 2001
From: Javier Mesa <31845091+jmesao@users.noreply.github.com>
Date: Tue, 8 Sep 2020 11:09:06 +0200
Subject: [PATCH] ONL-4822 (#28)
* ONL-4822 feat: Rename section to category and pass an object with the props to create an event
* ONL-4822 feat: Update unit tests
* ONL-4822 feat: Export huha classes
* ONL-4822 feat: Update readme and changelog
* ONL-4822 feat: Upgrade version
* ONL-4822 feat: Remove line break
---
CHANGELOG.md | 10 ++++++++
README.md | 2 +-
package-lock.json | 2 +-
package.json | 2 +-
src/huha.js | 63 ++++++++++++++++++++++++-----------------------
src/huha.spec.js | 41 ++++++++++++++++--------------
6 files changed, 68 insertions(+), 52 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 78d12a3..73102bc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [3.0.0] - 2020-09-04
+### BREAKING CHANGES
+- It is necessary pass an object to create an event.
+
+### Added
+- Export HuhaTask and HuhaEvent classes.
+
+### Changed
+- Renamed `section` to `category` for events.
+
## [2.0.2] - 2020-03-13
### Fixes
- Fix to mute error 'invalid operand to in' on IE11.
diff --git a/README.md b/README.md
index 76ef2ed..815261a 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,7 @@ Method | Description |
`constructor(options)` | Instantiates a new `Huha` class with the given `options`. The `options` argument is an object containing the configuration of the class. Options available are:
- `trackOnGoogleAnalytics` (Boolean): Indicates if the task need to be tracked on Google Analytics
- `trackOnIntercom` (Boolean): Indicates if the task need to be tracked on Intercom
- `trackOnSegment` (Boolean): Indicates if the task need to be tracked on Segment
`createTask({ name: 'TaskName' })` | Creates and returns a `HuhaTask` class. The `properties` argument is an object containing the given `name` and the other fields are used for providing extra context:
- `label`: Label of the task (by default is the task name)
- `category`: Name of the category of the task
- `value`: Value of the action done to the object
- `parentTask` (Object): Huha parent task. Use it to link child tasks to a parent task via the execId
- `execId` (String): Identifier to link events to tasks
- `persistent` (Boolean): Indicates if the task should be persisted. If the task is persisted, it will be saved on localStorage and you will need to abandon it manually.
`getTask(name)` | Gets an in progress task giving its `name`
-`createEvent(name, object, action, section, value, task, eventGroup)` | Creates, tracks (*) and returns a `HuhaEvent` class with the given `name`. The other params are used for providing extra context:
- `object`: Name of the object that is being manipulated during the event
- `action`: Name of the action that is being executed in the object during the event
- `section`: Name of the the section og this event, so it can be grouped as categories
- `value`: Value of the action done to the object
- `eventGroup`: Identifier of the group this event is linked to
- `task`: Task associated to the event
+`createEvent({ name: 'EventName' })` | Creates, tracks (*) and returns a `HuhaEvent` class with the given `name`. The `properties` argument is an object containing the given `name` and the other fields are used for providing extra context:
- `object`: Name of the object that is being manipulated during the event
- `action`: Name of the action that is being executed in the object during the event
- `category`: Name of the the section og this event, so it can be grouped as categories
- `value`: Value of the action done to the object
- `eventGroup`: Identifier of the group this event is linked to
- `task`: Task associated to the event
(*) The event is tracked in Google Analytics or Segment based on the `Huha` options.
diff --git a/package-lock.json b/package-lock.json
index 93f8eb4..8e6048e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "@ebury/huha",
- "version": "2.0.2",
+ "version": "3.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index f2068c6..5dd1c37 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "@ebury/huha",
"description": "huha.js (Hyperactive Users Hint Analysis) is a JavaScript framework that measures the usability and user experience in an automated way, including the limitations of the model and the best practices.",
- "version": "2.0.2",
+ "version": "3.0.0",
"repository": "github:Ebury/huha",
"license": "MIT",
"scripts": {
diff --git a/src/huha.js b/src/huha.js
index fa56dfc..f026f61 100644
--- a/src/huha.js
+++ b/src/huha.js
@@ -234,30 +234,29 @@ class HuhaTask {
class HuhaEvent {
/**
* Constructor of the HuhaEvent
- * @param name {string} Name of the event
- * @param object {string} Name of the object that is being manipulated during the event
- * @param action {string} Name of the action that is being executed in the object during the
- * event
- * @param section {string} Name of the the section og this event, so it can be grouped as
- * categories
- * @param value {string} Value of the action done to the object
- * @param task {string|HuhaTask} Task associated to the event
- * @param eventGroup {string} Identifier of the group this event is linked to
+ * @param props of the event {object} contain the next fields:
+ * - name {string} Name of the event
+ * - object {string} Name of the object that is being manipulated during the event
+ * - action {string} Name of the action that is being executed in the object during the event
+ * - category {string} Name of the the section of this event, so it can be grouped as categories
+ * - value {string} Value of the action done to the object
+ * - task {string|HuhaTask} Task associated to the event
+ * - eventGroup {string} Identifier of the group this event is linked to
* @param options {object} Object containing the configuration of the class. Options available
* are:
* - trackOnGoogleAnalytics (Boolean): Indicates if the task needs to be tracked on Google
* Analytics
* - trackOnSegment (Boolean): Indicates if the task needs to be tracked on Segment
*/
- constructor(name, object, action, section, value, task, eventGroup, options) {
- this.name = name;
- this.object = object;
- this.action = action;
- this.section = section;
- this.value = value;
- this.task = task;
- if (eventGroup) {
- this.eventGroup = eventGroup;
+ constructor(props, options) {
+ this.name = props.name;
+ this.object = props.object;
+ this.action = props.action;
+ this.category = props.category;
+ this.value = props.value;
+ this.task = props.task;
+ if (props.eventGroup) {
+ this.eventGroup = props.eventGroup;
} else if (this.task && this.task.execId) {
this.eventGroup = this.task.execId;
} else {
@@ -287,12 +286,12 @@ class HuhaEvent {
sendToGoogleAnalytics() {
if (typeof gtag !== 'undefined') {
gtag('event', this.action, {
- event_category: this.section,
+ event_category: this.category,
event_label: this.object,
value: this.value,
});
} else if (typeof ga !== 'undefined') {
- ga('send', 'event', this.section, this.action, this.object, this.value);
+ ga('send', 'event', this.category, this.action, this.object, this.value);
}
}
@@ -302,7 +301,7 @@ class HuhaEvent {
sendToSegment() {
if (typeof analytics !== 'undefined') {
analytics.track(this.name, {
- category: this.section,
+ category: this.category,
label: this.object,
action: this.action,
value: this.value,
@@ -376,18 +375,18 @@ class Huha {
/**
* Creates, tracks and returns a event with the given data
- * @param name {string} Name of the event.
- * @param object {string} Name of the object that is being manipulated during the event
- * @param action {string} Name of the action that is being executed in the object during the event
- * @param section {string} Name of the the section og this event, so it can be grouped as
- * categories
- * @param value {string} Value of the action done to the object
- * @param task {string|HuhaTask} Task associated to the event
- * @param eventGroup {string} Identifier of the group this event is linked to
+ * @param properties of the event {object} contain the next fields:
+ * - name {string} Name of the event
+ * - object {string} Name of the object that is being manipulated during the event
+ * - action {string} Name of the action that is being executed in the object during the event
+ * - category {string} Name of the the section of this event, so it can be grouped as categories
+ * - value {string} Value of the action done to the object
+ * - task {string|HuhaTask} Task associated to the event
+ * - eventGroup {string} Identifier of the group this event is linked to
* @returns {HuhaEvent}
*/
- createEvent(name, object, action, section, value, task, eventGroup) {
- const huhaEvent = new HuhaEvent(name, object, action, section, value, task, eventGroup, {
+ createEvent(properties) {
+ const huhaEvent = new HuhaEvent(properties, {
trackOnGoogleAnalytics: this.trackOnGoogleAnalytics,
trackOnSegment: this.trackOnSegment,
});
@@ -491,3 +490,5 @@ class Huha {
}
module.exports = Huha;
+module.exports.HuhaTask = HuhaTask;
+module.exports.HuhaEvent = HuhaEvent;
diff --git a/src/huha.spec.js b/src/huha.spec.js
index 5b72882..f0ba856 100644
--- a/src/huha.spec.js
+++ b/src/huha.spec.js
@@ -250,18 +250,20 @@ describe('Huha', () => {
it('should create an event with the parameters defined', () => {
const huha = new Huha();
+ const eventProperties = {
+ name: 'mockEvent',
+ object: 'mockObject',
+ action: 'mockAction',
+ category: 'mockCategory',
+ value: 'mockValue',
+ task: null,
+ eventGroup: 'id-1',
+ };
+
// Check the number of the events
expect(huha.events.length).toBe(0);
- const event = huha.createEvent(
- 'mockEvent',
- 'mockObject',
- 'mockAction',
- 'mockSection',
- 'mockValue',
- null,
- 'id-1',
- );
+ const event = huha.createEvent(eventProperties);
// Checking results
expect(huha.events.length).toBe(1);
@@ -269,7 +271,7 @@ describe('Huha', () => {
expect(event.name).toBe('mockEvent');
expect(event.object).toBe('mockObject');
expect(event.action).toBe('mockAction');
- expect(event.section).toBe('mockSection');
+ expect(event.category).toBe('mockCategory');
expect(event.value).toBe('mockValue');
expect(event.task).toBeNull();
expect(event.eventGroup).toBe('id-1');
@@ -277,6 +279,7 @@ describe('Huha', () => {
it('should create an event with a task associated', () => {
const huha = new Huha();
+
const taskProperties = {
name: 'mockTask-1',
category: 'mockCategory',
@@ -284,21 +287,23 @@ describe('Huha', () => {
execId: 'id-1',
};
const task = huha.createTask(taskProperties);
- const event = huha.createEvent(
- 'mockEvent',
- 'mockObject',
- 'mockAction',
- 'mockSection',
- 'mockValue',
+
+ const eventProperties = {
+ name: 'mockEvent',
+ object: 'mockObject',
+ action: 'mockAction',
+ category: 'mockCategory',
+ value: 'mockValue',
task,
- );
+ };
+ const event = huha.createEvent(eventProperties);
// Checking results
expect(event).toBeDefined();
expect(event.name).toBe('mockEvent');
expect(event.object).toBe('mockObject');
expect(event.action).toBe('mockAction');
- expect(event.section).toBe('mockSection');
+ expect(event.category).toBe('mockCategory');
expect(event.value).toBe('mockValue');
expect(event.task).toBeDefined();
expect(task.execId).toBe('id-1');