Skip to content

Commit

Permalink
initialize pendo with current user and group (#707) (#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellanoce authored Dec 6, 2022
1 parent a5742fc commit 8baf25b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
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

0 comments on commit 8baf25b

Please sign in to comment.