Skip to content

Commit a582549

Browse files
authored
Merge pull request #166 from segmentio/gps/amplitude
[DEST-852] Amplitude: Add mapping of non-property fields to event_props
2 parents abd371d + cf5bcb0 commit a582549

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

integrations/amplitude/HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 3.1.0 / 2019-08-09
2+
3+
- Add mapping of non-property fields to event_props.
4+
15
# 3.0.0 / 2019-06-10
26

37
- Update Amplitude SDK to v5.2.2

integrations/amplitude/lib/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var Amplitude = (module.exports = integration('Amplitude')
4949
.option('preferAnonymousIdForDeviceId', false)
5050
.option('traitsToSetOnce', [])
5151
.option('traitsToIncrement', [])
52+
.option('appendFieldsToEventProps', {})
5253
.tag('<script src="' + src + '">'));
5354

5455
/**
@@ -253,6 +254,11 @@ function logEvent(track, dontSetRevenue) {
253254
window.amplitude.getInstance().setUserProperties(params);
254255
}
255256

257+
// Append extra fields to event_props
258+
each(function(prop, field) {
259+
props[prop] = track.proxy(field);
260+
}, this.options.appendFieldsToEventProps);
261+
256262
// track the event
257263
if (options.groups) {
258264
window.amplitude

integrations/amplitude/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-amplitude",
33
"description": "The Amplitude analytics.js integration.",
4-
"version": "3.0.1",
4+
"version": "3.1.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/amplitude/test/index.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ describe('Amplitude', function() {
6464
.option('traitsToSetOnce', [])
6565
.option('traitsToIncrement', [])
6666
.option('deviceIdFromUrlParam', false)
67+
.option('appendFieldsToEventProps', {})
6768
);
6869
});
6970

@@ -633,6 +634,18 @@ describe('Amplitude', function() {
633634
analytics.page();
634635
analytics.called(window.amplitude.getInstance().setDeviceId, 'example');
635636
});
637+
638+
it('should send an event with context properties mapped', function() {
639+
amplitude.options.appendFieldsToEventProps = {
640+
'context.page.path': 'pagePath'
641+
};
642+
643+
analytics.track('event', { foo: 'bar' });
644+
analytics.called(window.amplitude.getInstance().logEvent, 'event', {
645+
foo: 'bar',
646+
pagePath: '/context.html'
647+
});
648+
});
636649
});
637650

638651
describe('#orderCompleted', function() {

0 commit comments

Comments
 (0)