Skip to content

Example: Segment

Richard Cowin edited this page Nov 28, 2023 · 3 revisions

Key Concepts

Example

For the Segment example, we use a macro to capture the details of setting up the monitoring of Segment's track event.

The macro definition is as follows:

      "defmacros": {
            "segment": {
                "comment": "Segment integration",
                "poll": {
                    "duration": 1000
                },
                "source": "on-async",
                "key": "window.analytics",
                "on": "track",
                "action": "event",
                "extract": {
                    "expression": "params:at(0)"
                }
            }
        },

The macro will extract the event name of Segment and allow it to be used in when conditionals or to be used in a bind statement.

After this macro has been setup, it can be used as follows:

    "macro": "segment",
    "apply": [
        {
            "when": "AddedToCart",
            "extract": {
                "expression": "params:at(1).itemName"
            }
            "apply": [
                {"tag": "addedToCart.itemName", "action": "bind"},
                {"when": "sofa", "tag": "addedToCart.sofa", "action": "event"}
            ]
        }
    ]
}

In this example the first when will match on Segment event AddedToCart and extract the propery named itemName.

It will then produce the following two metrics:

  • bind the value of itemName to audience attribute addedToCart.itemName
  • when the itemName matches on sofa it will create an evolv event called addedToCart.sofa