@dpgradio/creative 5.8.1 → 5.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package-lock.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dpgradio/creative",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.2",
|
|
4
4
|
"description": "Support package for standalone Javascript applications",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"sockjs-client": "^1.6.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
+
"@babel/preset-env": "^7.22.9",
|
|
31
32
|
"@dpgradio/eslint-config-recommended": "^0.0.1",
|
|
32
33
|
"eslint": "^8.32.0",
|
|
33
34
|
"eslint-plugin-import": "^2.27.5",
|
|
@@ -2,7 +2,7 @@ import { describe, expect, test, jest } from '@jest/globals'
|
|
|
2
2
|
import hybrid from '../../app/hybrid.js'
|
|
3
3
|
import openLink from '../../utils/openLink.js'
|
|
4
4
|
|
|
5
|
-
jest.mock('../../
|
|
5
|
+
jest.mock('../../app/hybrid.js', () => ({
|
|
6
6
|
isNativeApp: jest.fn(),
|
|
7
7
|
call: jest.fn(),
|
|
8
8
|
}))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, test, jest } from '@jest/globals'
|
|
2
|
+
import { removePhoneNumberCountryPrefix } from '../../index.js'
|
|
3
|
+
|
|
4
|
+
describe('removing explicitly given prefixes', () => {
|
|
5
|
+
test('it removes the country prefix when there is a match', () => {
|
|
6
|
+
const result = removePhoneNumberCountryPrefix('+31.634542211', '+31')
|
|
7
|
+
|
|
8
|
+
expect(result).toBe('0634542211')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('it does not remove the country prefix when there is no match, but it does remove the .', () => {
|
|
12
|
+
const result = removePhoneNumberCountryPrefix('+33.634542211', '+31')
|
|
13
|
+
|
|
14
|
+
expect(result).toBe('+33634542211')
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
jest.mock('../../config/config.js', () => ({
|
|
19
|
+
config: jest.fn(() => 'NL'),
|
|
20
|
+
}))
|
|
21
|
+
|
|
22
|
+
describe('removing prefixes provided by the config', () => {
|
|
23
|
+
test('it removes the country prefix when there is a match', () => {
|
|
24
|
+
const result = removePhoneNumberCountryPrefix('+31.634542211')
|
|
25
|
+
|
|
26
|
+
expect(result).toBe('0634542211')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('it does not remove the country prefix when there is no match, but it does remove the .', () => {
|
|
30
|
+
const result = removePhoneNumberCountryPrefix('+32.634542211')
|
|
31
|
+
|
|
32
|
+
expect(result).toBe('+32634542211')
|
|
33
|
+
})
|
|
34
|
+
})
|
package/src/index.js
CHANGED
|
@@ -13,3 +13,4 @@ export { default as loadScript } from './utils/loadScript.js'
|
|
|
13
13
|
export { default as openLink } from './utils/openLink.js'
|
|
14
14
|
export { default as tap } from './utils/tap.js'
|
|
15
15
|
export { cdnImageUrl, cdnUrl } from './utils/cdnUrl.js'
|
|
16
|
+
export { removePhoneNumberCountryPrefix } from './utils/phoneNumber.js'
|
package/src/privacy/dataLayer.js
CHANGED
|
@@ -5,6 +5,8 @@ import loadScript from '../utils/loadScript.js'
|
|
|
5
5
|
class DataLayer {
|
|
6
6
|
constructor() {
|
|
7
7
|
window.dataLayer = window.dataLayer || []
|
|
8
|
+
this.campaignDetails = {}
|
|
9
|
+
this.userInformation = {}
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
initialize(gtmId = 'GTM-TW99VZN') {
|
|
@@ -12,6 +14,14 @@ class DataLayer {
|
|
|
12
14
|
|
|
13
15
|
this.pushGtmStart()
|
|
14
16
|
this.pushUserWhenAuthenticated()
|
|
17
|
+
this._getUserInformationOnLoad()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
setCampaignDetails(details) {
|
|
21
|
+
this.campaignDetails = {
|
|
22
|
+
inApp: hybrid.isNativeApp,
|
|
23
|
+
...details,
|
|
24
|
+
}
|
|
15
25
|
}
|
|
16
26
|
|
|
17
27
|
push(data) {
|
|
@@ -26,16 +36,29 @@ class DataLayer {
|
|
|
26
36
|
this.push({ event, ...data })
|
|
27
37
|
}
|
|
28
38
|
|
|
39
|
+
async pushCampaignAction(action, data) {
|
|
40
|
+
this.push({
|
|
41
|
+
event: 'campaign_action',
|
|
42
|
+
campaign: {
|
|
43
|
+
...this.campaignDetails,
|
|
44
|
+
action,
|
|
45
|
+
...data,
|
|
46
|
+
},
|
|
47
|
+
...this.userInformation,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
29
51
|
pushUserWhenAuthenticated() {
|
|
30
52
|
hybrid.on('authenticated', ({ radioToken }) => {
|
|
31
53
|
if (radioToken) {
|
|
32
|
-
this.
|
|
54
|
+
this.setUserInformation(radioToken)
|
|
55
|
+
this.pushEvent('account_id', this.userInformation)
|
|
33
56
|
}
|
|
34
57
|
})
|
|
35
58
|
}
|
|
36
59
|
|
|
37
60
|
async pushVirtualPageView(brand = config('gtm_brand')) {
|
|
38
|
-
|
|
61
|
+
await this._getUserInformationOnLoad()
|
|
39
62
|
|
|
40
63
|
this.pushEvent('VirtualPageView', {
|
|
41
64
|
virtualPageURL: {
|
|
@@ -43,29 +66,25 @@ class DataLayer {
|
|
|
43
66
|
platform: 'browser',
|
|
44
67
|
brand,
|
|
45
68
|
},
|
|
46
|
-
|
|
69
|
+
user: this.userInformation,
|
|
47
70
|
})
|
|
48
71
|
}
|
|
49
72
|
|
|
50
73
|
async _getUserInformationOnLoad() {
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
console.error('User information could not be loaded:', error)
|
|
59
|
-
return {}
|
|
74
|
+
if (hybrid.isNativeApp()) {
|
|
75
|
+
try {
|
|
76
|
+
const radioToken = await hybrid.appLoaded()
|
|
77
|
+
this.setUserInformation(radioToken)
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error('User information could not be loaded:', error)
|
|
80
|
+
}
|
|
60
81
|
}
|
|
61
82
|
}
|
|
62
83
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
loggedIn: true,
|
|
68
|
-
},
|
|
84
|
+
setUserInformation(radioToken) {
|
|
85
|
+
this.userInformation = {
|
|
86
|
+
account_id: hybrid.decodeRadioToken(radioToken).uid,
|
|
87
|
+
loggedIn: true,
|
|
69
88
|
}
|
|
70
89
|
}
|
|
71
90
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { config } from '../config/config.js'
|
|
2
|
+
|
|
3
|
+
const prefixes = {
|
|
4
|
+
BE: '+32',
|
|
5
|
+
NL: '+31',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const removePhoneNumberCountryPrefix = (phoneNumber, prefix = null) => {
|
|
9
|
+
prefix ||= prefixes[config('country_code')]
|
|
10
|
+
|
|
11
|
+
if (prefix) {
|
|
12
|
+
phoneNumber = phoneNumber.replace(`${prefix}.`, '0')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return phoneNumber.replace('.', '')
|
|
16
|
+
}
|