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 visitor support #970

Merged
merged 3 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions global_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// "useJWT": true, // Whether or not to enable JWT. If true, the apiKey will be hidden from the build output and the token must be specified through manual initialization.
"sessionTrackingEnabled": true, // Whether or not session tracking is enabled for all pages
"analyticsEventsEnabled": true, // Whether or not to submit user interaction analytics events
// "visitor": { // Information about the visitor interacting with the experience
nmanu1 marked this conversation as resolved.
Show resolved Hide resolved
// "id": "<ID_HERE>", // The ID associated with the visitor
// "idMethod": "<ID_METHOD_HERE>" // The method used to generate the visitor ID (e.g. 'YEXT_USER for Yext Auth')
// },
"logo": "", // The link to the logo for open graph meta tag - og:image.
"favicon": "",
"googleTagManagerName": "dataLayer", // The name of your Google Tag Manager data layer
Expand Down
4 changes: 3 additions & 1 deletion static/js/answers-experience.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import DeferredPromise from './deferred-promise';
import analyticsListener from './runtime-config-listeners/analytics';
import sessionTrackingListener from './runtime-config-listeners/session-tracking';
import querySourceListener from './runtime-config-listeners/query-source';
import visitorListener from './runtime-config-listeners/visitor';

/**
* @typedef {import('./runtime-config.js').RuntimeConfigListener} RuntimeConfigListener
Expand All @@ -14,7 +15,8 @@ export default class AnswersExperience {
this._runtimeConfigListeners = [
analyticsListener,
sessionTrackingListener,
querySourceListener
querySourceListener,
visitorListener
];

this._registerRuntimeConfigListeners();
Expand Down
10 changes: 10 additions & 0 deletions static/js/runtime-config-listeners/visitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @type {import('../runtime-config.js').RuntimeConfigListener}
*/
export default {
key: 'visitor',
callback: value => {
// console.error('called');
nmanu1 marked this conversation as resolved.
Show resolved Hide resolved
ANSWERS.setVisitor(value);
}
}
4 changes: 4 additions & 0 deletions test-site/config/global_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// "useJWT": true, // Whether or not to enable JWT. If true, the apiKey will be hidden from the build and the token must be specified through the runtime config.
"sessionTrackingEnabled": true, // Whether or not session tracking is enabled for all pages
"analyticsEventsEnabled": true, // Whether or not to submit user interaction analytics events
// "visitor": { // Information about the user interacting with the experience
// "id": "<ID_HERE>", // The ID associated with the user
// "idMethod": "<ID_METHOD_HERE>" // The method used to generate the visitor ID (e.g. 'YEXT_USER for Yext Auth')
// },
"logo": "", // The link to the logo for open graph meta tag - og:image.
"favicon": "",
"googleTagManagerName": "dataLayer", // The name of your Google Tag Manager data layer
Expand Down
12 changes: 12 additions & 0 deletions tests/static/js/answers-experience.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import AnswersExperience from '../../../static/js/answers-experience';
import RuntimeConfig from '../../../static/js/runtime-config';

describe('AnswersExperience works properly', () => {
it('visitor listener is called when visitor is set', () => {
const runtimeConfig = new RuntimeConfig();
const experience = new AnswersExperience(runtimeConfig);
const callListenerSpy = jest.spyOn(experience.runtimeConfig, '_callKeySpecificListeners');
experience.runtimeConfig.set('visitor', { id: '123', idMethod: 'test' });
expect(callListenerSpy).toHaveBeenCalledWith('update', 'visitor');
});
});