You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type =SignalType.UserDefined// Sets the signal type to User Defined.
228
+
}
229
+
```
192
230
193
231
## Example rule implementations
194
232
233
+
You can use the Signals data definitions on this page to create tracking rules.
234
+
235
+
### Example: Identify users
236
+
237
+
Building off of the screen tracking example, you could create a rule that identifies users:
238
+
239
+
```javascript
240
+
functiondetectIdentify(currentSignal) {
241
+
var loginType;
242
+
243
+
// Check if the signal is related to network activity on a login URL
244
+
if (currentSignal.type==SignalType.Network&¤tSignal.data.url.includes("login")) {
245
+
loginType ="login";
246
+
}
247
+
248
+
// If a login type was detected, identify the user
249
+
if (loginType) {
250
+
var traits =newObject();
251
+
traits.loggedIn=true; // Set user status to logged in
252
+
let loginData =currentSignal.data.data.content; // Extract login data from the signal
253
+
traits.userName=loginData.userName; // Capture the user's name
254
+
255
+
if (loginType ==="login") {
256
+
var userId =loginData.userId; // Get userID from login data
257
+
analytics.identify(userId, traits); // Identify the user with the Identify call
258
+
}
259
+
}
260
+
}
261
+
262
+
//...other functions
263
+
264
+
functionprocessSignal(signal) {
265
+
//...other functions
266
+
detectIdentify(signal); // Process the Identify call based on incoming signals
267
+
}
268
+
```
269
+
270
+
271
+
### Example: Track `Add to Cart` events
272
+
273
+
This rule shows how you could implement the core ordering events from [the e-commerce Spec](/docs/connections/spec/ecommerce/v2/#core-ordering-overview):
274
+
275
+
```javascript
276
+
functiontrackAddToCart(currentSignal) {
277
+
// Check if the signal is an interaction with the "Add To Cart" button
278
+
if (currentSignal.type==SignalType.Interaction&¤tSignal.data.title=="Add To Cart") {
279
+
var properties =newObject(); // Initialize an object to store event properties
280
+
281
+
// Find the network response signal for additional data
282
+
let network =signals.find(currentSignal, SignalType.Network, (signal) => {
0 commit comments