Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

* Add configuration option `forceHttps`, which when set to `true` forces the SDK to always upload to HTTPS endpoint. By default the SDK uses the endpoint that matches the embedding site's protocol (for example if your site is HTTP, it will use the HTTP endpoint).

### 3.0.2 (July 6, 2016)

* `productId` is no longer a required field for `Revenue` logged via `logRevenueV2`.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ amplitude.getInstance().init('YOUR_API_KEY_HERE', null, {
| domain | string | Custom cookie domain | The top domain of the current page's url |
| eventUploadPeriodMillis | number | Amount of time in milliseconds that the SDK waits before uploading events if `batchEvents` is `true`. | 30\*1000 (30 sec) |
| eventUploadThreshold | number | Minimum number of events to batch together per request if `batchEvents` is `true`. | 30 |
| forceHttps | boolean | If `true`, the events will always be uploaded to HTTPS endpoint. Otherwise it will use the embedding site's protocol. | `false` |
| includeReferrer | boolean | 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 set once operation. | `false` |
| includeUtm | boolean | If `true`, finds utm parameters in the query string or the __utmz cookie, parses, and includes them as user propeties on all events uploaded. Also captures initial utm parameters for each session via a set once operation. | `false` |
| language | string | Custom language to set | Language determined by browser |
Expand Down
4 changes: 3 additions & 1 deletion amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,8 @@ AmplitudeClient.prototype.sendEvents = function sendEvents(callback) {
}

this._sending = true;
var url = ('https:' === window.location.protocol ? 'https' : 'http') + '://' + this.options.apiEndpoint + '/';
var protocol = this.options.forceHttps ? 'https' : ('https:' === window.location.protocol ? 'https' : 'http');
var url = protocol + '://' + this.options.apiEndpoint + '/';

// fetch events to send
var numEvents = Math.min(this._unsentCount(), this.options.uploadBatchSize);
Expand Down Expand Up @@ -4935,6 +4936,7 @@ module.exports = {
batchEvents: false,
eventUploadThreshold: 30,
eventUploadPeriodMillis: 30 * 1000, // 30s
forceHttps: false,
};

}, {"./language":29}],
Expand Down
6 changes: 3 additions & 3 deletions amplitude.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,8 @@ AmplitudeClient.prototype.sendEvents = function sendEvents(callback) {
}

this._sending = true;
var url = ('https:' === window.location.protocol ? 'https' : 'http') + '://' + this.options.apiEndpoint + '/';
var protocol = this.options.forceHttps ? 'https' : ('https:' === window.location.protocol ? 'https' : 'http');
var url = protocol + '://' + this.options.apiEndpoint + '/';

// fetch events to send
var numEvents = Math.min(this._unsentCount(), this.options.uploadBatchSize);
Expand Down
1 change: 1 addition & 0 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ module.exports = {
batchEvents: false,
eventUploadThreshold: 30,
eventUploadPeriodMillis: 30 * 1000, // 30s
forceHttps: false,
};
18 changes: 18 additions & 0 deletions test/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,24 @@ describe('setVersionName', function() {
assert.equal(server.requests[0].async, true);
});

it('should send https request', function() {
amplitude.options.forceHttps = true;
amplitude.logEvent('Event Type 1');
assert.lengthOf(server.requests, 1);
assert.equal(server.requests[0].url, 'https://api.amplitude.com/');
assert.equal(server.requests[0].method, 'POST');
assert.equal(server.requests[0].async, true);
});

it('should send https request by configuration', function() {
amplitude.init(apiKey, null, { forceHttps: true });
amplitude.logEvent('Event Type 1');
assert.lengthOf(server.requests, 1);
assert.equal(server.requests[0].url, 'https://api.amplitude.com/');
assert.equal(server.requests[0].method, 'POST');
assert.equal(server.requests[0].async, true);
});

it('should reject empty event types', function() {
amplitude.logEvent();
assert.lengthOf(server.requests, 0);
Expand Down
18 changes: 18 additions & 0 deletions test/amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,24 @@ describe('setVersionName', function() {
assert.equal(server.requests[0].async, true);
});

it('should send https request', function() {
amplitude.options.forceHttps = true;
amplitude.logEvent('Event Type 1');
assert.lengthOf(server.requests, 1);
assert.equal(server.requests[0].url, 'https://api.amplitude.com/');
assert.equal(server.requests[0].method, 'POST');
assert.equal(server.requests[0].async, true);
});

it('should send https request by configuration', function() {
amplitude.init(apiKey, null, { forceHttps: true });
amplitude.logEvent('Event Type 1');
assert.lengthOf(server.requests, 1);
assert.equal(server.requests[0].url, 'https://api.amplitude.com/');
assert.equal(server.requests[0].method, 'POST');
assert.equal(server.requests[0].async, true);
});

it('should reject empty event types', function() {
amplitude.logEvent();
assert.lengthOf(server.requests, 0);
Expand Down