Skip to content

Commit 8baf25b

Browse files
authored
initialize pendo with current user and group (#707) (#710)
1 parent a5742fc commit 8baf25b

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

integrations/pendo/HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.1.4 / 2022-11-18
2+
===================
3+
4+
* initialize pendo with current user and group
5+
16
1.1.2 / 2020-12-14
27
===================
38

integrations/pendo/lib/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,30 @@ Pendo.prototype.initialize = function() {
3737
usePendoAgentAPI: true
3838
};
3939

40+
var user = this.analytics.user();
41+
var isUserAnonymous = !user.id();
42+
var id = isUserAnonymous
43+
? pendoifyAnonymousId(user.anonymousId())
44+
: user.id();
45+
46+
var visitor = Object.assign({ id: id }, user.traits());
47+
window.pendo_options.visitor = Object.assign(
48+
visitor,
49+
window.pendo_options.visitor
50+
);
51+
52+
var group = this.analytics.group();
53+
if (group.id()) {
54+
var account = Object.assign(
55+
{ id: group.id() },
56+
group.traits()
57+
);
58+
window.pendo_options.account = Object.assign(
59+
account,
60+
window.pendo_options.account
61+
);
62+
}
63+
4064
this.load(this.ready, { apiKey: this.options.apiKey });
4165
};
4266

integrations/pendo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-pendo",
33
"description": "The Pendo analytics.js integration.",
4-
"version": "1.1.3",
4+
"version": "1.1.4",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/pendo/test/index.test.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ var tester = require('@segment/analytics.js-integration-tester');
99
describe('Pendo', function() {
1010
var analytics;
1111
var pendo;
12-
var options = {
13-
apiKey: 'test-key-for-segment-integration'
14-
};
12+
var options;
1513

1614
beforeEach(function() {
15+
options = {
16+
apiKey: 'test-key-for-segment-integration'
17+
};
1718
analytics = new Analytics();
1819
pendo = new Pendo(options);
1920

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

2627
afterEach(function() {
28+
delete window.pendo_options;
2729
analytics.restore();
2830
analytics.reset();
2931
pendo.reset();
@@ -60,9 +62,31 @@ describe('Pendo', function() {
6062
});
6163

6264
it('should create a pendo_options object using API', function() {
65+
analytics.initialize();
66+
analytics.assert.deepEqual(window.pendo_options, {
67+
apiKey: options.apiKey,
68+
usePendoAgentAPI: true,
69+
visitor: {
70+
id: '_PENDO_T_' + analytics.user().anonymousId()
71+
}
72+
});
73+
});
74+
75+
it('should create a pendo_options object for a user and group', function() {
76+
analytics.identify('user1', { foo: 'bar' });
77+
analytics.group('group1', { baz: 'quux' });
78+
analytics.initialize();
6379
analytics.assert.deepEqual(window.pendo_options, {
6480
apiKey: options.apiKey,
65-
usePendoAgentAPI: true
81+
usePendoAgentAPI: true,
82+
visitor: {
83+
id: 'user1',
84+
foo: 'bar'
85+
},
86+
account: {
87+
id: 'group1',
88+
baz: 'quux'
89+
}
6690
});
6791
});
6892
});

0 commit comments

Comments
 (0)