@plattar/plattar-ar-adapter 1.115.2 → 1.116.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/build/es2015/plattar-ar-adapter.js +1059 -814
- package/build/es2015/plattar-ar-adapter.min.js +1 -1
- package/build/es2019/plattar-ar-adapter.js +399 -245
- package/build/es2019/plattar-ar-adapter.min.js +1 -1
- package/dist/ar/product-ar.d.ts +1 -1
- package/dist/ar/product-ar.js +29 -21
- package/dist/util/util.d.ts +0 -1
- package/dist/util/util.js +0 -15
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -3
- package/dist/analytics/analytics.d.ts +0 -10
- package/dist/analytics/analytics.js +0 -92
- package/dist/util/basic-http.d.ts +0 -6
- package/dist/util/basic-http.js +0 -38
package/dist/ar/product-ar.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { LauncherAR } from "./launcher-ar";
|
|
|
3
3
|
* Performs AR functionality related to Plattar Products and Variation types
|
|
4
4
|
*/
|
|
5
5
|
export declare class ProductAR extends LauncherAR {
|
|
6
|
-
private
|
|
6
|
+
private _analytics;
|
|
7
7
|
private readonly _productID;
|
|
8
8
|
private readonly _variationID;
|
|
9
9
|
private _ar;
|
package/dist/ar/product-ar.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ProductAR = void 0;
|
|
7
7
|
const plattar_api_1 = require("@plattar/plattar-api");
|
|
8
|
-
const
|
|
8
|
+
const plattar_analytics_1 = require("@plattar/plattar-analytics");
|
|
9
9
|
const util_1 = require("../util/util");
|
|
10
10
|
const quicklook_viewer_1 = __importDefault(require("../viewers/quicklook-viewer"));
|
|
11
11
|
const reality_viewer_1 = __importDefault(require("../viewers/reality-viewer"));
|
|
@@ -17,12 +17,13 @@ const launcher_ar_1 = require("./launcher-ar");
|
|
|
17
17
|
class ProductAR extends launcher_ar_1.LauncherAR {
|
|
18
18
|
constructor(productID = null, variationID = null) {
|
|
19
19
|
super();
|
|
20
|
+
// analytics instance
|
|
21
|
+
this._analytics = null;
|
|
20
22
|
if (!productID) {
|
|
21
23
|
throw new Error("ProductAR.constructor(productID, variationID) - productID must be defined");
|
|
22
24
|
}
|
|
23
25
|
this._productID = productID;
|
|
24
26
|
this._variationID = variationID ? variationID : "default";
|
|
25
|
-
this._analytics = new analytics_1.default();
|
|
26
27
|
this._ar = null;
|
|
27
28
|
}
|
|
28
29
|
get productID() {
|
|
@@ -32,27 +33,32 @@ class ProductAR extends launcher_ar_1.LauncherAR {
|
|
|
32
33
|
return this._variationID;
|
|
33
34
|
}
|
|
34
35
|
_setupAnalytics(product, variation) {
|
|
35
|
-
|
|
36
|
+
let analytics = null;
|
|
36
37
|
const scene = product.relationships.find(plattar_api_1.Scene);
|
|
37
38
|
// setup scene stuff (if any)
|
|
38
39
|
if (scene) {
|
|
39
|
-
analytics.
|
|
40
|
-
analytics.
|
|
40
|
+
analytics = new plattar_analytics_1.Analytics(scene.attributes.application_id);
|
|
41
|
+
analytics.origin = plattar_api_1.Server.location().type;
|
|
42
|
+
this._analytics = analytics;
|
|
43
|
+
analytics.data.push("sceneId", scene.id);
|
|
44
|
+
analytics.data.push("sceneTitle", scene.attributes.title);
|
|
41
45
|
const application = scene.relationships.find(plattar_api_1.Project);
|
|
42
46
|
// setup application stuff (if any)
|
|
43
47
|
if (application) {
|
|
44
|
-
analytics.push("applicationId", application.id);
|
|
45
|
-
analytics.push("applicationTitle", application.attributes.title);
|
|
48
|
+
analytics.data.push("applicationId", application.id);
|
|
49
|
+
analytics.data.push("applicationTitle", application.attributes.title);
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
if (analytics) {
|
|
53
|
+
// set product stuff
|
|
54
|
+
analytics.data.push("productId", product.id);
|
|
55
|
+
analytics.data.push("productTitle", product.attributes.title);
|
|
56
|
+
analytics.data.push("productSKU", product.attributes.sku);
|
|
57
|
+
// set variation stuff
|
|
58
|
+
analytics.data.push("variationId", variation.id);
|
|
59
|
+
analytics.data.push("variationTitle", variation.attributes.title);
|
|
60
|
+
analytics.data.push("variationSKU", variation.attributes.sku);
|
|
61
|
+
}
|
|
56
62
|
}
|
|
57
63
|
/**
|
|
58
64
|
* Initialise the ProductAR instance. This returns a Promise that resolves
|
|
@@ -144,14 +150,16 @@ class ProductAR extends launcher_ar_1.LauncherAR {
|
|
|
144
150
|
if (!this._ar) {
|
|
145
151
|
throw new Error("ProductAR.start() - cannot proceed as AR instance is null");
|
|
146
152
|
}
|
|
153
|
+
const analytics = this._analytics;
|
|
154
|
+
if (analytics) {
|
|
155
|
+
analytics.data.push("device", this._ar.device);
|
|
156
|
+
analytics.data.push("eventCategory", this._ar.nodeType);
|
|
157
|
+
analytics.data.push("eventAction", "Start Augment");
|
|
158
|
+
analytics.write();
|
|
159
|
+
analytics.startRecordEngagement();
|
|
160
|
+
}
|
|
147
161
|
// this was initialised via the init() function
|
|
148
162
|
this._ar.start();
|
|
149
|
-
this._analytics.track({
|
|
150
|
-
device: this._ar.device,
|
|
151
|
-
eventCategory: this._ar.nodeType,
|
|
152
|
-
eventAction: "Start Augment"
|
|
153
|
-
});
|
|
154
|
-
this._analytics.startRecordEngagement();
|
|
155
163
|
}
|
|
156
164
|
}
|
|
157
165
|
exports.ProductAR = ProductAR;
|
package/dist/util/util.d.ts
CHANGED
package/dist/util/util.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Util = void 0;
|
|
4
|
-
const _lut = [];
|
|
5
|
-
for (let i = 0; i < 256; i++) {
|
|
6
|
-
_lut[i] = (i < 16 ? '0' : '') + (i).toString(16);
|
|
7
|
-
}
|
|
8
4
|
/**
|
|
9
5
|
* Static Utility Functions
|
|
10
6
|
*/
|
|
@@ -54,17 +50,6 @@ class Util {
|
|
|
54
50
|
}
|
|
55
51
|
return false;
|
|
56
52
|
}
|
|
57
|
-
static generateUUID() {
|
|
58
|
-
const d0 = Math.random() * 0xffffffff | 0;
|
|
59
|
-
const d1 = Math.random() * 0xffffffff | 0;
|
|
60
|
-
const d2 = Math.random() * 0xffffffff | 0;
|
|
61
|
-
const d3 = Math.random() * 0xffffffff | 0;
|
|
62
|
-
const uuid = _lut[d0 & 0xff] + _lut[d0 >> 8 & 0xff] + _lut[d0 >> 16 & 0xff] + _lut[d0 >> 24 & 0xff] + '-' +
|
|
63
|
-
_lut[d1 & 0xff] + _lut[d1 >> 8 & 0xff] + '-' + _lut[d1 >> 16 & 0x0f | 0x40] + _lut[d1 >> 24 & 0xff] + '-' +
|
|
64
|
-
_lut[d2 & 0x3f | 0x80] + _lut[d2 >> 8 & 0xff] + '-' + _lut[d2 >> 16 & 0xff] + _lut[d2 >> 24 & 0xff] +
|
|
65
|
-
_lut[d3 & 0xff] + _lut[d3 >> 8 & 0xff] + _lut[d3 >> 16 & 0xff] + _lut[d3 >> 24 & 0xff];
|
|
66
|
-
return uuid.toLowerCase();
|
|
67
|
-
}
|
|
68
53
|
static getIOSVersion() {
|
|
69
54
|
if (/iP(hone|od|ad)/.test(navigator.platform)) {
|
|
70
55
|
const v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.116.1";
|
|
2
2
|
export default _default;
|
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plattar/plattar-ar-adapter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.116.1",
|
|
4
4
|
"description": "Plattar AR Adapter for interfacing with Google & Apple WebAR",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -37,12 +37,13 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://www.plattar.com",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@plattar/plattar-
|
|
40
|
+
"@plattar/plattar-analytics": "^1.116.2",
|
|
41
|
+
"@plattar/plattar-api": "^1.115.2",
|
|
41
42
|
"@plattar/plattar-qrcode": "1.114.1",
|
|
42
43
|
"@plattar/plattar-web": "^1.113.10"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@babel/cli": "^7.15.
|
|
46
|
+
"@babel/cli": "^7.15.7",
|
|
46
47
|
"@babel/core": "^7.15.5",
|
|
47
48
|
"@babel/preset-env": "^7.15.6",
|
|
48
49
|
"browserify": "^17.0.0",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default class Analytics {
|
|
2
|
-
private readonly _map;
|
|
3
|
-
constructor();
|
|
4
|
-
track(dataSet?: any | undefined | null): void;
|
|
5
|
-
pageview(dataSet?: any | undefined | null): void;
|
|
6
|
-
private _send;
|
|
7
|
-
push(key: string, value: any): void;
|
|
8
|
-
getUserID(): string;
|
|
9
|
-
startRecordEngagement(): void;
|
|
10
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const util_1 = require("../util/util");
|
|
4
|
-
const plattar_api_1 = require("@plattar/plattar-api");
|
|
5
|
-
class Analytics {
|
|
6
|
-
constructor() {
|
|
7
|
-
this._map = new Map();
|
|
8
|
-
this.push("source", "embed");
|
|
9
|
-
this.push("pageTitle", document.title);
|
|
10
|
-
this.push("pageURL", location.href);
|
|
11
|
-
this.push("referrer", document.referrer);
|
|
12
|
-
this.push("user_id", this.getUserID());
|
|
13
|
-
}
|
|
14
|
-
track(dataSet = null) {
|
|
15
|
-
this._send("track", dataSet);
|
|
16
|
-
}
|
|
17
|
-
pageview(dataSet = null) {
|
|
18
|
-
this._send("pageview", dataSet);
|
|
19
|
-
}
|
|
20
|
-
_send(event, dataSet = null) {
|
|
21
|
-
const url = plattar_api_1.Server.location().analytics;
|
|
22
|
-
const data = dataSet || {};
|
|
23
|
-
const dims = Object.fromEntries(this._map);
|
|
24
|
-
const cData = Object.assign(data, dims);
|
|
25
|
-
const analytic = {
|
|
26
|
-
event: event,
|
|
27
|
-
origin: plattar_api_1.Server.location().type,
|
|
28
|
-
application_id: cData.applicationId,
|
|
29
|
-
data: cData
|
|
30
|
-
};
|
|
31
|
-
// NOTE - Consider switching this to navigator.sendBeacon which is designed
|
|
32
|
-
// for sending analytics data even when page is unloaded
|
|
33
|
-
// see https://stackoverflow.com/questions/40523469/navigator-sendbeacon-to-pass-header-information
|
|
34
|
-
// see https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API
|
|
35
|
-
try {
|
|
36
|
-
const xmlhttp = new XMLHttpRequest();
|
|
37
|
-
xmlhttp.open("POST", url);
|
|
38
|
-
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
|
39
|
-
xmlhttp.send(JSON.stringify(analytic));
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
console.error("Analytics.send(" + event + ") - Error during POST - " + err);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
push(key, value) {
|
|
46
|
-
this._map.set(key, value);
|
|
47
|
-
}
|
|
48
|
-
getUserID() {
|
|
49
|
-
const key = "plattar_user_id";
|
|
50
|
-
let userID = null;
|
|
51
|
-
try {
|
|
52
|
-
userID = localStorage.getItem(key);
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
userID = util_1.Util.generateUUID();
|
|
56
|
-
// try storing if just generated
|
|
57
|
-
try {
|
|
58
|
-
localStorage.setItem(key, userID);
|
|
59
|
-
}
|
|
60
|
-
catch (_err) { /* silent */ }
|
|
61
|
-
}
|
|
62
|
-
if (!userID) {
|
|
63
|
-
userID = util_1.Util.generateUUID();
|
|
64
|
-
// try storing if just generated
|
|
65
|
-
try {
|
|
66
|
-
localStorage.setItem(key, userID);
|
|
67
|
-
}
|
|
68
|
-
catch (_err) { /*silent */ }
|
|
69
|
-
}
|
|
70
|
-
return userID;
|
|
71
|
-
}
|
|
72
|
-
startRecordEngagement() {
|
|
73
|
-
let time;
|
|
74
|
-
const handlePageHide = () => {
|
|
75
|
-
if (document.visibilityState === "hidden") {
|
|
76
|
-
time = new Date();
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
const time2 = new Date();
|
|
80
|
-
const diff = time2.getTime() - time.getTime();
|
|
81
|
-
this.track({
|
|
82
|
-
eventAction: "View Time",
|
|
83
|
-
viewTime: diff,
|
|
84
|
-
eventLabel: diff
|
|
85
|
-
});
|
|
86
|
-
document.removeEventListener("visibilitychange", handlePageHide, false);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
document.addEventListener("visibilitychange", handlePageHide, false);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.default = Analytics;
|
package/dist/util/basic-http.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Simple HTTP interaction module
|
|
5
|
-
*/
|
|
6
|
-
class BasicHTTP {
|
|
7
|
-
static get(protocol, path) {
|
|
8
|
-
return new Promise((accept, reject) => {
|
|
9
|
-
try {
|
|
10
|
-
const http = new XMLHttpRequest();
|
|
11
|
-
http.open(protocol, path, true);
|
|
12
|
-
http.onload = (e) => {
|
|
13
|
-
if (http.status === 200) {
|
|
14
|
-
if (http.response) {
|
|
15
|
-
try {
|
|
16
|
-
const resp = JSON.parse(http.response);
|
|
17
|
-
return accept(resp);
|
|
18
|
-
}
|
|
19
|
-
catch (_err) { /* silent */ }
|
|
20
|
-
}
|
|
21
|
-
return accept({});
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
return reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
http.onerror = (e) => {
|
|
28
|
-
return reject(e);
|
|
29
|
-
};
|
|
30
|
-
http.send(null);
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
return reject(e);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.default = BasicHTTP;
|