Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 14c590c

Browse filesBrowse files
authored
feat: add ingestion_metadata field (#552)
1 parent 35e2dd3 commit 14c590c
Copy full SHA for 14c590c

File tree

Expand file treeCollapse file tree

3 files changed

+64
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+64
-0
lines changed
Open diff view settings
Collapse file

‎src/amplitude-client.js‎

Copy file name to clipboardExpand all lines: src/amplitude-client.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,13 @@ AmplitudeClient.prototype._logEvent = function _logEvent(
14301430
};
14311431
}
14321432

1433+
if (_isIngestionMetadataSet(this)) {
1434+
event.ingestion_metadata = {
1435+
source_name: this.options.ingestionMetadata.sourceName || undefined,
1436+
source_version: this.options.ingestionMetadata.sourceVersion || undefined,
1437+
};
1438+
}
1439+
14331440
if (eventType === Constants.IDENTIFY_EVENT || eventType === Constants.GROUP_IDENTIFY_EVENT) {
14341441
this._unsentIdentifys.push({ event, callback, errorCallback });
14351442
this._limitEventsQueued(this._unsentIdentifys);
@@ -1469,6 +1476,13 @@ const _isObservePlanSet = function _isObservePlanSet(scope) {
14691476
);
14701477
};
14711478

1479+
const _isIngestionMetadataSet = function _isIngestionMetadataSet(scope) {
1480+
return (
1481+
scope.options.ingestionMetadata &&
1482+
(scope.options.ingestionMetadata.sourceName || scope.options.ingestionMetadata.sourceVersion)
1483+
);
1484+
};
1485+
14721486
var _shouldTrackField = function _shouldTrackField(scope, field) {
14731487
return !!scope.options.trackingOptions[field];
14741488
};
Collapse file

‎src/options.js‎

Copy file name to clipboardExpand all lines: src/options.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import { version as libraryVersion } from '../package.json';
2424
* @property {boolean} [includeGclid=`false`] - If `true`, captures the gclid URL parameter as well as the user's initial_gclid via a setOnce operation.
2525
* @property {boolean} [includeReferrer=`false`] - If `true`, captures the referrer and referring_domain for each session, as well as the user's initial_referrer and initial_referring_domain via a setOnce operation.
2626
* @property {boolean} [includeUtm=`false`] - If `true`, finds UTM parameters in the query string or the _utmz cookie, parses, and includes them as user properties on all events uploaded. This also captures initial UTM parameters for each session via a setOnce operation.
27+
* @property {Object} [ingestionMetadata] Ingestion metadata
28+
* @property {string} [ingestionMetadata.sourceName] source name in ingestion metadata, e.g. "ampli"
29+
* @property {string} [ingestionMetadata.sourceVersion] source version in ingestion metadata, e.g. "1.0.0"
2730
* @property {string} [language=The language determined by the browser] - Custom language to set.
2831
* @property {Object} [library=`{ name: 'amplitude-js', version: packageJsonVersion }`] - Values for the library version
2932
* @property {string} [logLevel=`WARN`] - Level of logs to be printed in the developer console. Valid values are 'DISABLE', 'ERROR', 'WARN', 'INFO'. To learn more about the different options, see below.
@@ -74,6 +77,10 @@ export default {
7477
includeGclid: false,
7578
includeReferrer: false,
7679
includeUtm: false,
80+
ingestionMetadata: {
81+
sourceName: '',
82+
sourceVersion: '',
83+
},
7784
language: language.getLanguage(),
7885
library: {
7986
name: 'amplitude-js',
Collapse file

‎test/amplitude-client.js‎

Copy file name to clipboardExpand all lines: test/amplitude-client.js
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,17 @@ describe('AmplitudeClient', function () {
908908
assert.deepEqual(amplitude.options.plan, plan);
909909
});
910910

911+
it('should set ingestion metadata options', function () {
912+
const amplitude = new AmplitudeClient('ingestion metadata');
913+
const ingestionMetadata = {
914+
sourceName: 'ampli',
915+
sourceVersion: '1.0.0',
916+
};
917+
amplitude.init(apiKey, null, { ingestionMetadata: ingestionMetadata });
918+
919+
assert.deepEqual(amplitude.options.ingestionMetadata, ingestionMetadata);
920+
});
921+
911922
it('should set sessionId from config', () => {
912923
const amplitude = new AmplitudeClient();
913924
amplitude.init(apiKey, null, { sessionId: 123 });
@@ -4572,4 +4583,36 @@ describe('AmplitudeClient', function () {
45724583
assert.equal(amplitude._unsentEvents[0].event.partner_id, null);
45734584
});
45744585
});
4586+
4587+
describe('ingestionMetadata Support', function () {
4588+
beforeEach(function () {
4589+
// reset ingestionMetadata
4590+
amplitude.options.ingestionMetadata = {
4591+
sourceName: '',
4592+
sourceVersion: '',
4593+
};
4594+
reset();
4595+
});
4596+
4597+
it('should include ingestion_metadata', function () {
4598+
const ingestionMetadata = {
4599+
sourceName: 'ampli',
4600+
sourceVersion: '1.0.0',
4601+
};
4602+
amplitude.init(apiKey, null, { batchEvents: true, ingestionMetadata: ingestionMetadata });
4603+
4604+
amplitude.logEvent('testEvent1');
4605+
assert.deepEqual(amplitude._unsentEvents[0].event.ingestion_metadata, {
4606+
source_name: 'ampli',
4607+
source_version: '1.0.0',
4608+
});
4609+
});
4610+
4611+
it('should set ingestion_metadata default null', function () {
4612+
amplitude.init(apiKey, null, { batchEvents: true });
4613+
4614+
amplitude.logEvent('testEvent1');
4615+
assert.equal(amplitude._unsentEvents[0].event.ingestion_metadata, null);
4616+
});
4617+
});
45754618
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.