Artisan IMG > Segment (segment) (c31f2339-8a6c-4179-8e5c-728e81a24a5d)

Segment
1.4

Segment is an analytics API and customer data platform that allows you to easily move data between different sources and destinations.

Overview
Copy

API INFO: The Base URL used for the Segment connector is https://api.segment.io/v1/. More information can be found on their main API documentation (v1.0) site. This is where users will also be able to find the API Limitations page.

Below is an example of a way in which you could potentially use the Segment trigger to track any actions on your Source website and fire the trigger when a specified action is performed. The JSON data then received through the trigger is managed through different branches based on the event.

The Source considered in this example is a Training website that sells various training courses. We create individual branches based on the events that occur on the Training website's sales page.

Below is some sample data that comes via the source website:

1
{
2
"_metadata": {
3
"bundled": [
4
"FullStory",
5
"HubSpot",
6
"Segment.io",
7
"Visual Tagger"
8
],
9
"bundled_ids": [
10
"601xxxxxxxxxxxx8e5f7c6",
11
"6346exxxxxxxxxxxx4159409",
12
"60133xxxxxxxxxxxc82c0e"
13
],
14
"unbundled": [
15
"Amplitude",
16
"Customer.io"
17
]
18
},
19
"anonymous_id": "kwednxxx-xxx-xx-xxx-xx497nfbhd",
20
"channel": "client",
21
"context": {
22
"campaign": {
23
"content": "john-live",
24
"medium": "yt-description",
25
"name": "yesterday-live",
26
"source": "youtube"
27
},
28
"ip": "79.xx.xxx.25",
29
"library": {
30
"name": "analytics.js",
31
"version": "4.1.8"
32
},
33
"locale": "en-gb",
34
"page": {
35
"path": "/pwj",
36
"referrer": "https://youtube.com/"
37
},
38
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15"
39
},
40
"event": "Sales Page Visited",
41
"integrations": {},
42
"message_id": "ajs-78456xxxxxxxxxxxu934422",
43
"original_timestamp": "2021-05-25T08:44:37.279Z",
44
"project_id": "q2dfhexxxxxxxkdspofk",
45
"properties": {
46
"course_name": "JS",
47
"currency": "USD",
48
"utm_campaign": "yesterday-live",
49
"utm_source": "youtube",
50
"value": 420
51
},
52
"received_at": "2021-05-25T08:44:38.777Z",
53
"sent_at": "2021-05-25T08:44:37.280Z",
54
"timestamp": "2021-05-25T08:44:38.776Z",
55
"type": "track",
56
"user_id": null,
57
"version": 2
58
}

The following workflow gives an example of how you can achieve this:

EXTRA AUTHS: In order to complete this workflow, you will also need to be authenticated with the Google Sheets connector.

1 - Setup Segment Trigger & the branches
Copy

Select the Segment trigger from the trigger options available and set the operation to 'On page track'.

There are various operations that the Segment trigger facilitates, and you can choose any based on your needs. To know more about the Segment Trigger, you can refer to the Trigger Setup section above

Add a Branch connector to your workflow. Then, using the connector-snake, find the jsonpath for the 'Value To Test' field from the trigger. It should appear similar to this: $.steps.trigger.event.

JSONPATHS: For more information on what jsonpaths are and how to use jsonpaths with Tray, please see our pages on Basic data concepts and Mapping data between steps

CONNECTOR-SNAKE: The simplest and easiest way to generate your jsonpaths is to use our feature called the Connector-snake. Please see the main page for more details.

The next step is to name the branches. These names depend entirely on the events that you wish to track and take necessary actions accordingly.

In this example, the considered events are Sales Page Visited, Checkout Started, and Order Completed. Thus the three branches. The last branch is a Default branch, which is auto-created and manages all the other events except the ones specified above.

Feel free to re-name your steps as you go along to make things clearer for yourself and other users. However, the operation names themselves often suffice.

Once we have set up the trigger and the Branch connector, the workflow will listen to any page view events on our source website, and then based on the current event type, the respective branches will take specific actions.

2 - Create event-based branches
Copy

As the next steps, the workflow will execute based on the events specified in the Branch step:

Branch-1: Sales Page Visited

On the Sales Page Visited event, as a first step the Segment connector is identifying the Sales page visitor.

Based on the output of the initial step, i.e., Successful or Unsuccessful, the Boolean Condition connector is checking if the visitor is known?

If the visitor is known, then no action is needed, and thus the workflow terminates.

If the visitor is unknown, then the Segment connector using the Get Profile Traits (Alpha) operation is identifying the traits of the visitor based on the 'anonymous_id'. Traits are pieces of information you know about a user.

In the end, the newly gathered traits are stored in a third-party service. In this case, we are using google sheets as a generic placeholder for any service or database you may wish to use.

Branch-2: Checkout Started

On the Checkout Started event, as a first step, the Segment connector is identifying the traits of the visitor as we did in the previous step.

As a next step, the Segment connector is identifying the traits of the visitor using an email address.

The second check is precautionary and optional.

As the email address field is not mandatory, there are chances that the value for the email field may not be available. In such a situation, the workflow will prompt an error and stop the further execution as it is its default mechanism.

To handle this situation, we are using the Manual Error handling mechanism. To select Manual Error handling for the Personas Get Traits (email) step in the properties panel, click 'Handle errors' and set the error handling to 'Manual'.

This error handling method gives you two branches:

  • Success: This means the email is available, and the step could return visitor traits using the email address. Then we merge the traits from both the steps, i.e., Personas Get Traits and Personas Get Traits (email) using an Object Helpers, and store this merged info in a Google Sheet.

  • Error: This means the email address is not available, then we are storing the data only from the Personas Get Traits step into the excel sheet.

Branch-3: Order Completed

The Order Completed branch sends a message on the selected Slack channel notifying that a specific order is completed.

This Notification can be further used in various ways based on your requirements.

Again as we did in the previous two branches, as a first step, the Segment connector is identifying the traits of the visitor.

Using this traits information a Slack message would be sent on the selected channel.

BEST PRACTICES: Whenever you do decide to create your own workflow, be sure to check out some of our key articles such as: