choreograph-create-pixel 1.3.0 β 1.3.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/README.md +4 -4
- package/dist/bundle.cjs.js +7 -3
- package/dist/bundle.esm.js +7 -3
- package/dist/bundle.iife.min.js +2 -2
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ new Pixel({
|
|
|
76
76
|
// [Optional] Trigger by DOM events, rather than scrape content updates
|
|
77
77
|
trigger: {
|
|
78
78
|
event: "click",
|
|
79
|
-
elements:
|
|
79
|
+
elements: "button.basket[data-sku]",
|
|
80
80
|
},
|
|
81
81
|
|
|
82
82
|
// The "element" parameter only becomes available when using a trigger
|
|
@@ -91,7 +91,7 @@ new Pixel({
|
|
|
91
91
|
|
|
92
92
|
trigger: {
|
|
93
93
|
event: "click",
|
|
94
|
-
elements:
|
|
94
|
+
elements: "button.checkout",
|
|
95
95
|
},
|
|
96
96
|
|
|
97
97
|
// Segment pixels support multiple SKUs
|
|
@@ -103,7 +103,7 @@ new Pixel({
|
|
|
103
103
|
|
|
104
104
|
### CDN library
|
|
105
105
|
|
|
106
|
-
This implementation method allows for direct embedding on pages without the need for
|
|
106
|
+
This alternative implementation method allows for direct embedding on pages without the need for bundling nor transpiling.
|
|
107
107
|
|
|
108
108
|
```html
|
|
109
109
|
<script src="https://cdn.jsdelivr.net/npm/choreograph-create-pixel@1"></script>
|
|
@@ -133,7 +133,7 @@ Enable browser console debugging by adding `?pixel_debug` or `#pixel_debug` to t
|
|
|
133
133
|
| `scrape.*`<br>_(scrapers only)_ | String, Number, Boolean or Function | Scrapes arbitrary product data. `*` should always match with existing field names in the advertiser's product store. | _Required_ |
|
|
134
134
|
| `trigger` | Object | Adds an event listener to enable the pixel only on a specific DOM event, instead of on scrape content updates. | `undefined` |
|
|
135
135
|
| `trigger.event` | String | DOM event type. [List of supported values.](https://www.w3schools.com/jsref/dom_obj_event.asp) | _Required_ |
|
|
136
|
-
| `trigger.elements` | Function
|
|
136
|
+
| `trigger.elements` | String, Function | This query selector string, or function returning DOM element(s), is used to apply the event listener to. | _Required_ |
|
|
137
137
|
| `optional`<br>_(scrapers only)_ | Array | An array of field names (as used in `scrape.*`) that are allowed to have empty values. | `[]` |
|
|
138
138
|
| `before` | Function | A custom function that's executed just before the pixel is executed. | `(scrapedData, callback) => { callback(scrapedData); }` |
|
|
139
139
|
| `after` | Function | A custom function that's executed just after the pixel has been executed. | `(scrapedData) => {}` |
|
package/dist/bundle.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! choreograph-create-pixel v1.3.
|
|
1
|
+
/*! choreograph-create-pixel v1.3.2 2022/12/22 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
class ChoreographCreatePixel {
|
|
@@ -137,7 +137,11 @@ class ChoreographCreatePixel {
|
|
|
137
137
|
const attribute = `create-${this.config.type}-${this.config.trigger.event}`;
|
|
138
138
|
|
|
139
139
|
try {
|
|
140
|
-
let elements =
|
|
140
|
+
let elements =
|
|
141
|
+
typeof this.config.trigger.elements === "string"
|
|
142
|
+
? document.querySelectorAll(this.config.trigger.elements)
|
|
143
|
+
: this.config.trigger.elements();
|
|
144
|
+
|
|
141
145
|
if (!elements.forEach) elements = [elements];
|
|
142
146
|
|
|
143
147
|
elements.forEach((element) => {
|
|
@@ -172,7 +176,7 @@ class ChoreographCreatePixel {
|
|
|
172
176
|
try {
|
|
173
177
|
result = result(element);
|
|
174
178
|
} catch (error) {
|
|
175
|
-
if (this.config.optional.includes(fieldName)) return
|
|
179
|
+
if (this.config.optional.includes(fieldName)) return undefined;
|
|
176
180
|
|
|
177
181
|
this.log(
|
|
178
182
|
this.config.type === "attribution" ? "warn" : "error",
|
package/dist/bundle.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! choreograph-create-pixel v1.3.
|
|
1
|
+
/*! choreograph-create-pixel v1.3.2 2022/12/22 */
|
|
2
2
|
class ChoreographCreatePixel {
|
|
3
3
|
constructor(userConfig) {
|
|
4
4
|
this.previouslyScrapedHash = null;
|
|
@@ -135,7 +135,11 @@ class ChoreographCreatePixel {
|
|
|
135
135
|
const attribute = `create-${this.config.type}-${this.config.trigger.event}`;
|
|
136
136
|
|
|
137
137
|
try {
|
|
138
|
-
let elements =
|
|
138
|
+
let elements =
|
|
139
|
+
typeof this.config.trigger.elements === "string"
|
|
140
|
+
? document.querySelectorAll(this.config.trigger.elements)
|
|
141
|
+
: this.config.trigger.elements();
|
|
142
|
+
|
|
139
143
|
if (!elements.forEach) elements = [elements];
|
|
140
144
|
|
|
141
145
|
elements.forEach((element) => {
|
|
@@ -170,7 +174,7 @@ class ChoreographCreatePixel {
|
|
|
170
174
|
try {
|
|
171
175
|
result = result(element);
|
|
172
176
|
} catch (error) {
|
|
173
|
-
if (this.config.optional.includes(fieldName)) return
|
|
177
|
+
if (this.config.optional.includes(fieldName)) return undefined;
|
|
174
178
|
|
|
175
179
|
this.log(
|
|
176
180
|
this.config.type === "attribution" ? "warn" : "error",
|
package/dist/bundle.iife.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! choreograph-create-pixel v1.3.
|
|
2
|
-
var ChoreographCreatePixel=function(){"use strict";function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var r=1;r<arguments.length;r++){var
|
|
1
|
+
/*! choreograph-create-pixel v1.3.2 2022/12/22 */
|
|
2
|
+
var ChoreographCreatePixel=function(){"use strict";function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?e(Object(i),!0).forEach((function(e){n(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,i(n.key),n)}}function n(e,t,r){return(t=i(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var o=function(){function e(r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.previouslyScrapedHash=null,this.logs=[],this.config=t({colors:{error:"red",warn:"orange",success:"green"},icons:{scraper:"π",viewed:"π",basketed:"π",purchased:"π§Ύ",attribution:"π",conversion:"π΅"},debug:/(pixel|lemonpi)_debug/i.test(location.href),before:function(e,t){return t(e)},after:function(){},optional:[]},r),this.validateConfig()&&this.cycle()}var i,o,c;return i=e,o=[{key:"log",value:function(e,t){var r,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;if(this.config.debug&&!this.logs.includes(t)){var i=["%cβΈ¬ create%c ".concat(this.config.type," ").concat(this.config.icons[this.config.type]," %c").concat(t),"background:black;color:white;border-radius:3px;padding:3px 6px","font-weight:bold","color:".concat(this.config.colors[e])];n&&i.push(n),(r=console).info.apply(r,i),this.logs.push(t)}}},{key:"validateConfig",value:function(){if("number"!=typeof this.config.advertiser)this.log("error","Please use a number",{advertiser:this.config.advertiser});else if(["scraper","viewed","basketed","purchased"].includes(this.config.type))if(this.config.url instanceof RegExp){if(this.config.scrape)return!0;this.log("error","Please provide something to scrape",{scrape:this.config.scrape})}else this.log("error","Please use a regular expression",{url:this.config.url});else this.log("error","Please use scraper, viewed, basketed or purchased",{type:this.config.type})}},{key:"cycle",value:function(){var e=this;if(this.config.url.test(location.href))if("scraper"===this.config.type&&document.querySelector('html[class*="translated-"]'))this.log("warn","This page has been translated by the browser, and won't be scraped");else if(this.config.trigger){var t="create-".concat(this.config.type,"-").concat(this.config.trigger.event);try{var r="string"==typeof this.config.trigger.elements?document.querySelectorAll(this.config.trigger.elements):this.config.trigger.elements();r.forEach||(r=[r]),r.forEach((function(r){r.hasAttribute(t)||(r.addEventListener(e.config.trigger.event,(function(){return e.scrape(r)})),r.setAttribute(t,""))}))}catch(e){this.log("error",e.message,{"trigger.elements":this.config.trigger.elements})}}else this.scrape();else this.log("warn",'URL pattern does not match "'.concat(location.href,'"'),{url:this.config.url});setTimeout((function(){return e.cycle()}),750)}},{key:"scrape",value:function(e){var r,i=this,o=!1,c=function(t,r){var c=t;if("function"==typeof c)try{c=c(e)}catch(e){if(i.config.optional.includes(r))return;i.log("attribution"===i.config.type?"warn":"error",e.message,n({},r?"scrape.".concat(r):"scrape",c)),o=!0}if("string"==typeof c&&(c=c.replace(/\s+/g," ").trim()),null==c||""===c){if(i.config.optional.includes(r))return null;i.log("attribution"===i.config.type?"warn":"error","Value is empty",n({},r?"scrape.".concat(r):"scrape",c)),o=!0}return c};"conversion"===this.config.type?"string"!=typeof(r={conversion:c(this.config.scrape),attribution:localStorage.getItem("create-attribution-id")}).attribution&&(this.log("warn","There's no attribution ID stored yet"),o=!0):r="scraper"!==this.config.type?c(this.config.scrape):Object.keys(this.config.scrape).reduce((function(e,r){return t(t({},e),{},n({},r,c(i.config.scrape[r],r)))}),{});var s=JSON.stringify(r);if(!o&&this.previouslyScrapedHash!==s){try{this.config.before(r,(function(e){if("attribution"===i.config.type){localStorage.setItem("create-attribution-id",r),i.log("success","Successful!",{attribution:r});try{i.config.after(r)}catch(e){i.log("error",e.message,{after:i.config.after})}}else Array.isArray(e)?e.forEach((function(e){return i.send(e)})):i.send(e)}))}catch(e){this.log("error",e.message,{before:this.config.before})}this.previouslyScrapedHash=s,this.logs.length=0}}},{key:"send",value:function(e){var r,n=this;switch(this.config.type){case"scraper":r="https://d.lemonpi.io/scrapes".concat(this.config.debug?"?validate=true":"");break;case"conversion":r="https://lemonpi.io/";break;default:r="https://d.lemonpi.io/a/".concat(this.config.advertiser,"/product/event?e=").concat(encodeURIComponent(JSON.stringify({"event-type":"product-".concat(this.config.type),sku:e})))}"scraper"===this.config.type||this.config.debug?fetch(r,"scraper"===this.config.type?{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({"advertiser-id":this.config.advertiser,sku:e.sku,fields:t(t({},e),{},{sku:void 0})})}:null).then((function(t){return t.json().then((function(r){if(t.ok){n.log("warn","Successful, with warnings. Details:",r);try{n.config.after(e)}catch(e){n.log("error",e.message,{after:n.config.after})}}else n.log("error","Failed: ".concat(t.status," (").concat(t.statusText,"). Details:"),r);n.logs.length=0})).catch((function(){if(t.ok){n.log("success","Successful!",["viewed","basketed","purchased"].includes(n.config.type)?{sku:e}:e);try{n.config.after(e)}catch(e){n.log("error",e.message,{after:n.config.after})}}else n.log("error","Failed: ".concat(t.status," (").concat(t.statusText,"). Details:"),t);n.logs.length=0}))})).catch((function(e){n.log("error","Failed: ".concat(e.message)),n.logs.length=0})):(new Image).src=r}}],c=[{key:"getUrl",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.allowedQueryParameters,r=void 0===t?[]:t,n=e.allowHash,i=void 0!==n&&n,o="".concat(location.protocol,"//").concat(location.host).concat(location.pathname),c=new URLSearchParams(location.search);return r.reduce((function(e,t){var r=e?"&":"?",n=encodeURI(t),i=c.get(t);return null!=i?(o+="".concat(r).concat(n).concat(""===i?"":"=".concat(encodeURI(i))),!0):e}),!1),i&&(o+=location.hash),o}},{key:"getAllPathSegments",value:function(){return location.pathname.split("/").filter((function(e){return e})).map((function(e){return decodeURI(e)}))}},{key:"getPathSegment",value:function(e){return this.getAllPathSegments()[e]}},{key:"getAllQueryParameters",value:function(){return location.search.replace(/^\?/,"").split("&").filter((function(e){return e})).reduce((function(e,r){return t(t({},e),{},n({},decodeURI(r.split("=")[0]),decodeURI(r.split("=")[1]||"")))}),{})}},{key:"getQueryParameter",value:function(e){return this.getAllQueryParameters()[e]}}],o&&r(i.prototype,o),c&&r(i,c),Object.defineProperty(i,"prototype",{writable:!1}),e}();return o}();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "choreograph-create-pixel",
|
|
3
3
|
"description": "This library lets you apply best practises to Choreograph Create pixel development and implementation.",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wpp",
|
|
7
7
|
"groupm",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"opendc"
|
|
11
11
|
],
|
|
12
12
|
"author": "Rick Stevens <rick.stevens@choreograph.com> (https://lemonpi.io)",
|
|
13
|
-
"repository": "gitlab:
|
|
13
|
+
"repository": "gitlab:2sixty/choreograph-create/solutions/choreograph-create-pixel",
|
|
14
14
|
"homepage": "https://lemonpi.io",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"main": "dist/bundle.cjs.js",
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"prepublishOnly": "npm run build"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "^7.
|
|
32
|
-
"@babel/preset-env": "^7.
|
|
33
|
-
"@rollup/plugin-babel": "^6.0.
|
|
31
|
+
"@babel/core": "^7.20.7",
|
|
32
|
+
"@babel/preset-env": "^7.20.2",
|
|
33
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
34
34
|
"@rollup/plugin-eslint": "^9.0.1",
|
|
35
|
-
"
|
|
35
|
+
"@rollup/plugin-terser": "^0.2.1",
|
|
36
|
+
"eslint": "^8.30.0",
|
|
36
37
|
"eslint-config-prettier": "^8.5.0",
|
|
37
38
|
"eslint-plugin-prettier": "^4.2.1",
|
|
38
39
|
"moment": "^2.29.4",
|
|
39
|
-
"prettier": "^2.
|
|
40
|
-
"rollup": "^2.79.1"
|
|
41
|
-
"rollup-plugin-terser": "^7.0.2"
|
|
40
|
+
"prettier": "^2.8.1",
|
|
41
|
+
"rollup": "^2.79.1"
|
|
42
42
|
}
|
|
43
43
|
}
|