Skip to content

Commit 2271166

Browse files
author
Lluis Fons
committed
feat(DIST-401): Add tracking parameters
1 parent 168ac79 commit 2271166

File tree

7 files changed

+86
-33
lines changed

7 files changed

+86
-33
lines changed

demo/widget-api.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
hideFooter: true,
4343
hideHeaders: true,
4444
disableSubmit: true,
45+
source: 'example.com',
46+
medium: 'embed-sdk',
47+
mediumVersion: '0.29.1',
48+
embedTrigger_type: 'on_page_load',
4549
onSubmit: function () {
4650
alert('my-embedded-typeform-1 has been submitted')
4751
}

src/core/attributes.js

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,43 @@ const getDataset = element => {
3535
return data
3636
}
3737

38-
const sanitizePopupAttributes = data => {
38+
const sanitizeCommonAttributes = data => {
3939
const obj = {}
4040

41+
if (data.hideHeaders === '' || data.hideHeaders === 'true') {
42+
obj.hideHeaders = true
43+
}
44+
45+
if (data.hideFooter === '' || data.hideFooter === 'true') {
46+
obj.hideFooter = true
47+
}
48+
49+
if (data.hideScrollbars === '' || data.hideScrollbars === 'true') {
50+
obj.hideScrollbars = true
51+
}
52+
53+
if (data.source) {
54+
obj.source = data.source
55+
}
56+
57+
if (data.medium) {
58+
obj.medium = data.medium
59+
}
60+
61+
if (data.mediumVersion) {
62+
obj.mediumVersion = data.mediumVersion
63+
}
64+
65+
if (data.embedTriggerType) {
66+
obj.embedTriggerType = data.embedTriggerType
67+
}
68+
69+
return obj
70+
}
71+
72+
const sanitizePopupAttributes = data => {
73+
const obj = sanitizeCommonAttributes(data)
74+
4175
if (data.mode) {
4276
obj.mode = transformLegacyDataMode(data.mode)
4377
}
@@ -52,18 +86,6 @@ const sanitizePopupAttributes = data => {
5286
obj.autoOpen = true
5387
}
5488

55-
if (data.hideHeaders === '' || data.hideHeaders === 'true') {
56-
obj.hideHeaders = true
57-
}
58-
59-
if (data.hideFooter === '' || data.hideFooter === 'true') {
60-
obj.hideFooter = true
61-
}
62-
63-
if (data.hideScrollbars === '' || data.hideScrollbars === 'true') {
64-
obj.hideScrollbars = true
65-
}
66-
6789
if (data.open) {
6890
obj.open = data.open
6991
obj.openValue = data.openValue
@@ -89,19 +111,7 @@ const sanitizePopupAttributes = data => {
89111
}
90112

91113
const sanitizeWidgetAttributes = data => {
92-
const obj = {}
93-
94-
if (data.hideHeaders === '' || data.hideHeaders === 'true') {
95-
obj.hideHeaders = true
96-
}
97-
98-
if (data.hideFooter === '' || data.hideFooter === 'true') {
99-
obj.hideFooter = true
100-
}
101-
102-
if (data.hideScrollbars === '' || data.hideScrollbars === 'true') {
103-
obj.hideScrollbars = true
104-
}
114+
const obj = sanitizeCommonAttributes(data)
105115

106116
const transparency = parseInt(data.transparency, 10)
107117
if (data.transparency && transparency >= 0 && transparency <= 100) {

src/core/attributes.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ describe('Attributes', () => {
1717
popupMockElem.setAttribute('data-hide-footer', false)
1818
popupMockElem.setAttribute('data-invalid-attribute', true)
1919
popupMockElem.setAttribute('data-size', '15')
20+
popupMockElem.setAttribute('data-source', 'example.com')
21+
popupMockElem.setAttribute('data-medium', 'embed-snippet')
22+
popupMockElem.setAttribute('data-medium-version', '0.29.1')
23+
popupMockElem.setAttribute('data-embed-trigger-type', 'on_page_load')
2024

2125
const popupOptions = {
2226
mode: 'popup',
@@ -25,7 +29,11 @@ describe('Attributes', () => {
2529
open: 'scroll',
2630
openValue: '20',
2731
hideHeaders: true,
28-
size: 15
32+
size: 15,
33+
source: 'example.com',
34+
medium: 'embed-snippet',
35+
mediumVersion: '0.29.1',
36+
embedTriggerType: 'on_page_load'
2937
}
3038

3139
expect(sanitizePopupAttributes(getDataset(popupMockElem))).toEqual(popupOptions)

src/core/make-popup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const buildOptions = (embedId, options) => {
4646
embedType: POPUP_MODES[options.mode] || POPUP_MODES[POPUP],
4747
isModalOpen: false,
4848
autoClose: DEFAULT_AUTOCLOSE_TIMEOUT,
49+
medium: 'embed-sdk',
4950
hideFooter: false,
5051
hideHeaders: false,
5152
hideScrollbars: false,
@@ -64,6 +65,10 @@ const buildOptions = (embedId, options) => {
6465

6566
const queryStringKeys = {
6667
embedType: 'typeform-embed',
68+
source: 'typeform-source',
69+
medium: 'typeform-medium',
70+
mediumVersion: 'typeform-medium-version',
71+
embedTriggerType: 'typeform-embed-trigger-type',
6772
hideFooter: 'embed-hide-footer',
6873
hideHeaders: 'embed-hide-headers',
6974
disableTracking: 'disable-tracking'

src/core/make-popup.spec.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,34 @@ const instantiatePopup = (options) => {
2929
}
3030

3131
const renderPopupComponent = (autoOpen = false) => {
32-
const options = { hola: true, open: autoOpen ? 'load' : null }
32+
const options = {
33+
hola: true,
34+
open: autoOpen ? 'load' : null,
35+
source: 'example.com',
36+
medium: 'embed-snippet',
37+
mediumVersion: '0.29.1',
38+
embedTriggerType: 'on_page_load'
39+
}
3340

3441
const popup = instantiatePopup(options)
3542
if (!autoOpen) popup.open()
3643
const component = renderMock.mock.calls[0][0]
3744

3845
expect(renderMock).toHaveBeenCalledTimes(1)
3946
expect(component.type.name).toEqual('Popup')
40-
expect(component.props.url).toEqual(`${URL}?typeform-embed=popup-blank`)
47+
expect(component.props.url).toEqual(`${URL}?typeform-embed=popup-blank&typeform-source=example.com&typeform-medium=embed-snippet&typeform-medium-version=0.29.1&typeform-embed-trigger-type=on_page_load`)
4148
expect(component.props.options).toEqual(expect.objectContaining(options))
4249
}
4350

4451
const renderMobileModalComponent = (autoOpen = false) => {
4552
const spy = jest.fn()
46-
const options = { uid: UID, buttonText: 'hola', open: autoOpen ? 'load' : null, onSubmit: spy }
53+
const options = {
54+
uid: UID,
55+
buttonText: 'hola',
56+
open: autoOpen ? 'load' : null,
57+
onSubmit: spy,
58+
source: 'my-website.com'
59+
}
4760

4861
isMobileMock.mockImplementation(() => true)
4962
renderMock.mockClear()
@@ -54,7 +67,7 @@ const renderMobileModalComponent = (autoOpen = false) => {
5467

5568
expect(renderMock).toHaveBeenCalledTimes(1)
5669
expect(component.type.name).toEqual('MobileModal')
57-
expect(component.props.url).toEqual(`${URL}?typeform-embed=popup-blank`)
70+
expect(component.props.url).toEqual(`${URL}?typeform-embed=popup-blank&typeform-source=my-website.com&typeform-medium=embed-sdk`)
5871
expect(component.props.buttonText).toEqual(options.buttonText)
5972

6073
component.props.onSubmit()

src/core/make-widget.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const defaultOptions = {
2121
mode: 'embed-widget',
2222
hideFooter: false,
2323
hideHeaders: false,
24+
medium: 'embed-sdk',
2425
hideScrollbars: false,
2526
disableTracking: false,
2627
transferableUrlParameters: [],
@@ -30,6 +31,10 @@ const defaultOptions = {
3031

3132
const queryStringKeys = {
3233
mode: 'typeform-embed',
34+
source: 'typeform-source',
35+
medium: 'typeform-medium',
36+
mediumVersion: 'typeform-medium-version',
37+
embedTriggerType: 'typeform-embed-trigger-type',
3338
hideFooter: 'embed-hide-footer',
3439
hideHeaders: 'embed-hide-headers',
3540
opacity: 'embed-opacity',

src/core/make-widget.spec.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ randomString.mockImplementation(() => EMBED_ID)
2020
describe('makeWidget', () => {
2121
it('renders a Widget component on desktop devices', () => {
2222
const element = document.createElement('div')
23-
const options = { opacity: 5, mandarina: 2 }
23+
const options = {
24+
opacity: 5,
25+
mandarina: 2,
26+
source: 'website.com',
27+
medium: 'embed-wordpress',
28+
mediumVersion: '9999'
29+
}
2430

2531
isMobileMock.mockImplementationOnce(() => false)
2632
renderMock.mockClear()
@@ -35,7 +41,9 @@ describe('makeWidget', () => {
3541
const { query } = UrlParse(widgetURL, true)
3642
expect(query['embed-opacity']).toEqual('5')
3743
expect(query['mandarina']).toBeUndefined()
38-
44+
expect(query['typeform-source']).toEqual('website.com')
45+
expect(query['typeform-medium']).toEqual('embed-wordpress')
46+
expect(query['typeform-medium-version']).toEqual('9999')
3947
expect(component.type.name).toEqual('Widget')
4048
expect(component.props.options).toEqual(expect.objectContaining(options))
4149
})

0 commit comments

Comments
 (0)