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

initialize pendo with current user and group (#707) (#710) #714

Merged
merged 1 commit into from
Dec 6, 2022
Merged
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
5 changes: 5 additions & 0 deletions integrations/pendo/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.1.4 / 2022-11-18
===================

* initialize pendo with current user and group

1.1.2 / 2020-12-14
===================

Expand Down
24 changes: 24 additions & 0 deletions integrations/pendo/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ Pendo.prototype.initialize = function() {
usePendoAgentAPI: true
};

var user = this.analytics.user();
var isUserAnonymous = !user.id();
var id = isUserAnonymous
? pendoifyAnonymousId(user.anonymousId())
: user.id();

var visitor = Object.assign({ id: id }, user.traits());
window.pendo_options.visitor = Object.assign(
visitor,
window.pendo_options.visitor
);

var group = this.analytics.group();
if (group.id()) {
var account = Object.assign(
{ id: group.id() },
group.traits()
);
window.pendo_options.account = Object.assign(
account,
window.pendo_options.account
);
}

this.load(this.ready, { apiKey: this.options.apiKey });
};

Expand Down
2 changes: 1 addition & 1 deletion integrations/pendo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@segment/analytics.js-integration-pendo",
"description": "The Pendo analytics.js integration.",
"version": "1.1.3",
"version": "1.1.4",
"keywords": [
"analytics.js",
"analytics.js-integration",
Expand Down
32 changes: 28 additions & 4 deletions integrations/pendo/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ var tester = require('@segment/analytics.js-integration-tester');
describe('Pendo', function() {
var analytics;
var pendo;
var options = {
apiKey: 'test-key-for-segment-integration'
};
var options;

beforeEach(function() {
options = {
apiKey: 'test-key-for-segment-integration'
};
analytics = new Analytics();
pendo = new Pendo(options);

Expand All @@ -24,6 +25,7 @@ describe('Pendo', function() {
});

afterEach(function() {
delete window.pendo_options;
analytics.restore();
analytics.reset();
pendo.reset();
Expand Down Expand Up @@ -60,9 +62,31 @@ describe('Pendo', function() {
});

it('should create a pendo_options object using API', function() {
analytics.initialize();
analytics.assert.deepEqual(window.pendo_options, {
apiKey: options.apiKey,
usePendoAgentAPI: true,
visitor: {
id: '_PENDO_T_' + analytics.user().anonymousId()
}
});
});

it('should create a pendo_options object for a user and group', function() {
analytics.identify('user1', { foo: 'bar' });
analytics.group('group1', { baz: 'quux' });
analytics.initialize();
analytics.assert.deepEqual(window.pendo_options, {
apiKey: options.apiKey,
usePendoAgentAPI: true
usePendoAgentAPI: true,
visitor: {
id: 'user1',
foo: 'bar'
},
account: {
id: 'group1',
baz: 'quux'
}
});
});
});
Expand Down