@dpgradio/creative 5.8.1 → 5.9.0

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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dpgradio/creative",
3
- "version": "5.8.1",
3
+ "version": "5.9.0",
4
4
  "description": "Support package for standalone Javascript applications",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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.pushEvent('account_id', this._formatUserInformation(radioToken))
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
- const user = await this._getUserInformationOnLoad()
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
- ...user,
69
+ user: this.userInformation,
47
70
  })
48
71
  }
49
72
 
50
73
  async _getUserInformationOnLoad() {
51
- if (!hybrid.isNativeApp()) {
52
- return {}
53
- }
54
- try {
55
- const radioToken = await hybrid.appLoaded()
56
- return this._formatUserInformation(radioToken)
57
- } catch (error) {
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
- _formatUserInformation(radioToken) {
64
- return {
65
- user: {
66
- account_id: hybrid.decodeRadioToken(radioToken).uid,
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
  }
@@ -1,4 +1,4 @@
1
- import SockJS from 'sockjs-client/dist/sockjs.js'
1
+ import SockJS from 'sockjs-client/dist/sockjs'
2
2
 
3
3
  export default class SocketConnection {
4
4
  constructor(host, options) {