@bigbeakads/smartads-sdk-js 0.0.1

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 ADDED
@@ -0,0 +1,79 @@
1
+ # SmartAds SDK for JavaScript
2
+
3
+ Lightweight JavaScript SDK for SmartAds event tracking and attribution reporting. Supports both **ES Module** and **UMD** formats, works seamlessly in modern frameworks and vanilla HTML pages.
4
+
5
+ ## Quick Start
6
+
7
+ ### ES Module
8
+
9
+ ```bash
10
+ npm install @bigbeakads/smartads-sdk-js
11
+ ```
12
+
13
+ ```js
14
+ import SmartAds from '@bigbeakads/smartads-sdk-js';
15
+
16
+ const smartAds = new SmartAds({
17
+ accessToken: 'YOUR_ACCESS_TOKEN',
18
+ });
19
+
20
+ await smartAds.report({ eventName: 'EVENT_CONTENT_VIEW' });
21
+ ```
22
+
23
+ ### UMD (Script Tag)
24
+
25
+ ```html
26
+ <script src="https://unpkg.com/@bigbeakads/smartads-sdk-js/dist/umd/smartads-sdk-js.min.js"></script>
27
+ <script>
28
+ var smartAds = new SmartAds({
29
+ accessToken: 'YOUR_ACCESS_TOKEN',
30
+ });
31
+
32
+ smartAds.report({ eventName: 'EVENT_CONTENT_VIEW' });
33
+ </script>
34
+ ```
35
+
36
+ ## API Reference
37
+
38
+ ### `new SmartAds(options)`
39
+
40
+ Creates a SmartAds SDK instance.
41
+
42
+ | Parameter | Type | Required | Description |
43
+ | --------------------- | -------- | -------- | ----------------------------- |
44
+ | `options.accessToken` | `string` | **Yes** | Your application access token |
45
+
46
+ ### `smartAds.report(options)`
47
+
48
+ Reports an event to the SmartAds server. Returns a `Promise<Response>`. Supports both Promise and callback patterns.
49
+
50
+ #### Parameters
51
+
52
+ | Parameter | Type | Required | Default | Description |
53
+ | ----------- | ---------------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
+ | `eventName` | `EventName` | **Yes** | — | The event name to report. Supported values: `EVENT_ADD_TO_CART`, `EVENT_PURCHASE`, `EVENT_CONTENT_VIEW`, `EVENT_COMPLETE_REGISTRATION`, `EVENT_FIRST_DEPOSIT` |
55
+ | `callback` | `(response, error?) => void` | No | — | Response-first callback |
56
+
57
+ #### Promise Usage
58
+
59
+ ```js
60
+ const response = await smartAds.report({
61
+ eventName: 'EVENT_PURCHASE',
62
+ });
63
+ console.log('Response:', response);
64
+ ```
65
+
66
+ #### Callback Usage
67
+
68
+ ```js
69
+ smartAds.report({
70
+ eventName: 'EVENT_PURCHASE',
71
+ callback: (response, error) => {
72
+ if (error) {
73
+ console.error('Report failed:', error.message);
74
+ return;
75
+ }
76
+ console.log('Response:', response);
77
+ },
78
+ });
79
+ ```
@@ -0,0 +1,25 @@
1
+ type EventName = 'EVENT_ADD_TO_CART' | 'EVENT_PURCHASE' | 'EVENT_CONTENT_VIEW' | 'EVENT_COMPLETE_REGISTRATION' | 'EVENT_FIRST_DEPOSIT';
2
+ interface SmartAdsOptions {
3
+ accessToken: string;
4
+ }
5
+ interface ReportCallback {
6
+ (response: Response | null, error?: Error): void;
7
+ }
8
+ interface KwaiReportOptions {
9
+ eventName: EventName;
10
+ callback?: ReportCallback;
11
+ }
12
+ interface TTReportOptions {
13
+ eventName: EventName;
14
+ callback?: ReportCallback;
15
+ }
16
+ type ReportOptions = KwaiReportOptions | TTReportOptions;
17
+ declare class SmartAds {
18
+ private accessToken;
19
+ constructor(options: SmartAdsOptions);
20
+ private reportKwai;
21
+ private reportTT;
22
+ report(options: ReportOptions): Promise<Response>;
23
+ }
24
+ export { SmartAds, type EventName };
25
+ export default SmartAds;
@@ -0,0 +1,150 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(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); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(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), y; }, finish: function finish(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), resetTryEntry(r), y; } }, catch: function _catch(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; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
+ var POSTBACK_URL = 'https://agent.ads-server-k.com/smartads/api/v1/postback/kwai';
12
+ function getUrlParam(name) {
13
+ try {
14
+ var url = new URL(window.location.href);
15
+ return url.searchParams.get(name) || '';
16
+ } catch (_unused) {
17
+ return '';
18
+ }
19
+ }
20
+ var SmartAds = /*#__PURE__*/function () {
21
+ function SmartAds(options) {
22
+ _classCallCheck(this, SmartAds);
23
+ _defineProperty(this, "accessToken", void 0);
24
+ if (!options.accessToken) {
25
+ throw new Error('accessToken is required');
26
+ }
27
+ this.accessToken = options.accessToken;
28
+ }
29
+ _createClass(SmartAds, [{
30
+ key: "reportKwai",
31
+ value: function reportKwai(options) {
32
+ var eventName = options.eventName;
33
+ if (!eventName) {
34
+ throw new Error('eventName is required');
35
+ }
36
+ var clickid = getUrlParam('click_id');
37
+ var pixelId = getUrlParam('pixel_id');
38
+ if (!clickid) {
39
+ throw new Error('click_id is required in URL parameters');
40
+ }
41
+ if (!pixelId) {
42
+ throw new Error('pixel_id is required in URL parameters');
43
+ }
44
+ var payload = {
45
+ access_token: this.accessToken,
46
+ event_name: eventName,
47
+ clickid: clickid,
48
+ pixelId: pixelId,
49
+ is_attributed: 1,
50
+ mmpcode: 'PL',
51
+ pixelSdkVersion: '9.9.9',
52
+ testFlag: false,
53
+ trackFlag: false,
54
+ properties: '{}'
55
+ };
56
+ return fetch(POSTBACK_URL, {
57
+ method: 'POST',
58
+ headers: {
59
+ 'Content-Type': 'application/json'
60
+ },
61
+ body: JSON.stringify(payload)
62
+ }).then( /*#__PURE__*/function () {
63
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(response) {
64
+ var json;
65
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
66
+ while (1) switch (_context.prev = _context.next) {
67
+ case 0:
68
+ _context.next = 2;
69
+ return response.json();
70
+ case 2:
71
+ json = _context.sent;
72
+ if (!(json.result === 1)) {
73
+ _context.next = 7;
74
+ break;
75
+ }
76
+ return _context.abrupt("return", json);
77
+ case 7:
78
+ throw new Error(json);
79
+ case 8:
80
+ case "end":
81
+ return _context.stop();
82
+ }
83
+ }, _callee);
84
+ }));
85
+ return function (_x) {
86
+ return _ref.apply(this, arguments);
87
+ };
88
+ }()).catch(function (error) {
89
+ console.error('Error reporting event:', error);
90
+ throw error;
91
+ });
92
+ }
93
+ }, {
94
+ key: "reportTT",
95
+ value: function reportTT(options) {
96
+ // TODO: TT postback logic
97
+ throw new Error('TT report not implemented');
98
+ }
99
+ }, {
100
+ key: "report",
101
+ value: function () {
102
+ var _report = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
103
+ var callback, isTT, _response, _error;
104
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
105
+ while (1) switch (_context2.prev = _context2.next) {
106
+ case 0:
107
+ callback = options.callback;
108
+ isTT = !!getUrlParam('ttclid');
109
+ _context2.prev = 2;
110
+ if (!isTT) {
111
+ _context2.next = 9;
112
+ break;
113
+ }
114
+ _context2.next = 6;
115
+ return this.reportTT(options);
116
+ case 6:
117
+ _context2.t0 = _context2.sent;
118
+ _context2.next = 12;
119
+ break;
120
+ case 9:
121
+ _context2.next = 11;
122
+ return this.reportKwai(options);
123
+ case 11:
124
+ _context2.t0 = _context2.sent;
125
+ case 12:
126
+ _response = _context2.t0;
127
+ callback === null || callback === void 0 || callback(_response, undefined);
128
+ return _context2.abrupt("return", _response);
129
+ case 17:
130
+ _context2.prev = 17;
131
+ _context2.t1 = _context2["catch"](2);
132
+ _error = _context2.t1 instanceof Error ? _context2.t1 : new Error(String(_context2.t1));
133
+ callback === null || callback === void 0 || callback(null, _error);
134
+ throw _error;
135
+ case 22:
136
+ case "end":
137
+ return _context2.stop();
138
+ }
139
+ }, _callee2, this, [[2, 17]]);
140
+ }));
141
+ function report(_x2) {
142
+ return _report.apply(this, arguments);
143
+ }
144
+ return report;
145
+ }()
146
+ }]);
147
+ return SmartAds;
148
+ }();
149
+ export { SmartAds };
150
+ export default SmartAds;
@@ -0,0 +1 @@
1
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(self,(function(){return function(){var t={935:function(t){function e(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function u(t){e(a,o,i,u,c,"next",t)}function c(t){e(a,o,i,u,c,"throw",t)}u(void 0)}))}},t.exports.__esModule=!0,t.exports.default=t.exports},76:function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.__esModule=!0,t.exports.default=t.exports},81:function(t,e,r){var n=r(355);function o(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,n(o.key),o)}}t.exports=function(t,e,r){return e&&o(t.prototype,e),r&&o(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t},t.exports.__esModule=!0,t.exports.default=t.exports},951:function(t,e,r){var n=r(355);t.exports=function(t,e,r){return(e=n(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.__esModule=!0,t.exports.default=t.exports},958:function(t,e,r){var n=r(705).default;function o(){"use strict";t.exports=o=function(){return r},t.exports.__esModule=!0,t.exports.default=t.exports;var e,r={},i=Object.prototype,a=i.hasOwnProperty,u=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",f=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function p(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(e){p=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),a=new N(n||[]);return u(i,"_invoke",{value:S(t,r,a)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}r.wrap=h;var v="suspendedStart",y="executing",m="completed",x={};function w(){}function g(){}function b(){}var _={};p(_,s,(function(){return this}));var E=Object.getPrototypeOf,k=E&&E(E(G([])));k&&k!==i&&a.call(k,s)&&(_=k);var L=b.prototype=w.prototype=Object.create(_);function j(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,u,c){var s=d(t[o],t,i);if("throw"!==s.type){var f=s.arg,l=f.value;return l&&"object"==n(l)&&a.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,u,c)}),(function(t){r("throw",t,u,c)})):e.resolve(l).then((function(t){f.value=t,u(f)}),(function(t){return r("throw",t,u,c)}))}c(s.arg)}var o;u(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}})}function S(t,r,n){var o=v;return function(i,a){if(o===y)throw new Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:e,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=T(u,n);if(c){if(c===x)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===v)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var s=d(t,r,n);if("normal"===s.type){if(o=n.done?m:"suspendedYield",s.arg===x)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function T(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,T(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),x;var i=d(o,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,x;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,x):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,x)}function P(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)}function M(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function G(t){if(t||""===t){var r=t[s];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(a.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(n(t)+" is not iterable")}return g.prototype=b,u(L,"constructor",{value:b,configurable:!0}),u(b,"constructor",{value:g,configurable:!0}),g.displayName=p(b,l,"GeneratorFunction"),r.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,p(t,l,"GeneratorFunction")),t.prototype=Object.create(L),t},r.awrap=function(t){return{__await:t}},j(O.prototype),p(O.prototype,f,(function(){return this})),r.AsyncIterator=O,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new O(h(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},j(L),p(L,l,"Generator"),p(L,s,(function(){return this})),p(L,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=G,N.prototype={constructor:N,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(M),!t)for(var r in this)"t"===r.charAt(0)&&a.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){if(this.done)throw t;var r=this;function n(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),s=a.call(i,"finallyLoc");if(c&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(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&&a.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,x):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),x},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),M(r),x}},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;M(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:G(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),x}},r}t.exports=o,t.exports.__esModule=!0,t.exports.default=t.exports},388:function(t,e,r){var n=r(705).default;t.exports=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports},355:function(t,e,r){var n=r(705).default,o=r(388);t.exports=function(t){var e=o(t,"string");return"symbol"==n(e)?e:String(e)},t.exports.__esModule=!0,t.exports.default=t.exports},705:function(t){function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,{a:e}),e},r.d=function(t,e){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return function(){"use strict";r.r(n),r.d(n,{SmartAds:function(){return h}});var t=r(958),e=r.n(t),o=r(935),i=r.n(o),a=r(76),u=r.n(a),c=r(81),s=r.n(c),f=r(951),l=r.n(f);function p(t){try{return new URL(window.location.href).searchParams.get(t)||""}catch(t){return""}}var h=function(){function t(e){if(u()(this,t),l()(this,"accessToken",void 0),!e.accessToken)throw new Error("accessToken is required");this.accessToken=e.accessToken}var r;return s()(t,[{key:"reportKwai",value:function(t){var r=t.eventName;if(!r)throw new Error("eventName is required");var n=p("click_id"),o=p("pixel_id");if(!n)throw new Error("click_id is required in URL parameters");if(!o)throw new Error("pixel_id is required in URL parameters");var a={access_token:this.accessToken,event_name:r,clickid:n,pixelId:o,is_attributed:1,mmpcode:"PL",pixelSdkVersion:"9.9.9",testFlag:!1,trackFlag:!1,properties:"{}"};return fetch("https://agent.ads-server-k.com/smartads/api/v1/postback/kwai",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).then(function(){var t=i()(e()().mark((function t(r){var n;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,r.json();case 2:if(1!==(n=t.sent).result){t.next=7;break}return t.abrupt("return",n);case 7:throw new Error(n);case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()).catch((function(t){throw console.error("Error reporting event:",t),t}))}},{key:"reportTT",value:function(t){throw new Error("TT report not implemented")}},{key:"report",value:(r=i()(e()().mark((function t(r){var n,o,i,a;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.callback,o=!!p("ttclid"),t.prev=2,!o){t.next=9;break}return t.next=6,this.reportTT(r);case 6:t.t0=t.sent,t.next=12;break;case 9:return t.next=11,this.reportKwai(r);case 11:t.t0=t.sent;case 12:return i=t.t0,null==n||n(i,void 0),t.abrupt("return",i);case 17:throw t.prev=17,t.t1=t.catch(2),a=t.t1 instanceof Error?t.t1:new Error(String(t.t1)),null==n||n(null,a),a;case 22:case"end":return t.stop()}}),t,this,[[2,17]])}))),function(t){return r.apply(this,arguments)})}]),t}();n.default=h}(),n}()}));
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@bigbeakads/smartads-sdk-js",
3
+ "version": "0.0.1",
4
+ "description": "BigBeak Smart Ads SDK for JavaScript",
5
+ "module": "dist/esm/index.js",
6
+ "main": "dist/umd/index.min.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "scripts": {
9
+ "dev": "father dev",
10
+ "build": "father build",
11
+ "build:deps": "father prebundle",
12
+ "prepublishOnly": "father doctor && npm run build"
13
+ },
14
+ "keywords": [],
15
+ "authors": [],
16
+ "license": "MIT",
17
+ "files": [
18
+ "dist",
19
+ "compiled"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "devDependencies": {
25
+ "father": "^4.6.21"
26
+ }
27
+ }