This is a simple Salesforce CLI project that shows how you can send events to the Segment HTTP API from within a Salesforce org.
First, get yourself a Salesforce developer account. The Salesforce CLI is going to be your next stop..
Once your development environment is configured
- git clone https://github.com/ibigfoot/salesforce-event-source.git
- cd salesforce-event-source
- sfdx force:auth:web:login -d -a
- sfdx:force:org:create -s -a -f config/project-scratch-def.json
- sfdx:force:source:push -u
Then, setup a Segment HTTP API source
Example of calling .track() using anonymous apex
SegmentTrackEvent evt = new SegmentTrackEvent();
evt.userId = '019mr8mf4r';
evt.event = 'Item Purchased';
evt.addCustomProperty('name', 'Leap to Conclusions Mat');
evt.addCustomProperty('revenue', '14.99');
SegmentContext context = new SegmentContext();
context.ip = '24.5.68.47';
evt.timestamp = DateTime.now();
SegmentUtil util = new SegmentUtil('<YOUR SEGMENT WRITE KEY');
util.track(evt);
Segment API Methods implemented:
- track()
- page()
- identify()