Commit 7bf002e9 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch...

Merge branch '346998-check-that-value-is-a-decimal-value-for-snowplow-events-on-frontent' into 'master'

Parse`value` as a numeric value for Snowplow events on frontend

See merge request gitlab-org/gitlab!81928
parents c33668ee da274cf4
......@@ -10,7 +10,8 @@ export function dispatchSnowplowEvent(
throw new Error('Tracking: no category provided for tracking.');
}
const { label, property, value, extra = {} } = data;
const { label, property, extra = {} } = data;
let { value } = data;
const standardContext = getStandardContext({ extra });
const contexts = [standardContext];
......@@ -19,5 +20,9 @@ export function dispatchSnowplowEvent(
contexts.push(data.context);
}
if (value !== undefined) {
value = Number(value);
}
return window.snowplow('trackStructEvent', category, action, label, property, value, contexts);
}
......@@ -66,7 +66,7 @@ The following example shows `data-track-*` attributes assigned to a button:
| `data-track-action` | true | Action the user is taking. Clicks must be prepended with `click` and activations must be prepended with `activate`. For example, focusing a form field is `activate_form_input` and clicking a button is `click_button`. Replaces `data-track-event`, which was [deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/290962) in GitLab 13.11. |
| `data-track-label` | false | The specific element or object to act on. This can be: the label of the element, for example, a tab labeled 'Create from template' for `create_from_template`; a unique identifier if no text is available, for example, `groups_dropdown_close` for closing the Groups dropdown in the top bar; or the name or title attribute of a record being created. |
| `data-track-property` | false | Any additional property of the element, or object being acted on. |
| `data-track-value` | false | Describes a numeric value (decimal) directly related to the event. This could be the value of an input. For example, `10` when clicking `internal` visibility. If omitted, this is the element's `value` property or `undefined`. For checkboxes, the default value is the element's checked attribute or `0` when unchecked. |
| `data-track-value` | false | Describes a numeric value (decimal) directly related to the event. This could be the value of an input. For example, `10` when clicking `internal` visibility. If omitted, this is the element's `value` property or `undefined`. For checkboxes, the default value is the element's checked attribute or `0` when unchecked. The value is parsed as numeric before sendind the event. |
| `data-track-extra` | false | A key-value pair object passed as a valid JSON string. This attribute is added to the `extra` property in our [`gitlab_standard`](schemas.md#gitlab_standard) schema. |
| `data-track-context` | false | To append a custom context object, passed as a valid JSON string. |
......
......@@ -378,6 +378,16 @@ describe('Tracking', () => {
expect(eventSpy).toHaveBeenCalledWith(TEST_CATEGORY, 'click_input2', {
value: '0',
});
expect(snowplowSpy).toHaveBeenCalledWith(
'trackStructEvent',
TEST_CATEGORY,
'click_input2',
undefined,
undefined,
0,
[standardContext],
);
});
it('handles checkbox values correctly', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment