Skip to content

Commit 646d759

Browse files
committed
Merge pull request #1 from attribution/project-id-in-header
Encode project_id in header
2 parents f987d13 + 5308f27 commit 646d759

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var protocol = require('segmentio/protocol');
1313
var send = require('yields/send-json');
1414
var topDomain = require('top-domain');
1515
var uuid = require('uuid');
16+
var encode = require('ForbesLindesay/base64-encode');
1617

1718
/**
1819
* Cookie options
@@ -166,9 +167,20 @@ Attribution.prototype.normalize = function(msg) {
166167
*/
167168

168169
Attribution.prototype.send = function(path, msg, fn) {
169-
var projectId = this.options.project || window.Attribution.projectId;
170-
var url = scheme() + '//track.attributionapp.com' + path + "?project_id=" + projectId;
171-
var headers = { 'Content-Type': 'text/plain' };
170+
var url = scheme() + '//track.attributionapp.com' + path;
171+
172+
var username = this.options.project || window.Attribution.projectId;
173+
var password = "";
174+
var basicAuth = 'Basic ' + encode(username + ":" + password);
175+
176+
var headers = {
177+
'Content-Type': 'text/plain',
178+
'Authorization': basicAuth
179+
};
180+
181+
// No headers on JSONP so put the project_id in the msg
182+
msg.project_id = username;
183+
172184
fn = fn || noop;
173185
var self = this;
174186

0 commit comments

Comments
 (0)