Skip to content

Commit 8e85c38

Browse files
committed
Update wording and add exposures through segment docs
1 parent 301e348 commit 8e85c38

File tree

1 file changed

+88
-2
lines changed
  • src/connections/destinations/catalog/actions-absmartly

1 file changed

+88
-2
lines changed

src/connections/destinations/catalog/actions-absmartly/index.md

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ This destination is maintained by ABsmartly. For any issues with the destination
2020
3. Add the following Connection Settings:
2121
- **Collector Endpoint**: Your ABsmartly Collector REST Endpoint. Usually `https://<your-subdomain>.absmartly.io/v1`
2222
- **API Key**: An existing API Key. Created under Settings->API Keys in the ABsmartly Web Console.
23-
- **Environment**: The environment where the events are originated matching an existing environment in ABsmartly. Created under Settings->Environments in the ABsmartly Web Console.
23+
- **Environment**: The environment where the events are originated matching an existing environment in ABsmartly. Created under Settings->Environments in the ABsmartly Web Console.
24+
5. Enable the _Track Calls_ mapping to send events to ABsmartly.
2425

2526
{% include components/actions-fields.html %}
2627

@@ -34,7 +35,7 @@ other destinations. The Segment spec includes the [Experiment Viewed semantic ev
3435
for this purpose.
3536

3637
> info ""
37-
> By default, the _Track Calls_ action will filter and not send to ABsmartly events with name `Experiment Viewed`.
38+
> By default, the _Track Calls_ mapping will filter and not send to ABsmartly events with name `Experiment Viewed`.
3839
3940
In the ABsmartly context, we can [install a custom event logger](https://docs.absmartly.com/docs/sdk%20documentation/getting-started/#using-a-custom-event-logger) and send exposures directly to Segment.
4041

@@ -75,6 +76,91 @@ analytics.ready(function() {
7576
});
7677
```
7778

79+
### Publishing experiment exposures through Segment
80+
81+
To publish experiment exposures through Segment, you must first configure
82+
and enable the _Exposures (Verbatim)_ mapping on your ABsmartly (Actions) destination.
83+
84+
We want to replace the direct flow of exposure events from the ABsmartly SDK to the ABsmartly collector, by instead sending them to Segment
85+
for processing by the destination function.
86+
87+
This can be achieved by instantiating the ABsmartly SDK with a custom context publisher.
88+
89+
The custom publisher will publish an `Experiment Viewed` Segment event with ABsmartly's exposure data in the `properties.exposure` field as well
90+
as the normal semantic data that Segment recommends for this event.
91+
92+
Here is an example in Javascript.
93+
94+
```javascript
95+
analytics.ready(function() {
96+
// initialize ABSmartly SDK
97+
const sdk = new absmartly.SDK({
98+
endpoint: 'https://your-absmartly-endpoint.absmartly.io/v1',
99+
apiKey: '<YOUR-API-KEY>',
100+
environment: 'development',
101+
application: 'YOUR-APP',
102+
});
103+
104+
// ABSmartly publisher implementation that publishes ABSmartly exposures to Segment,
105+
// instead of directly to the ABSmartly Collector
106+
// these will then be pushed by the ABSmartly segment integration to the ABSmartly collector
107+
class SegmentContextPublisher extends absmartly.ContextPublisher {
108+
constructor(segment) {
109+
super();
110+
111+
this._segment = segment;
112+
}
113+
114+
publish(request, sdk, context) {
115+
// NOTE: only exposures are expected to come via this route
116+
// other types of events should be tracked through the Segment API
117+
if (request.exposures) {
118+
for (const exposure of request.exposures) {
119+
this._segment.track(`Experiment Viewed`, {
120+
experiment_id: exposure.id,
121+
experiment_name: exposure.name,
122+
variation_id: exposure.variant,
123+
variation_name: "ABCDEFG"[exposure.variant],
124+
exposure: Object.assign({},
125+
{
126+
exposures: [exposure],
127+
},
128+
// add anything else in the a/b smartly payload that are not exposures or goals
129+
...Object.entries(request)
130+
.filter(e => (e[0] !== 'exposures') && (e[0] !== 'goals'))
131+
.map(e => ({[e[0]]: e[1]}))
132+
)
133+
});
134+
}
135+
}
136+
137+
return Promise.resolve();
138+
}
139+
}
140+
141+
// set this as the default publisher - all contexts created from now on will use it by default
142+
sdk.setContextPublisher(new SegmentContextPublisher(analytics));
143+
144+
const request = {
145+
units: {
146+
userId: analytics.user().id(),
147+
anonymousId: analytics.user().anonymousId(),
148+
},
149+
};
150+
151+
window.context = sdk.createContext(request);
152+
context.attribute("user_agent", navigator.userAgent);
153+
154+
context.ready().then((response) => {
155+
console.log("ABSmartly Context ready!");
156+
console.log(context.treatment("test-exp"));
157+
}).catch((error) => {
158+
console.log(error);
159+
});
160+
});
161+
```
162+
163+
78164
## Migration from the classic A/B Smartly destination
79165

80166
To migrate from the classic A/B Smartly destination to ABsmartly (Actions) be sure to disconnect the classic A/B Smartly destination before enabling the ABsmartly (Actions) destination to avoid duplicate experimentation events in ABsmartly.

0 commit comments

Comments
 (0)