dbm 1.1.2 → 1.1.4
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/graphapi/webclient/decode/index.js +8 -0
- package/package.json +1 -1
- package/react/admin/EditPage.js +1 -1
- package/react/admin/editor/fields/ImageField.js +4 -3
- package/react/image/CoverScaledImage.js +5 -0
- package/react/image/Image.js +10 -1
- package/react/image/WidthScaledImage.js +5 -0
- package/site/BrowserUpdater.js +21 -3
- package/tracking/Controller.js +81 -0
- package/tracking/DataLayerTracker.js +2 -2
- package/tracking/MetaPixelTracker.js +112 -0
- package/tracking/index.js +8 -1
- package/utils/ArrayFunctions.js +13 -0
- package/utils/UrlFunctions.js +25 -3
|
@@ -93,4 +93,12 @@ export const fullSetup = function() {
|
|
|
93
93
|
currentDecoder.item.setValue("encodingType", name);
|
|
94
94
|
currentDecoder.item.register(decodePrefix + name);
|
|
95
95
|
}
|
|
96
|
+
|
|
97
|
+
{
|
|
98
|
+
let name = "visibility";
|
|
99
|
+
let currentDecoder = new Dbm.graphapi.webclient.decode.DecodeBaseObject();
|
|
100
|
+
currentDecoder.item.setValue("copyFields", ["visibility"]);
|
|
101
|
+
currentDecoder.item.setValue("encodingType", name);
|
|
102
|
+
currentDecoder.item.register(decodePrefix + name);
|
|
103
|
+
}
|
|
96
104
|
}
|
package/package.json
CHANGED
package/react/admin/EditPage.js
CHANGED
|
@@ -107,7 +107,7 @@ export default class EditPage extends Dbm.react.BaseObject {
|
|
|
107
107
|
React.createElement("div", {className: "spacing micro"}),
|
|
108
108
|
React.createElement("div", {className: "flex-row justify-between"},
|
|
109
109
|
React.createElement("div", {className: "flex-row-item"},
|
|
110
|
-
React.createElement("div", {onClick: () => {this._generateSeoSummary()}}, "Generate"),
|
|
110
|
+
React.createElement("div", {onClick: () => {this._generateSeoSummary()}, className: "action-button action-button-padding"}, "Generate"),
|
|
111
111
|
),
|
|
112
112
|
React.createElement("div", {className: "flex-row-item"},
|
|
113
113
|
Dbm.react.text.text(this.item.properties.descriptionLength),
|
|
@@ -35,7 +35,7 @@ export default class ImageField extends Dbm.react.BaseObject {
|
|
|
35
35
|
React.createElement("div", {},
|
|
36
36
|
React.createElement(Dbm.react.area.HasData, {check: Dbm.react.source.contextVariable("moduleData.editorData.data." + fieldName + ".id"), checkType: "invert/default"},
|
|
37
37
|
React.createElement(Dbm.react.interaction.CommandButton, {command: Dbm.commands.callFunction(this._addToLibrary.bind(this))},
|
|
38
|
-
React.createElement("div", {},
|
|
38
|
+
React.createElement("div", {className: "action-button action-button-padding"},
|
|
39
39
|
"Add to library"
|
|
40
40
|
)
|
|
41
41
|
)
|
|
@@ -43,17 +43,18 @@ export default class ImageField extends Dbm.react.BaseObject {
|
|
|
43
43
|
),
|
|
44
44
|
React.createElement(Dbm.react.area.HasData, {check: Dbm.react.source.contextVariable("moduleData.editorData.data." + fieldName + ".id")},
|
|
45
45
|
React.createElement(Dbm.react.form.FormField, {value: this.item.properties.altText, className: "standard-field standard-field-padding full-width"}),
|
|
46
|
+
React.createElement("div", {className: "spacing micro"}),
|
|
46
47
|
React.createElement("div", {className: "flex-row small-item-spacing"},
|
|
47
48
|
React.createElement("div", {className: "flex-row-item"},
|
|
48
49
|
React.createElement(Dbm.react.interaction.CommandButton, {command: Dbm.commands.callFunction(this._generateAltText.bind(this))},
|
|
49
|
-
React.createElement("div", {},
|
|
50
|
+
React.createElement("div", {className: "action-button action-button-padding"},
|
|
50
51
|
"Generate"
|
|
51
52
|
)
|
|
52
53
|
)
|
|
53
54
|
),
|
|
54
55
|
React.createElement("div", {className: "flex-row-item"},
|
|
55
56
|
React.createElement(Dbm.react.interaction.CommandButton, {command: Dbm.commands.callFunction(this._saveAltTextToLibrary.bind(this))},
|
|
56
|
-
React.createElement("div", {},
|
|
57
|
+
React.createElement("div", {className: "action-button action-button-padding"},
|
|
57
58
|
"Save to library"
|
|
58
59
|
)
|
|
59
60
|
)
|
|
@@ -21,6 +21,11 @@ export default class CoverScaledImage extends Dbm.react.BaseObject {
|
|
|
21
21
|
|
|
22
22
|
let newProps = this._copyProps({src: url});
|
|
23
23
|
|
|
24
|
+
let altText = Dbm.objectPath(image, "altText");
|
|
25
|
+
if(altText) {
|
|
26
|
+
newProps["alt"] = altText;
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
let elementType = this.getPropValue("elementType");
|
|
25
30
|
if(elementType) {
|
|
26
31
|
newProps["elementType"] = elementType;
|
package/react/image/Image.js
CHANGED
|
@@ -11,6 +11,7 @@ export default class Image extends Dbm.react.BaseObject {
|
|
|
11
11
|
let isDiv = (elementType !== "img");
|
|
12
12
|
if(isDiv) {
|
|
13
13
|
delete aProps["src"];
|
|
14
|
+
delete aProps["alt"];
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
|
@@ -26,7 +27,15 @@ export default class Image extends Dbm.react.BaseObject {
|
|
|
26
27
|
};
|
|
27
28
|
let className = "image";
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
let props = {style: imageStyle, className: className};
|
|
31
|
+
|
|
32
|
+
let altText = this.getPropValue("alt");
|
|
33
|
+
if(altText) {
|
|
34
|
+
props["role"] = "img";
|
|
35
|
+
props["aria-label"] = altText;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return this._createMainElement("div", props, this.getPropValue("children"));
|
|
30
39
|
}
|
|
31
40
|
else {
|
|
32
41
|
let className = "image";
|
|
@@ -19,6 +19,11 @@ export default class WidthScaledImage extends Dbm.react.BaseObject {
|
|
|
19
19
|
|
|
20
20
|
let newProps = this._copyProps({src: url});
|
|
21
21
|
|
|
22
|
+
let altText = Dbm.objectPath(image, "altText");
|
|
23
|
+
if(altText) {
|
|
24
|
+
newProps["alt"] = altText;
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
let elementType = this.getPropValue("elementType");
|
|
23
28
|
if(elementType) {
|
|
24
29
|
newProps["elementType"] = elementType;
|
package/site/BrowserUpdater.js
CHANGED
|
@@ -29,11 +29,29 @@ export default class BrowserUpdater extends Dbm.core.BaseObject {
|
|
|
29
29
|
|
|
30
30
|
let title = Dbm.objectPath(this.item.pageData, "page.title") + this.item.titleSuffix;
|
|
31
31
|
document.title = title;
|
|
32
|
-
|
|
32
|
+
{
|
|
33
|
+
let element = document.querySelector('meta[property="og:title"]');
|
|
34
|
+
if(element) {
|
|
35
|
+
element.setAttribute("content", title);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
|
|
34
40
|
let description = Dbm.objectPath(this.item.pageData, "page.meta/description");
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
{
|
|
42
|
+
let element = document.querySelector('meta[name="description"]');
|
|
43
|
+
if(element) {
|
|
44
|
+
element.setAttribute("content", description);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
{
|
|
49
|
+
let element = document.querySelector('meta[property="og:description"]');
|
|
50
|
+
if(element) {
|
|
51
|
+
element.setAttribute("content", description);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
37
55
|
|
|
38
56
|
//METODO: set canonical
|
|
39
57
|
|
package/tracking/Controller.js
CHANGED
|
@@ -6,6 +6,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
6
6
|
super._construct();
|
|
7
7
|
|
|
8
8
|
this.item.setValue("trackers", []);
|
|
9
|
+
this.item.setValue("currency", "EUR");
|
|
9
10
|
|
|
10
11
|
Dbm.flow.addDirectUpdateCommand(this.item.requireProperty("active", false), Dbm.commands.callFunction(this._updateActiveStatus.bind(this)));
|
|
11
12
|
|
|
@@ -154,4 +155,84 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
154
155
|
}
|
|
155
156
|
}
|
|
156
157
|
}
|
|
158
|
+
|
|
159
|
+
_getValueFromItems(aItems) {
|
|
160
|
+
let value = 0;
|
|
161
|
+
|
|
162
|
+
let currentArray = aItems;
|
|
163
|
+
let currentArrayLength = currentArray.length;
|
|
164
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
165
|
+
let currentItem = currentArray[i];
|
|
166
|
+
|
|
167
|
+
let quantity = currentItem.quantity ? currentItem.quantity : 1;
|
|
168
|
+
value += quantity*currentItem.price;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
trackProductView(aProduct) {
|
|
175
|
+
|
|
176
|
+
let items = [aProduct];
|
|
177
|
+
|
|
178
|
+
let data = {
|
|
179
|
+
currency: this.item.currency,
|
|
180
|
+
value: this._getValueFromItems(items),
|
|
181
|
+
items: items
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
this.trackEvent("Product view", data);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
trackAddedToCart(aProductOrProducts) {
|
|
188
|
+
let items = Dbm.utils.ArrayFunctions.singleOrArray(aProductOrProducts);
|
|
189
|
+
|
|
190
|
+
let data = {
|
|
191
|
+
currency: this.item.currency,
|
|
192
|
+
value: this._getValueFromItems(items),
|
|
193
|
+
items: items
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
this.trackEvent("Added to cart", data);
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
trackCheckoutStrated(aProductOrProducts) {
|
|
201
|
+
let items = Dbm.utils.ArrayFunctions.singleOrArray(aProductOrProducts);
|
|
202
|
+
|
|
203
|
+
let data = {
|
|
204
|
+
currency: this.item.currency,
|
|
205
|
+
value: this._getValueFromItems(items),
|
|
206
|
+
items: items
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
this.trackEvent("Checkout started", data);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
trackPurchase(aTransactionId, aProductOrProducts) {
|
|
213
|
+
let items = Dbm.utils.ArrayFunctions.singleOrArray(aProductOrProducts);
|
|
214
|
+
|
|
215
|
+
let data = {
|
|
216
|
+
transaction_id: aTransactionId,
|
|
217
|
+
currency: this.item.currency,
|
|
218
|
+
value: this._getValueFromItems(items),
|
|
219
|
+
items: items
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this.trackEvent("Purchase", data);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
createProductItemData(aId, aName, aPrice, aQuantity = 1, aAddtionalData = {}) {
|
|
226
|
+
|
|
227
|
+
let returnObject = {
|
|
228
|
+
...aAddtionalData,
|
|
229
|
+
id: aId,
|
|
230
|
+
item_id: aId,
|
|
231
|
+
item_name: aName,
|
|
232
|
+
price: aPrice,
|
|
233
|
+
quantity: aQuantity
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return returnObject;
|
|
237
|
+
}
|
|
157
238
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Dbm from "../index.js";
|
|
2
|
-
import Cookies from "js-cookie";
|
|
3
2
|
|
|
4
|
-
export default class
|
|
3
|
+
export default class DataLayerTracker extends Dbm.core.BaseObject {
|
|
5
4
|
_construct() {
|
|
6
5
|
super._construct();
|
|
7
6
|
}
|
|
@@ -68,6 +67,7 @@ export default class Controller extends Dbm.core.BaseObject {
|
|
|
68
67
|
console.log(aEventName, aData);
|
|
69
68
|
|
|
70
69
|
this.addToDataLayer({"event": "trackEvent", "value": {"name": aEventName, "data": aData}});
|
|
70
|
+
this._gtag("event", aEventName, aData);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
trackCurrentPage() {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
3
|
+
export default class MetaPixelTracker extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
this.item.requireProperty("pixelId")
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
_setupFunction() {
|
|
11
|
+
|
|
12
|
+
if(window.fbq) return;
|
|
13
|
+
|
|
14
|
+
let fbq = function() {
|
|
15
|
+
fbq.callMethod ? fbq.callMethod.apply(fbq, arguments) : fbq.queue.push(arguments);
|
|
16
|
+
}
|
|
17
|
+
window.fbq = fbq;
|
|
18
|
+
|
|
19
|
+
if(!window._fbq) {
|
|
20
|
+
window._fbq = fbq;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fbq.push = fbq;
|
|
24
|
+
fbq.loaded = true;
|
|
25
|
+
fbq.version = "2.0";
|
|
26
|
+
fbq.queue = [];
|
|
27
|
+
fbq.disablePushState = true;
|
|
28
|
+
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
startTracking() {
|
|
33
|
+
|
|
34
|
+
//MENOTE: do nothing
|
|
35
|
+
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
startStatisticsTracking() {
|
|
40
|
+
|
|
41
|
+
//MENOTE: do nothing
|
|
42
|
+
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
startMarketingTracking() {
|
|
47
|
+
|
|
48
|
+
this._setupFunction();
|
|
49
|
+
Dbm.loading.loadScript("https://connect.facebook.net/en_US/fbevents.js");
|
|
50
|
+
|
|
51
|
+
let pixelId = this.item.pixelId;
|
|
52
|
+
|
|
53
|
+
if(this.item.pixelId) {
|
|
54
|
+
window.fbq("init", this.item.pixelId);
|
|
55
|
+
window.fbq("track", "PageView");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
stopTracking() {
|
|
62
|
+
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_convertGooogleAnalyctisData(aData) {
|
|
67
|
+
|
|
68
|
+
let data = {
|
|
69
|
+
content_type: "product",
|
|
70
|
+
value: aData.value,
|
|
71
|
+
currency: aData.currency,
|
|
72
|
+
contents: aData.items,
|
|
73
|
+
num_items: aData.items.length,
|
|
74
|
+
content_ids: Dbm.utils.ArrayFunctions.mapField(aData.items, "id")
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if(aData.items.length === 1) {
|
|
78
|
+
data["content_name"] = aData.items[0]["item_name"];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
trackEvent(aEventName, aData) {
|
|
85
|
+
console.log("trackEvent");
|
|
86
|
+
console.log(aEventName, aData);
|
|
87
|
+
|
|
88
|
+
if(aEventName === "Purchase") {
|
|
89
|
+
window.fbq('track', 'Purchase', this._convertGooogleAnalyctisData(aData), {eventID: aData.transaction_id});
|
|
90
|
+
}
|
|
91
|
+
else if(aEventName === "Product view") {
|
|
92
|
+
window.fbq('track', 'ViewContent', this._convertGooogleAnalyctisData(aData));
|
|
93
|
+
}
|
|
94
|
+
else if(aEventName === "Added to cart") {
|
|
95
|
+
window.fbq('track', 'AddToCart', this._convertGooogleAnalyctisData(aData));
|
|
96
|
+
}
|
|
97
|
+
else if(aEventName === "Checkout started") {
|
|
98
|
+
window.fbq('track', 'InitiateCheckout', this._convertGooogleAnalyctisData(aData));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
window.fbq("trackCustom", aEventName, aData);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
trackCurrentPage() {
|
|
106
|
+
window.fbq("track", "PageView");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
trackPage(aUrl) {
|
|
110
|
+
window.fbq("track", "PageView");
|
|
111
|
+
}
|
|
112
|
+
}
|
package/tracking/index.js
CHANGED
|
@@ -2,8 +2,9 @@ import Dbm from "../index.js";
|
|
|
2
2
|
|
|
3
3
|
export {default as Controller} from "./Controller.js";
|
|
4
4
|
export {default as DataLayerTracker} from "./DataLayerTracker.js";
|
|
5
|
+
export {default as MetaPixelTracker} from "./MetaPixelTracker.js";
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
+
export const setup = function() {
|
|
7
8
|
|
|
8
9
|
let controller = new Dbm.tracking.Controller();
|
|
9
10
|
controller.item.register("trackingController");
|
|
@@ -13,4 +14,10 @@ export let setup = function() {
|
|
|
13
14
|
|
|
14
15
|
let dataLayerTracker = new Dbm.tracking.DataLayerTracker();
|
|
15
16
|
controller.addTracker(dataLayerTracker.item);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const addMetaPixel = function(aPixelId) {
|
|
20
|
+
let tracker = new Dbm.tracking.MetaPixelTracker();
|
|
21
|
+
tracker.item.pixelId = aPixelId;
|
|
22
|
+
Dbm.getInstance().repository.getItem("trackingController").controller.addTracker();
|
|
16
23
|
}
|
package/utils/ArrayFunctions.js
CHANGED
|
@@ -130,5 +130,18 @@ export const filterByField = function(aArray, aField, aValue) {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
return returnArray;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export const mapField = function(aArray, aField) {
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
let currentArray = aArray;
|
|
140
|
+
let currentArrayLength = currentArray.length;
|
|
141
|
+
let returnArray = new Array(acurrentArrayLength);
|
|
142
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
143
|
+
returnArray[i] = Dbm.objectPath(aArray[i], aField);
|
|
144
|
+
}
|
|
145
|
+
|
|
133
146
|
return returnArray;
|
|
134
147
|
}
|
package/utils/UrlFunctions.js
CHANGED
|
@@ -16,7 +16,15 @@ export let createScaledImageUrl = function(aImageData, aWantedWidth) {
|
|
|
16
16
|
100*Math.round(window.devicePixelRatio*window.innerWidth/100)
|
|
17
17
|
)
|
|
18
18
|
);
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
let scaleString = "width=" + scaleToWidth;
|
|
21
|
+
|
|
22
|
+
let format = "webp";
|
|
23
|
+
if(format) {
|
|
24
|
+
scaleString += ",format=" + format;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
url = aImageData["resizeUrl"].split("{scale}").join(scaleString);
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
return url;
|
|
@@ -43,7 +51,14 @@ export let createCoverScaledImageUrl = function(aImageData, aWantedWidth, aWante
|
|
|
43
51
|
|
|
44
52
|
let scaleToHeight = Math.round(aWantedHeight*scaleToWidth/aWantedWidth);
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+
let scaleString = "width=" + scaleToWidth + ",height=" + scaleToHeight + ",fit=cover";
|
|
55
|
+
|
|
56
|
+
let format = "webp";
|
|
57
|
+
if(format) {
|
|
58
|
+
scaleString += ",format=" + format;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
url = aImageData["resizeUrl"].split("{scale}").join(scaleString);
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
return url;
|
|
@@ -60,7 +75,14 @@ export const getContainScaledImageUrl = function(aUrl, aWantedWidth, aWantedHeig
|
|
|
60
75
|
|
|
61
76
|
let scaleToHeight = Math.round(aWantedHeight*scaleToWidth/aWantedWidth);
|
|
62
77
|
|
|
63
|
-
|
|
78
|
+
let scaleString = "width=" + scaleToWidth + ",height=" + scaleToHeight + ",fit=contain";
|
|
79
|
+
|
|
80
|
+
let format = "webp";
|
|
81
|
+
if(format) {
|
|
82
|
+
scaleString += ",format=" + format;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return aUrl.split("{scale}").join(scaleString);
|
|
64
86
|
}
|
|
65
87
|
|
|
66
88
|
export let createContainScaledImageUrl = function(aImageData, aWantedWidth, aWantedHeight) {
|