@@ -14,6 +14,7 @@ var send = require('yields/send-json');
14
14
var topDomain = require ( 'top-domain' ) ;
15
15
var uuid = require ( 'uuid' ) ;
16
16
var encode = require ( 'ForbesLindesay/base64-encode' ) ;
17
+ var cors = require ( 'has-cors' ) ;
17
18
18
19
/**
19
20
* Cookie options
@@ -169,26 +170,22 @@ Attribution.prototype.normalize = function(msg) {
169
170
Attribution . prototype . send = function ( path , msg , fn ) {
170
171
var url = scheme ( ) + '//track.attributionapp.com' + path ;
171
172
172
- var username = this . options . project || window . Attribution . projectId ;
173
- var password = "" ;
174
- var basicAuth = 'Basic ' + encode ( username + ":" + password ) ;
173
+ var projectId = this . options . project || window . Attribution . projectId ;
175
174
176
- var headers = {
177
- 'Content-Type' : 'text/plain' ,
178
- 'Authorization' : basicAuth
179
- } ;
175
+ // If we're POSTing, let's send the project_id in the params
176
+ // only on POST though, or else we'll get two question marks
177
+ if ( cors )
178
+ url += "?project_id=" + projectId ;
180
179
181
- // No headers on JSONP so put the project_id in the msg
182
- msg . project_id = username ;
180
+ // If we're JSONPing, let's send it in the encoded params
181
+ msg . project_id = projectId ;
183
182
184
183
fn = fn || noop ;
185
184
var self = this ;
186
185
187
- // msg
188
186
msg = this . normalize ( msg ) ;
189
187
190
- // send
191
- send ( url , msg , headers , function ( err , res ) {
188
+ send ( url , msg , function ( err , res ) {
192
189
self . debug ( 'sent %O, received %O' , msg , arguments ) ;
193
190
if ( err ) return fn ( err ) ;
194
191
res . url = url ;
0 commit comments