Commit da274cf4 authored by Axel García's avatar Axel García

Parse Snowplow value as Number

Changelog: changed
parent 9e20fe77
...@@ -10,7 +10,8 @@ export function dispatchSnowplowEvent( ...@@ -10,7 +10,8 @@ export function dispatchSnowplowEvent(
throw new Error('Tracking: no category provided for tracking.'); 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 standardContext = getStandardContext({ extra });
const contexts = [standardContext]; const contexts = [standardContext];
...@@ -19,5 +20,9 @@ export function dispatchSnowplowEvent( ...@@ -19,5 +20,9 @@ export function dispatchSnowplowEvent(
contexts.push(data.context); contexts.push(data.context);
} }
if (value !== undefined) {
value = Number(value);
}
return window.snowplow('trackStructEvent', category, action, label, property, value, contexts); return window.snowplow('trackStructEvent', category, action, label, property, value, contexts);
} }
...@@ -69,7 +69,7 @@ The following example shows `data-track-*` attributes assigned to a button: ...@@ -69,7 +69,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-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-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-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-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. | | `data-track-context` | false | To append a custom context object, passed as a valid JSON string. |
......
...@@ -361,6 +361,16 @@ describe('Tracking', () => { ...@@ -361,6 +361,16 @@ describe('Tracking', () => {
expect(eventSpy).toHaveBeenCalledWith(TEST_CATEGORY, 'click_input2', { expect(eventSpy).toHaveBeenCalledWith(TEST_CATEGORY, 'click_input2', {
value: '0', value: '0',
}); });
expect(snowplowSpy).toHaveBeenCalledWith(
'trackStructEvent',
TEST_CATEGORY,
'click_input2',
undefined,
undefined,
0,
[standardContext],
);
}); });
it('handles checkbox values correctly', () => { 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