Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
196464d
Set up skeleton tracker module and implement sendSessionStart.
sblaurock Sep 23, 2019
92a1a0e
Add test for sendSessionStart.
sblaurock Sep 24, 2019
ebbac98
Provide URL creation helper method for autocomplete endpoints.
sblaurock Sep 24, 2019
0104679
Define red path tests for sendAutocompleteSelect.
sblaurock Sep 24, 2019
4d269f4
Define sendAutocompleteSearch + tests.
sblaurock Sep 24, 2019
7d39e93
Implement sendSearchResults.
sblaurock Sep 24, 2019
801f2bd
Add tests for sendSearchResults.
sblaurock Sep 25, 2019
ee12347
Tests for sendSearchResultClick.
sblaurock Sep 25, 2019
eabda65
Update sendAutocompleteSelect to use missing parameters, update tests.
sblaurock Sep 25, 2019
a48c7a9
Update tests for sendSearchSubmit.
sblaurock Sep 25, 2019
1c7b03b
Loosen restrictions on required parameters, make parameter structure …
sblaurock Sep 25, 2019
e5b9bfb
Define sendSearchResultClick behavior.
sblaurock Sep 27, 2019
cab2b7f
Add tests for sendSearchResultClick.
sblaurock Sep 27, 2019
e591d79
Defnine sendConversion + tests.
sblaurock Sep 27, 2019
63e4575
Implement sendPurchase + tests.
sblaurock Sep 27, 2019
93ac7cd
Corrections to sendPurchase tests.
sblaurock Sep 27, 2019
607c5cc
No longer return promises from tracking calls. Simplify test cases.
sblaurock Sep 27, 2019
ec32308
Set term and last used autocomplete item in browser storage.
sblaurock Sep 30, 2019
974f5c1
Add tests to ensure storage setting is being performed correctly.
sblaurock Sep 30, 2019
790551d
Tack on userId as supplied parameter to constructor, begin to refacto…
sblaurock Sep 30, 2019
3fee69a
Implement tracking request functionality inspired by `browser-trackin…
sblaurock Oct 1, 2019
65bafb3
Split requests and humanity into separate modules.
sblaurock Oct 1, 2019
334eda7
Define behavior for sendAutocompleteSelect + tests.
sblaurock Oct 1, 2019
f1e15d8
Define sendAutocompleteSearch + tests.
sblaurock Oct 1, 2019
83477ff
Update tests and define remaining methods.
sblaurock Oct 1, 2019
aafcae6
Add tests for tracker-humanity.
sblaurock Oct 1, 2019
cf45e22
Define test file for tracker-requests. Lint fixes.
sblaurock Oct 2, 2019
2f615f8
Remove storage options block and all downstream use cases.
sblaurock Oct 2, 2019
40bede6
Track isHuman in session storage + tests.
sblaurock Oct 2, 2019
135cc86
Add tests for tracker-requests.
sblaurock Oct 3, 2019
c66e0c6
Corrections to sendAutocompleteSelect + tests.
sblaurock Oct 3, 2019
61ae38e
Corrections to sendAutocompleteSearch + tests.
sblaurock Oct 3, 2019
6ff4692
Corrections for sendSearchResults + tests.
sblaurock Oct 3, 2019
b606c26
Corrections to sendSearchResultClick + tests.
sblaurock Oct 3, 2019
1773ff3
Corrections to sendConversion + tests.
sblaurock Oct 3, 2019
fed68a7
Corrections to sendPurchase + tests.
sblaurock Oct 3, 2019
937ce58
Merge remote-tracking branch 'origin/master' into feature/tracking-mo…
sblaurock Oct 4, 2019
ba4f34b
Merge remote-tracking branch 'origin/master' into feature/tracking-mo…
sblaurock Oct 4, 2019
81b7988
Use require in favor of import.
sblaurock Oct 4, 2019
32e3640
Add tests for tracker-requests send method.
sblaurock Oct 7, 2019
8ae20c1
Overflow on store2
rubikzube Oct 9, 2019
1439564
Linting error
rubikzube Oct 9, 2019
b79f974
Merge remote-tracking branch 'origin/master' into feature/tracking-mo…
sblaurock Oct 10, 2019
60c91fe
Merge branch 'feature/tracking-module' of github.com:Constructor-io/c…
sblaurock Oct 10, 2019
4d13d31
Verify parameters on first tracker test.
sblaurock Oct 12, 2019
51fefcb
Use cleanParams and append datetime parameter to search requests.
sblaurock Oct 12, 2019
2fc3a6a
Apply cleanParams to autocomplete and recommendations.
sblaurock Oct 12, 2019
dbae360
Verify outgoing query parameters via spied fetch for tracking tests.
sblaurock Oct 12, 2019
5aea236
Naming consistency tweaks.
sblaurock Oct 12, 2019
2dd281b
Reduce wait interval for request send tests.
sblaurock Oct 12, 2019
5007e2f
Support sending userId and add tests for search module.
sblaurock Oct 12, 2019
fb9cc81
Add tests to validate user id being sent with requests.
sblaurock Oct 12, 2019
4303aca
Add tests to validate user id and segments for tracking and
sblaurock Oct 12, 2019
7b5b346
Add tests to validate defaulting of section for tracking requests.
sblaurock Oct 12, 2019
7022311
Move store into folder, exclude from coverage reports.
sblaurock Oct 13, 2019
a515cf6
Update readme to document new methods.
sblaurock Oct 13, 2019
6945e21
Readme tweaks.
sblaurock Oct 13, 2019
202b79c
Pull out unrelated changes to keep branch focus targeted.
sblaurock Oct 15, 2019
6f7b0c8
Update tracking method names to more closely align with existing
sblaurock Oct 15, 2019
897a77f
Updated customer_ids test in purchase
rubikzube Oct 15, 2019
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
3 changes: 3 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"exclude": [
"src/store/*"
],
"include": [
"src/*"
],
Expand Down
91 changes: 89 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![npm](https://img.shields.io/npm/v/@constructor-io/constructorio-client-javascript)](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)
![David (path)](https://img.shields.io/david/Constructor-io/constructorio-client-javascript)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Constructor-io/constructorio-client-javascript/blob/master/LICENSE)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Constructor-io/constructorio-client-javascript/blob/master/LICENSE)

A JavaScript client for [Constructor.io](http://constructor.io/). [Constructor.io](http://constructor.io/) provides search as a service that optimizes results using artificial intelligence (including natural language processing, re-ranking to optimize for conversions, and user personalization).

Expand All @@ -26,7 +26,7 @@ var constructorio = new ConstructorIOClient({

## 4. Retrieve Results

After instantiating an instance of the client, three modules will be exposed as properties to help retrieve data from Constructor.io: `search`, `autocomplete`, and `recommendations`.
After instantiating an instance of the client, four modules will be exposed as properties to help retrieve data from Constructor.io: `search`, `autocomplete`, `recommendations` and `tracking`.

### Search

Expand Down Expand Up @@ -130,6 +130,93 @@ constructorio.recommendations.getUserFeaturedItems({ parameters }).then(function
| --- | --- | --- |
| `results` | number | Number of results to retrieve |

### Tracker

The tracker module can be used to send tracking events. Returns `true` when successful, or will throw an error if an issue is encountered.

#### Send autocomplete select event
```javascript
constructorio.tracker.trackAutocompleteSelect('dogs', {
parameters
});
```

| Parameter | Type | Description |
| --- | --- | --- |
| `original_query` | string | ? |
| `result_id` | string | ? |
| `section` | string | ? |
| `tr` | string | ? |
| `group_id` | string | ? |
| `display_name` | string | ? |

#### Send autocomplete search event
```javascript
constructorio.tracker.trackSearchSubmit('dogs', {
parameters
});
```

| Parameter | Type | Description |
| --- | --- | --- |
| `original_query` | string | ? |
| `result_id` | string | ? |
| `group_id` | string | ? |
| `display_name` | string | ? |

#### Send search results event
```javascript
constructorio.tracker.trackSearchResultsLoaded('dogs', {
parameters
});
```

| Parameter | Type | Description |
| --- | --- | --- |
| `num_results` | string | ? |
| `customer_ids` | string | ? |

#### Send search result click event
```javascript
constructorio.tracker.trackSearchResultClick('dogs', {
parameters
});
```

| Parameter | Type | Description |
| --- | --- | --- |
| `name` | string | ? |
| `customer_id` | string | ? |
| `result_id` | string | ? |

#### Send conversion event
```javascript
constructorio.tracker.trackConversion('dogs', {
parameters
});
```

| Parameter | Type | Description |
| --- | --- | --- |
| `name` | string | ? |
| `customer_id` | string | ? |
| `result_id` | string | ? |
| `revenue` | string | ? |
| `section` | string | ? |

#### Send purchase event
```javascript
constructorio.tracker.trackPurchase({
parameters
});
```

| Parameter | Type | Description |
| --- | --- | --- |
| `customer_ids` | string | ? |
| `revenue` | string | ? |
| `section` | string | ? |

## Development / npm commands

```bash
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"eslint-plugin-import": "^2.18.2",
"http-server": "^0.11.1",
"jsdoc": "^3.6.3",
"jsdom": "^15.1.1",
"minami": "^1.2.3",
"mocha": "^6.2.0",
"mocha-jsdom": "^2.0.0",
Expand All @@ -50,6 +51,7 @@
"@constructor-io/constructorio-id": "^2.1.1",
"es6-promise": "^4.2.8",
"fetch-ponyfill": "^6.1.0",
"qs": "^6.8.0"
"qs": "^6.8.0",
"store2": "^2.9.0"
}
}
55 changes: 55 additions & 0 deletions spec/mocha.helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
const qs = require('qs');
const { JSDOM } = require('jsdom');
const store = require('../src/store/store');

// Setup mock DOM environment
const setupDOM = () => {
const { window } = new JSDOM();

global.window = window;
global.document = window.document;
};

// Tear down mock DOM environment
const teardownDOM = () => {
delete global.window;
delete global.document;
};

// Trigger browser resize event
const triggerResize = () => {
const resizeEvent = document.createEvent('Event');

resizeEvent.initEvent('resize', true, true);

global.window.resizeTo = (width, height) => {
global.window.innerWidth = width || global.window.innerWidth;
global.window.innerHeight = height || global.window.innerHeight;
global.window.dispatchEvent(resizeEvent);
};

window.resizeTo(1024, 768);
};

// Trigger browser unload event
const triggerUnload = () => {
const unloadEvent = document.createEvent('Event');

unloadEvent.initEvent('beforeunload', true, true);

global.window.unload = () => {
global.window.dispatchEvent(unloadEvent);
};

window.unload();
};

// Clear local and session storage
const clearStorage = () => {
store.local.clearAll();
store.session.clearAll();
};

// Extract query parameters as object from url
const extractUrlParamsFromFetch = (fetch) => {
Expand All @@ -14,5 +64,10 @@ const extractUrlParamsFromFetch = (fetch) => {
};

module.exports = {
setupDOM,
teardownDOM,
triggerResize,
triggerUnload,
clearStorage,
extractUrlParamsFromFetch,
};
53 changes: 53 additions & 0 deletions spec/src/modules/tracker-humanity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const dotenv = require('dotenv');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const store = require('../../../src/store/store');
const trackerHumanity = require('../../../src/modules/tracker-humanity');
const helpers = require('../../mocha.helpers');

chai.use(chaiAsPromised);
dotenv.config();

describe('ConstructorIO - Tracker - Humanity', () => {
describe('isHuman', () => {
const storageKey = '_constructorio_is_human';

beforeEach(() => {
global.CLIENT_VERSION = 'cio-mocha';

helpers.setupDOM();
});

afterEach(() => {
delete global.CLIENT_VERSION;

helpers.teardownDOM();
helpers.clearStorage();
});

it('Should not have isHuman flag set on initial instantiation', () => {
const humanity = trackerHumanity();

expect(humanity.isHuman()).to.equal(false);
expect(store.session.get(storageKey)).to.equal(null);
});

it('Should have isHuman flag set if human-like actions are detected', () => {
const humanity = trackerHumanity();

expect(humanity.isHuman()).to.equal(false);
helpers.triggerResize();
expect(humanity.isHuman()).to.equal(true);
expect(store.session.get(storageKey)).to.equal(true);
});

it('Should have isHuman flag set if session variable is set', () => {
const humanity = trackerHumanity();

expect(humanity.isHuman()).to.equal(false);
store.session.set(storageKey, true);
expect(humanity.isHuman()).to.equal(true);
expect(store.session.get(storageKey)).to.equal(true);
});
});
});
Loading