|
2 | 2 | title: Attach custom properties to custom events |
3 | 3 | --- |
4 | 4 |
|
5 | | -import useBaseUrl from '@docusaurus/useBaseUrl'; |
| 5 | +## Send custom properties with custom events |
6 | 6 |
|
7 | | -## Tag properties to custom events you want to track |
| 7 | +When you track a custom event, you can include property key-value pairs alongside it. This lets you capture additional context about the event, for example which pricing plan a visitor selected when clicking a sign-up button, or which content variation they were shown. |
8 | 8 |
|
9 | | -Let's say you have a contact form both in the header and footer of your site. In addition to tracking submissions, you might want to know which section of your site the form was submitted on. Instead of creating separate goals for each form, you can send a custom property instead. |
| 9 | +### Using HTML class attributes |
10 | 10 |
|
11 | | -Similarly to how you define an event name inside the `class` attribute, you can use the format `plausible-event-<property>=<value>` to define custom properties. Following the same example, your code might look something like this: |
| 11 | +If you're using Plausible's class-based event tracking, add properties using the format `plausible-event-<property>=<value>` on the same element: |
12 | 12 |
|
13 | 13 | ```html |
14 | | -<body> |
15 | | - <!-- header --> |
16 | | - <form class="plausible-event-name=Form+Submit plausible-event-position=header">...</form> |
17 | | - |
18 | | - <!-- footer --> |
19 | | - <form class="plausible-event-name=Form+Submit plausible-event-position=footer">...</form> |
20 | | -</body> |
| 14 | +<button class="plausible-event-name=Sign+Up plausible-event-plan=starter">...</button> |
| 15 | +<button class="plausible-event-name=Sign+Up plausible-event-plan=pro">...</button> |
21 | 16 | ``` |
22 | 17 |
|
23 | | -Now, both form submissions would trigger the same `Form Submit` event, but the `position` property will be different. |
| 18 | +Both buttons trigger the same `Sign Up` event, but the `plan` property will differ between them. |
24 | 19 |
|
25 | | -:::tip To represent a space character in property values, you can use a `+` sign |
26 | | -This is because you can't include the space character in the `class` attribute |
| 20 | +:::tip |
| 21 | +To represent a space in a property value, use a `+` sign. Space characters are not valid in class attributes. |
27 | 22 | ::: |
28 | 23 |
|
29 | | -You can add up to 30 classes for custom properties. Simply separate them with a space character like in the above example. |
| 24 | +You can add up to 30 properties per event by separating each class with a space. |
30 | 25 |
|
31 | | -:::note |
32 | | -If you don't see a `plausible.init` call in your snippet, [upgrade your script](/script-update-guide) |
33 | | -::: |
| 26 | +## Using the JavaScript method |
34 | 27 |
|
35 | | -## Using custom properties in goals and funnels |
| 28 | +If you're triggering events manually with JavaScript, pass properties as a second argument: |
36 | 29 |
|
37 | | -When [creating a goal from a custom event](goal-conversions.md), you can attach up to three custom properties to that goal. |
| 30 | +```js |
| 31 | +plausible('Sign Up', {props: {plan: 'pro', variation: 'homepage-cta'}}) |
| 32 | +``` |
38 | 33 |
|
39 | | -This allows you to define more precise goals. For example, you can create a single goal for `Form Submit` and limit it to specific property values such as `position=header` or `method=HTTP`. |
| 34 | +--- |
40 | 35 |
|
41 | | -Goals with custom properties can also be [used inside funnels](funnel-analysis.md). This makes it possible to build funnels that track specific variations of the same event, such as different form locations, buttons or interaction types. |
| 36 | +## Create property-filtered goals |
42 | 37 |
|
43 | | -<details> |
| 38 | +When you [create a goal from a custom event](goal-conversions.md) in your site settings, you can optionally attach up to three property constraints to that goal definition. |
44 | 39 |
|
45 | | -<summary> |
| 40 | +A property-filtered goal only counts an event when both the event name and the property values match. For example, you can create a `Pro Sign Up` goal that only fires when a `Sign Up` event includes `plan=pro`. A separate `Starter Sign Up` goal would match `plan=starter`. |
46 | 41 |
|
47 | | -## Tag custom properties using the manual method |
| 42 | +This is distinct from simply sending properties with your events: |
48 | 43 |
|
49 | | -</summary> |
| 44 | +- **Sending a property with an event** records raw data. You can filter and analyze it in the dashboard after the fact. |
| 45 | +- **Attaching a property to a goal** makes the property part of the goal's definition. The goal only counts when that specific property value is present. It becomes a discrete conversion metric, not a filtered view of existing data. |
50 | 46 |
|
51 | | -This is an alternative option for those who are sending custom events manually with JavaScript, for example: |
| 47 | +--- |
52 | 48 |
|
53 | | -```js |
54 | | -plausible('Download') |
55 | | -``` |
| 49 | +## Use property-filtered goals in funnels |
56 | 50 |
|
57 | | -All you have to do is add the second argument to this function call with the custom properties as follows: |
| 51 | +Funnels in Plausible are built from goals, not raw events. Each funnel step must map to a defined goal. |
58 | 52 |
|
59 | | -```js |
60 | | -plausible('Download', {props: {method: 'HTTP', position: 'footer'}}) |
61 | | -``` |
| 53 | +If you want a funnel step to represent a specific variation of an event rather than all instances of it, you need a goal with the property constraint built in. |
| 54 | + |
| 55 | +For example, a funnel that tracks: |
| 56 | + |
| 57 | +1. Visitor views the pricing page |
| 58 | +2. Visitor clicks the Pro plan sign-up button |
| 59 | +3. Visitor completes registration |
| 60 | + |
| 61 | +Step 2 requires a goal that matches only `Sign Up` events where `plan=pro`. Without the property constraint on the goal, that step would count any sign-up button click on the site regardless of which plan was selected. |
62 | 62 |
|
63 | | -</details> |
| 63 | +Once you've created property-filtered goals, you can [add them as funnel steps](funnel-analysis.md) the same way as any other goal. |
0 commit comments