Skip to content

Commit

Permalink
ONL-4822 (#28)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jmesao authored Sep 8, 2020
1 parent 0a6a11e commit b059243
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 52 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:<br>- `trackOnGoogleAnalytics` (Boolean): Indicates if the task need to be tracked on Google Analytics<br>- `trackOnIntercom` (Boolean): Indicates if the task need to be tracked on Intercom<br>- `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:<br>- `label`: Label of the task (by default is the task name)<br>- `category`: Name of the category of the task<br>- `value`: Value of the action done to the object<br>- `parentTask` (Object): Huha parent task. Use it to link child tasks to a parent task via the execId<br>- `execId` (String): Identifier to link events to tasks <br>- `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:<br>- `object`: Name of the object that is being manipulated during the event<br>- `action`: Name of the action that is being executed in the object during the event<br>- `section`: Name of the the section og this event, so it can be grouped as categories<br>- `value`: Value of the action done to the object<br>- `eventGroup`: Identifier of the group this event is linked to<br>- `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:<br>- `object`: Name of the object that is being manipulated during the event<br>- `action`: Name of the action that is being executed in the object during the event<br>- `category`: Name of the the section og this event, so it can be grouped as categories<br>- `value`: Value of the action done to the object<br>- `eventGroup`: Identifier of the group this event is linked to<br>- `task`: Task associated to the event

(*) The event is tracked in Google Analytics or Segment based on the `Huha` options.

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
63 changes: 32 additions & 31 deletions src/huha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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,
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -491,3 +490,5 @@ class Huha {
}

module.exports = Huha;
module.exports.HuhaTask = HuhaTask;
module.exports.HuhaEvent = HuhaEvent;
41 changes: 23 additions & 18 deletions src/huha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,55 +250,60 @@ 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);
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).toBeNull();
expect(event.eventGroup).toBe('id-1');
});

it('should create an event with a task associated', () => {
const huha = new Huha();

const taskProperties = {
name: 'mockTask-1',
category: 'mockCategory',
value: 'mockValue',
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');
Expand Down

0 comments on commit b059243

Please sign in to comment.