@walkeros/web-destination-meta
Version:
Meta pixel web destination for walkerOS
1 lines • 12.7 kB
JavaScript
"use strict";function _array_like_to_array(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _array_with_holes(e){if(Array.isArray(e))return e}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function _define_property(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _iterable_to_array_limit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,a=[],i=!0,c=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(a.push(n.value),!t||a.length!==t);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==r.return||r.return()}finally{if(c)throw o}}return a}}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){_define_property(e,t,r[t])})}return e}function ownKeys(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 _object_spread_props(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),e}function _sliced_to_array(e,t){return _array_with_holes(e)||_iterable_to_array_limit(e,t)||_unsupported_iterable_to_array(e,t)||_non_iterable_rest()}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _type_of(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function _unsupported_iterable_to_array(e,t){if(e){if("string"==typeof e)return _array_like_to_array(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_array_like_to_array(e,t):void 0}}var Destination=function(){var e,t,r=function(e){return"object"==(void 0===e?"undefined":_type_of(e))&&null!==e&&!function(e){return Array.isArray(e)}(e)&&"[object Object]"===Object.prototype.toString.call(e)},n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.timestamp||(new Date).setHours(0,13,37,0),r=e.group||"gr0up",n=e.count||1,o=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};r=_object_spread({},g,r);var n=Object.entries(t).reduce(function(t,n){var o=_sliced_to_array(n,2),a=o[0],i=o[1],c=e[a];return r.merge&&Array.isArray(c)&&Array.isArray(i)?t[a]=i.reduce(function(e,t){return e.includes(t)?e:_to_consumable_array(e).concat([t])},_to_consumable_array(c)):(r.extend||a in e)&&(t[a]=i),t},{});return r.shallow?_object_spread({},e,n):(Object.assign(e,n),e)}({event:"entity action",data:{string:"foo",number:1,boolean:!0,array:[0,"text",!1],not:void 0},context:{dev:["test",1]},globals:{lang:"elb"},custom:{completely:"random"},user:{id:"us3r",device:"c00k13",session:"s3ss10n"},nested:[{type:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:"".concat(t,"-").concat(r,"-").concat(n),trigger:"test",entity:"entity",action:"action",timestamp:t,timing:3.14,group:r,count:n,version:{source:m,tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.event){var a,i=_sliced_to_array(null!==(a=e.event.split(" "))&&void 0!==a?a:[],2),c=i[0],u=i[1];c&&u&&(o.entity=c,o.action=u)}return o},o=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"entity action",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.timestamp||(new Date).setHours(0,13,37,0),o={data:{id:"ers",name:"Everyday Ruck Snack",color:"black",size:"l",price:420}},a={data:{id:"cc",name:"Cool Cap",size:"one size",price:42}};return n(_object_spread_props(_object_spread({},{"cart view":{data:{currency:"EUR",value:2*o.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{type:"product",data:_object_spread_props(_object_spread({},o.data),{quantity:2}),context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:o.data.price+a.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[_object_spread_props(_object_spread({type:"product"},o),{context:{shopping:["checkout",0]},nested:[]}),_object_spread_props(_object_spread({type:"product"},a),{context:{shopping:["checkout",0]},nested:[]})],trigger:"load"},"order complete":{data:{id:"0rd3r1d",currency:"EUR",shipping:5.22,taxes:73.76,total:555},context:{shopping:["complete",0]},globals:{pagegroup:"shop"},nested:[_object_spread_props(_object_spread({type:"product"},o),{context:{shopping:["complete",0]},nested:[]}),_object_spread_props(_object_spread({type:"product"},a),{context:{shopping:["complete",0]},nested:[]}),{type:"gift",data:{name:"Surprise"},context:{shopping:["complete",0]},nested:[]}],trigger:"load"},"page view":{data:{domain:"www.example.com",title:"walkerOS documentation",referrer:"https://www.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":_object_spread_props(_object_spread({},o),{context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"}),"product view":_object_spread_props(_object_spread({},o),{context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"}),"product visible":{data:_object_spread_props(_object_spread({},o.data),{position:3,promo:!0}),context:{shopping:["discover",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"promotion visible":{data:{name:"Setting up tracking easily",position:"hero"},context:{ab_test:["engagement",0]},globals:{pagegroup:"homepage"},trigger:"visible"},"session start":{data:{id:"s3ss10n",start:r,isNew:!0,count:1,runs:1,isStart:!0,storage:!0,referrer:"",device:"c00k13"},user:{id:"us3r",device:"c00k13",session:"s3ss10n",hash:"h4sh",address:"street number",email:"user@example.com",phone:"+49 123 456 789",userAgent:"Mozilla...",browser:"Chrome",browserVersion:"90",deviceType:"desktop",language:"de-DE",country:"DE",region:"HH",city:"Hamburg",zip:"20354",timezone:"Berlin",os:"walkerOS",osVersion:"1.0",screenSize:"1337x420",ip:"127.0.0.0",internal:!0,custom:"value"}}}[e],t),{event:e}))},a=function(){var e=o("order complete");return["track","Purchase",{value:e.data.total,currency:"EUR",contents:e.nested.filter(function(e){return"product"===e.type}).map(function(e){return{id:e.data.id,quantity:1}}),content_type:"product",num_items:2},{eventID:e.id}]},i=function(){var e=o("product add");return["track","AddToCart",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]},c=function(){var e=o("cart view");return["track","InitiateCheckout",{currency:"EUR",value:e.data.value,contents:e.nested.filter(function(e){return"product"===e.type}).map(function(e){return{id:e.data.id,quantity:e.data.quantity}}),num_items:e.nested.filter(function(e){return"product"===e.type}).length},{eventID:e.id}]},u=function(){var e=o("product view");return["track","ViewContent",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]},s=Object.defineProperty,p=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,l=Object.prototype.hasOwnProperty,y=function(e,t){for(var r in t)s(e,r,{get:t[r],enumerable:!0})},_={};y(_,{DestinationMeta:function(){return v},default:function(){return C},destinationMeta:function(){return E},destinationMetaExamples:function(){return h}});var f=Object.getOwnPropertyNames,b=(e={"package.json":function(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.0.8",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return t||(0,e[f(e)[0]])((t={exports:{}}).exports,t),t.exports}),g={merge:!0,shallow:!0,extend:!0},m=b().version,v={},h={};y(h,{destinationMetaExamples:function(){return P}});var w={};y(w,{AddToCart:function(){return i},InitiateCheckout:function(){return c},Purchase:function(){return a},ViewContent:function(){return u}});var j={};y(j,{AddToCart:function(){return x},InitiateCheckout:function(){return S},Purchase:function(){return O},ViewContent:function(){return q},config:function(){return A}});var k,O={name:"Purchase",data:{map:{value:"data.total",currency:{value:"EUR"},contents:{loop:["nested",{condition:function(e){return r(e)&&"product"===e.type},map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"},num_items:{fn:function(e){return e.nested.filter(function(e){return"product"===e.type}).length}}}}},x={name:"AddToCart",data:{map:{value:"data.price",currency:{value:"EUR"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"}}}},S={name:"InitiateCheckout",data:{map:{value:"data.value",currency:{value:"EUR"},contents:{loop:["nested",{condition:function(e){return r(e)&&"product"===e.type},map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:function(e){return e.nested.filter(function(e){return"product"===e.type}).length}}}}},q={name:"ViewContent",data:{map:{value:"data.price",currency:{value:"EUR"},content_type:{value:"product"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]}}}},A={order:{complete:O},product:{view:q,add:x},cart:{view:S}},P={events:w,mapping:j},E={type:"meta-pixel",config:{},init:function(e){var t=e.config,r=e.wrap,n=t.settings,o=void 0===n?{}:n,a=t.loadScript,i=o.pixelId;if(a&&function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"https://connect.facebook.net/en_US/fbevents.js",t=document.createElement("script");t.src=e,t.async=!0,document.head.appendChild(t)}(),!i)return!1;!function(){var e=window;if(!e.fbq){var t=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];t.callMethod?t.callMethod.apply(t,r):t.queue.push(r)};e.fbq=t,e._fbq||(e._fbq=t),t.push=t,t.loaded=!0,t.version="2.0",t.queue=[]}}(),r("fbq",window.fbq)("init",i)},push:function(e,t){t.config;var n=t.mapping,o=void 0===n?{}:n,a=t.data,i=t.wrap,c=o.settings||{},u=c.track,s=c.trackCustom,p=i("fbq",window.fbq);"page view"!==e.event||o.settings||(e.event="PageView");var d=u||s||e.event;p(s?"trackCustom":"track",String(d),r(a)?a:{},{eventID:e.id})}},C=E;return k=_,function(e,t,r,n){if(t&&"object"===(void 0===t?"undefined":_type_of(t))||"function"==typeof t){var o=!0,a=!1,i=void 0;try{for(var c,u=function(){var o=c.value;l.call(e,o)||o===r||s(e,o,{get:function(){return t[o]},enumerable:!(n=p(t,o))||n.enumerable})},y=d(t)[Symbol.iterator]();!(o=(c=y.next()).done);o=!0)u()}catch(e){a=!0,i=e}finally{try{o||null==y.return||y.return()}finally{if(a)throw i}}}return e}(s({},"__esModule",{value:!0}),k)}();