Skip to content

Instantly share code, notes, and snippets.

@brennan
Forked from sperand-io/instructions.md
Created December 10, 2015 23:13
Show Gist options
  • Save brennan/3efdc6f076433edd22e9 to your computer and use it in GitHub Desktop.
Save brennan/3efdc6f076433edd22e9 to your computer and use it in GitHub Desktop.
What Is Segment Sending on My Behalf?

If you have node installed, you can clone the repo for whichever integration you'd like to use (say GA) then install segmentio-facade:

git clone https://github.com/segmentio/integration-google-analytics.git
cd integration-google-analytics
npm install segmentio-facade

Then create a new file in the top level of the directory with the script from this gist.

curl https://gist.githubusercontent.com/sperand-io/32cff1a9003d117c6fae/raw/a5932c51b68258475a0823db46b483cc7bbf1166/runner.js > runner.js

Follow the instructions in that script's comments to supply the call and settings from your project you'd like to simulate.

Finally, set your DEBUG env var and run that script.

DEBUG=* node runner

Boom, you'll get output showing the mapped request body and the endpoint(s) we're sending to.

/**
* Module dependencies
*/
var Integration = require('./lib');
var facade = require('segmentio-facade');
/**
* Your settings for the integration.
*/
var settings = /* paste the result of running the function below */
/**
* Go to your integrations page in chrome and run this in the console:
copy(segment.projectIntegrations.filter(function(obj) {
return obj.type === "<< ENTER INTEGRATION NAME HERE (Title Case)>>"
? true
: false;
})[0].settings
);
*/
/**
* Your event/identify/page etc.
* Copy directly from the debugger raw view!
*/
var event = /* example: {
"anonymousId": "32f28484-6c2d-4898-8e90-639aad371119",
"context": {
"library": {
"name": "analytics.js",
"version": "2.10.0"
},
"page": {
"path": "/simulator/",
"referrer": "",
"search": "",
"title": "Simulator - Segment",
"url": "https://tools.segment.io/simulator/"
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36",
"ip": "50.255.55.145"
},
"integrations": {
"Salesforce": true
},
"messageId": "c82f26af-66da-46ff-bd4e-c807291ad69f",
"receivedAt": "2015-07-28T19:36:19.245Z",
"sentAt": "2015-07-28T19:36:19.207Z",
"timestamp": "2015-07-28T19:36:19.239Z",
"traits": {
"Test_Field__c": "Gin & Juice",
"company": "Death Row",
"email": "snoop@dogg.com",
"name": "Snoop Dogg",
"phone": "270-33-4150",
"rating": 5,
"state": "California"
},
"type": "identify",
"userId": "UOENO123",
"originalTimestamp": "2015-07-28T19:36:19.201Z"
}; */
var Facades = {
track: facade.Track,
identify: facade.Identify,
alias: facade.Alias,
group: facade.Group,
page: facade.Page,
screen: facade.Screen
};
var message = new Facades[message.type](event);
var err = Integration.validate(message, settings);
if (err) return console.log(err);
var instance = new Integration(settings);
instance[message.type()](message, function(err, res){
if (err) return console.log('error: %s', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment