Web Publisher SDK
Last updated
Last updated
2.5 Intelligence's Web Publisher SDK is in private beta. to get started.
To use the SDK, you must have your account name (twofivedev_account
) and placement IDs. If you do not have these, please to get started.
Add the following JS snippet to your website:
<script type="text/javascript">
var twofivedev_account = 'YOUR_ACCOUNT_HERE'; // Required for twofivedev SDK
!function(){function t(t){return t&&t.__esModule?t.default:t}function e(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))}}var n={},o=function(t){"use strict";var e,r=function(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]},n=function(t,e,r,n){var o=e&&e.prototype instanceof i?e:i,a=Object.create(o.prototype),c=new p(n||[]);return a._invoke=f(t,r,c),a},o=function(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}},i=function(){},a=function(){},c=function(){},u=function(t){["next","throw","return"].forEach((function(e){r(t,e,(function(t){return this._invoke(e,t)}))}))},s=function(t,e){function r(n,i,a,c){var u=o(t[n],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==typeof f&&w.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var n;this._invoke=function(t,o){function i(){return new e((function(e,n){r(t,o,e,n)}))}return n=n?n.then(i,i):i()}},f=function(t,e,r){var n=L;return function(i,a){if(n===_)throw new Error("Generator is already running");if(n===j){if("throw"===i)throw a;return d()}for(r.method=i,r.arg=a;;){var c=r.delegate;if(c){var u=N(c,r);if(u){if(u===k)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===L)throw n=j,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=_;var s=o(t,e,r);if("normal"===s.type){if(n=r.done?j:E,s.arg===k)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=j,r.method="throw",r.arg=s.arg)}}},h=function(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)},l=function(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e},p=function(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(h,this),this.reset(!0)},v=function(t){if(t){var r=t[m];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function r(){for(;++n<t.length;)if(w.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}return{next:d}},d=function(){return{value:e,done:!0}},y=Object.prototype,w=y.hasOwnProperty,g="function"==typeof Symbol?Symbol:{},m=g.iterator||"@@iterator",x=g.asyncIterator||"@@asyncIterator",b=g.toStringTag||"@@toStringTag";try{r({},"")}catch(t){r=function(t,e,r){return t[e]=r}}t.wrap=n;var L="suspendedStart",E="suspendedYield",_="executing",j="completed",k={},O={};r(O,m,(function(){return this}));var S=Object.getPrototypeOf,G=S&&S(S(v([])));G&&G!==y&&w.call(G,m)&&(O=G);var P=c.prototype=i.prototype=Object.create(O);function N(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,N(t,r),"throw"===r.method))return k;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return k}var i=o(n,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,k;var a=i.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,k):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,k)}return a.prototype=c,r(P,"constructor",c),r(c,"constructor",a),a.displayName=r(c,b,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===a||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,c):(t.__proto__=c,r(t,b,"GeneratorFunction")),t.prototype=Object.create(P),t},t.awrap=function(t){return{__await:t}},u(s.prototype),r(s.prototype,x,(function(){return this})),t.AsyncIterator=s,t.async=function(e,r,o,i,a){void 0===a&&(a=Promise);var c=new s(n(e,r,o,i),a);return t.isGeneratorFunction(r)?c:c.next().then((function(t){return t.done?t.value:c.next()}))},u(P),r(P,b,"Generator"),r(P,m,(function(){return this})),r(P,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=v,p.prototype={constructor:p,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(l),!t)for(var r in this)"t"===r.charAt(0)&&w.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){var r=function(r,o){return a.type="throw",a.arg=t,n.next=r,o&&(n.method="next",n.arg=e),!!o};if(this.done)throw t;for(var n=this,o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=w.call(i,"catchLoc"),u=w.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&w.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,k):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),k},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),l(r),k}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;l(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:v(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),k}},t}(n);try{regeneratorRuntime=o}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=o:Function("r","regeneratorRuntime = r")(o)}r(t(n).mark((function e(){var o,i;return t(n).wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("undefined"!=typeof twofivedev_account){e.next=3;break}return console.error("twofivedev SDK error: missing account. Please set twofivedev_account."),e.abrupt("return");case 3:o=function(){var e=r(t(n).mark((function e(){var r;return t(n).wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,fetch("".concat("https://serve.5.dev","/pids?account=").concat(twofivedev_account),{method:"GET",headers:{accept:"application/json"}});case 3:return r=t.sent,t.next=6,r.json();case 6:window.twofivedev.placements=t.sent,window.twofivedev.readyState="ready",t.next=16;break;case 10:t.prev=10,t.t0=t.catch(0),console.error("twofivedev SDK error: failed to load placements",t.t0),window.twofivedev.placements=[],window.twofivedev.readyState="error",window.twofivedev.error=t.t0;case 16:case"end":return t.stop()}}),e,null,[[0,10]])})));return function(){return e.apply(this,arguments)}}(),(i=document.createElement("script")).onload=function(){},i.src="https://publisher.5.dev/sdk.js",document.head.appendChild(i),window.twofivedev={account:twofivedev_account,initializer:o(),readyState:"loading"};case 9:case"end":return e.stop()}}),e)})))()}();
</script>
For each of your placements, add an element on your site with id=<placement id>. For example, for a centered, non-sticky placement with ID sample_LB_1
and size 728x90, you can add the following to your site:
<div
id="sample_LB_1"
style="margin: 0 auto;height:90px;width:728px"
data-address="WALLET_ADDRESSS_HERE"
></div>
data-address
is the wallet address of the current user. It is optional but will help us serve a more relevant ad to the user.
That's it! The SDK will fill in the placement with a relevant ad.