zar 0.2.0 → 0.4.0
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/dist/zar.es.js +156 -34
- package/dist/zar.es.js.map +1 -1
- package/dist/zar.iife.js +2 -2
- package/dist/zar.iife.js.map +1 -1
- package/dist/zar.umd.js +2 -2
- package/dist/zar.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/zar.es.js
CHANGED
|
@@ -1349,7 +1349,7 @@ function dbg() {
|
|
|
1349
1349
|
return;
|
|
1350
1350
|
console.debug(...arguments);
|
|
1351
1351
|
}
|
|
1352
|
-
function
|
|
1352
|
+
function warn(msg) {
|
|
1353
1353
|
console.warn(msg);
|
|
1354
1354
|
if (window.Rollbar) {
|
|
1355
1355
|
window.Rollbar.warning(msg);
|
|
@@ -1488,7 +1488,7 @@ function postBeacon(_0) {
|
|
|
1488
1488
|
}
|
|
1489
1489
|
return false;
|
|
1490
1490
|
} catch (e2) {
|
|
1491
|
-
|
|
1491
|
+
warn("postBeacon:");
|
|
1492
1492
|
return false;
|
|
1493
1493
|
}
|
|
1494
1494
|
}
|
|
@@ -1527,6 +1527,9 @@ var NUMBER_POOL_RENEWAL_TIME_MS = 30 * 1e3;
|
|
|
1527
1527
|
var getNumberFailureCount = 0;
|
|
1528
1528
|
var MAX_GET_NUMBER_FAILURES = 3;
|
|
1529
1529
|
var poolIntervals = {};
|
|
1530
|
+
window.zarPoolData = window.zarPoolData || null;
|
|
1531
|
+
window.zarPoolDLObserverDone = window.zarPoolDLObserverDone || false;
|
|
1532
|
+
window.zarPoolDataLayer = window.zarPoolDataLayer || [];
|
|
1530
1533
|
var numberOverlayMap = /* @__PURE__ */ new Map();
|
|
1531
1534
|
function generateVisitId() {
|
|
1532
1535
|
return Date.now().toString(36) + "." + Math.random().toString(36).substring(2);
|
|
@@ -1554,7 +1557,7 @@ function initIDs() {
|
|
|
1554
1557
|
return { vid: vidResult };
|
|
1555
1558
|
}
|
|
1556
1559
|
function getDefaultApiUrl() {
|
|
1557
|
-
return window.location.host + "/api/
|
|
1560
|
+
return window.location.protocol + "://" + window.location.host + "/api/v2";
|
|
1558
1561
|
}
|
|
1559
1562
|
function getIDObj(key) {
|
|
1560
1563
|
return getSessionStorage(key);
|
|
@@ -1590,7 +1593,7 @@ function extractPhoneNumber({ elem }) {
|
|
|
1590
1593
|
}
|
|
1591
1594
|
return { text, html, numberText, href, number };
|
|
1592
1595
|
}
|
|
1593
|
-
function overlayPhoneNumber({ elems, number }) {
|
|
1596
|
+
function overlayPhoneNumber({ elems, number, force = false }) {
|
|
1594
1597
|
var origNum;
|
|
1595
1598
|
var overlayNum = number;
|
|
1596
1599
|
if (!number.startsWith("+1")) {
|
|
@@ -1598,17 +1601,23 @@ function overlayPhoneNumber({ elems, number }) {
|
|
|
1598
1601
|
}
|
|
1599
1602
|
for (var i2 = 0; i2 < elems.length; i2++) {
|
|
1600
1603
|
if (numberOverlayMap.has(elems[i2])) {
|
|
1601
|
-
|
|
1602
|
-
|
|
1604
|
+
if (force) {
|
|
1605
|
+
origNum = numberOverlayMap.get(elems[i2]);
|
|
1606
|
+
} else {
|
|
1607
|
+
dbg("element already in overlay map:", elems[i2]);
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1603
1610
|
}
|
|
1604
1611
|
var elemNum = extractPhoneNumber({ elem: elems[i2] });
|
|
1605
1612
|
if (!origNum) {
|
|
1606
1613
|
origNum = elemNum;
|
|
1607
|
-
} else if (elemNum.number && origNum.number && origNum.number !== elemNum.number) {
|
|
1608
|
-
|
|
1614
|
+
} else if (!force && elemNum.number && origNum.number && origNum.number !== elemNum.number) {
|
|
1615
|
+
warn("overlaying multiple numbers with a single number", origNum.number, elemNum.number);
|
|
1609
1616
|
}
|
|
1610
1617
|
dbg("overlaying", overlayNum, "on", elems[i2]);
|
|
1611
|
-
numberOverlayMap.
|
|
1618
|
+
if (!numberOverlayMap.has(elems[i2])) {
|
|
1619
|
+
numberOverlayMap.set(elems[i2], elemNum);
|
|
1620
|
+
}
|
|
1612
1621
|
if (elemNum.href) {
|
|
1613
1622
|
elems[i2].href = "tel:" + overlayNum;
|
|
1614
1623
|
}
|
|
@@ -1662,7 +1671,12 @@ function clearPoolIntervals() {
|
|
|
1662
1671
|
}
|
|
1663
1672
|
}
|
|
1664
1673
|
function getPoolNumber(_0) {
|
|
1665
|
-
return __async(this, arguments, function* ({
|
|
1674
|
+
return __async(this, arguments, function* ({
|
|
1675
|
+
poolId,
|
|
1676
|
+
apiUrl,
|
|
1677
|
+
number = null,
|
|
1678
|
+
context = null
|
|
1679
|
+
}) {
|
|
1666
1680
|
var payload = {
|
|
1667
1681
|
pool_id: poolId,
|
|
1668
1682
|
number,
|
|
@@ -1675,36 +1689,81 @@ function getPoolNumber(_0) {
|
|
|
1675
1689
|
return resp;
|
|
1676
1690
|
});
|
|
1677
1691
|
}
|
|
1692
|
+
function poolActive() {
|
|
1693
|
+
return window.zarPoolData && window.zarPoolData.status === NUMBER_POOL_SUCCESS && window.zarPoolData.number;
|
|
1694
|
+
}
|
|
1695
|
+
function drainPoolDataLayer() {
|
|
1696
|
+
if (!window.zarPoolDataLayer || !Array.isArray(window.zarPoolDataLayer)) {
|
|
1697
|
+
return {};
|
|
1698
|
+
}
|
|
1699
|
+
var mergedObject = {};
|
|
1700
|
+
for (var i2 = 0; i2 < window.zarPoolDataLayer.length; i2++) {
|
|
1701
|
+
var obj = window.zarPoolDataLayer[i2];
|
|
1702
|
+
for (var key in obj) {
|
|
1703
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
1704
|
+
mergedObject[key] = obj[key];
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
window.zarPoolDataLayer.length = 0;
|
|
1709
|
+
return mergedObject;
|
|
1710
|
+
}
|
|
1711
|
+
function updateTrackingNumberContext(_0) {
|
|
1712
|
+
return __async(this, arguments, function* ({
|
|
1713
|
+
apiUrl,
|
|
1714
|
+
poolId,
|
|
1715
|
+
number,
|
|
1716
|
+
context
|
|
1717
|
+
}) {
|
|
1718
|
+
if (!poolActive()) {
|
|
1719
|
+
warn("no valid pool data, not updating context");
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1722
|
+
var payload = {
|
|
1723
|
+
pool_id: poolId,
|
|
1724
|
+
number,
|
|
1725
|
+
context,
|
|
1726
|
+
properties: {
|
|
1727
|
+
zar: getStorage()
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
var resp = yield httpPost({ url: `${apiUrl}/update_number`, data: payload });
|
|
1731
|
+
return resp;
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1678
1734
|
function getPoolStats(_0) {
|
|
1679
1735
|
return __async(this, arguments, function* ({ apiUrl, key = null, with_contexts = false }) {
|
|
1680
1736
|
var params = {
|
|
1681
1737
|
key,
|
|
1682
1738
|
with_contexts
|
|
1683
1739
|
};
|
|
1684
|
-
var resp = yield httpGet({
|
|
1740
|
+
var resp = yield httpGet({
|
|
1741
|
+
url: `${apiUrl}/number_pool_stats`,
|
|
1742
|
+
params
|
|
1743
|
+
});
|
|
1685
1744
|
return resp;
|
|
1686
1745
|
});
|
|
1687
1746
|
}
|
|
1688
1747
|
function renewTrackingPool() {
|
|
1689
1748
|
return __async(this, arguments, function* ({
|
|
1690
|
-
poolId,
|
|
1691
|
-
number,
|
|
1692
1749
|
overlayElements,
|
|
1693
1750
|
apiUrl = getDefaultApiUrl(),
|
|
1694
1751
|
contextCallback = null
|
|
1695
1752
|
} = {}) {
|
|
1696
|
-
var context = {};
|
|
1753
|
+
var context = drainPoolDataLayer() || {};
|
|
1697
1754
|
if (contextCallback) {
|
|
1698
|
-
context = contextCallback() || {};
|
|
1755
|
+
context = contextCallback(context) || {};
|
|
1699
1756
|
}
|
|
1757
|
+
const poolId = window.zarPoolData.pool_id;
|
|
1758
|
+
const number = window.zarPoolData.number;
|
|
1700
1759
|
try {
|
|
1701
1760
|
var resp = yield getPoolNumber({ poolId, apiUrl, number, context });
|
|
1702
1761
|
} catch (e2) {
|
|
1703
1762
|
var msg = "error getting number: " + JSON.stringify(e2);
|
|
1704
|
-
|
|
1763
|
+
warn(msg);
|
|
1705
1764
|
getNumberFailureCount++;
|
|
1706
1765
|
if (getNumberFailureCount >= MAX_GET_NUMBER_FAILURES) {
|
|
1707
|
-
|
|
1766
|
+
warn("max failures, stopping pool");
|
|
1708
1767
|
clearPoolIntervals();
|
|
1709
1768
|
if (overlayElements) {
|
|
1710
1769
|
revertOverlayNumbers({ elems: overlayElements });
|
|
@@ -1713,8 +1772,18 @@ function renewTrackingPool() {
|
|
|
1713
1772
|
return { status: NUMBER_POOL_ERROR, msg };
|
|
1714
1773
|
}
|
|
1715
1774
|
if (resp.status === NUMBER_POOL_SUCCESS && resp.number) {
|
|
1775
|
+
var force = false;
|
|
1776
|
+
if (resp.number !== window.zarPoolData.number) {
|
|
1777
|
+
warn("number changed from " + window.zarPoolData.number + " to " + resp.number);
|
|
1778
|
+
window.zarPoolData.number = resp.number;
|
|
1779
|
+
force = true;
|
|
1780
|
+
}
|
|
1716
1781
|
if (overlayElements) {
|
|
1717
|
-
overlayPhoneNumber({
|
|
1782
|
+
overlayPhoneNumber({
|
|
1783
|
+
elems: overlayElements,
|
|
1784
|
+
number: resp.number,
|
|
1785
|
+
force
|
|
1786
|
+
});
|
|
1718
1787
|
}
|
|
1719
1788
|
} else {
|
|
1720
1789
|
if (overlayElements) {
|
|
@@ -1733,25 +1802,49 @@ function getPoolId(poolId) {
|
|
|
1733
1802
|
return poolId();
|
|
1734
1803
|
return poolId;
|
|
1735
1804
|
}
|
|
1805
|
+
function initPoolDataLayerObserver(apiUrl) {
|
|
1806
|
+
if (window.zarPoolDLObserverDone) {
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
if (!poolActive()) {
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
var originalPush = window.zarPoolDataLayer.push;
|
|
1813
|
+
window.zarPoolDataLayer.push = function(...args) {
|
|
1814
|
+
var result = originalPush.apply(this, args);
|
|
1815
|
+
var context = drainPoolDataLayer();
|
|
1816
|
+
if (!context) {
|
|
1817
|
+
return result;
|
|
1818
|
+
}
|
|
1819
|
+
updateTrackingNumberContext({
|
|
1820
|
+
apiUrl,
|
|
1821
|
+
poolId: window.zarPoolData.pool_id,
|
|
1822
|
+
number: window.zarPoolData.number,
|
|
1823
|
+
context
|
|
1824
|
+
});
|
|
1825
|
+
return result;
|
|
1826
|
+
};
|
|
1827
|
+
window.zarPoolDLObserverDone = true;
|
|
1828
|
+
}
|
|
1736
1829
|
function initTrackingPool() {
|
|
1737
1830
|
return __async(this, arguments, function* ({ poolData, poolConfig, apiUrl } = {}) {
|
|
1738
1831
|
var msg;
|
|
1739
1832
|
if (!poolConfig || !poolConfig.poolId || !poolConfig.overlayQuerySelector || !apiUrl) {
|
|
1740
1833
|
msg = "missing pool config: " + JSON.stringify(poolConfig);
|
|
1741
|
-
|
|
1834
|
+
warn(msg);
|
|
1742
1835
|
if (poolConfig.initCallback) {
|
|
1743
1836
|
poolConfig.initCallback({ status: NUMBER_POOL_ERROR, msg });
|
|
1744
1837
|
}
|
|
1745
1838
|
return poolIntervals;
|
|
1746
1839
|
}
|
|
1747
|
-
var context = {};
|
|
1840
|
+
var context = drainPoolDataLayer() || {};
|
|
1748
1841
|
if (poolConfig.contextCallback) {
|
|
1749
|
-
context = poolConfig.contextCallback() || {};
|
|
1842
|
+
context = poolConfig.contextCallback(context) || {};
|
|
1750
1843
|
}
|
|
1751
1844
|
var poolId = getPoolId(poolConfig.poolId);
|
|
1752
1845
|
if (!poolId) {
|
|
1753
1846
|
msg = "no pool ID";
|
|
1754
|
-
|
|
1847
|
+
warn(msg);
|
|
1755
1848
|
if (poolConfig.initCallback) {
|
|
1756
1849
|
poolConfig.initCallback({ status: NUMBER_POOL_ERROR, msg });
|
|
1757
1850
|
}
|
|
@@ -1762,19 +1855,25 @@ function initTrackingPool() {
|
|
|
1762
1855
|
poolData = yield getPoolNumber({ poolId, apiUrl, number: null, context });
|
|
1763
1856
|
} catch (e2) {
|
|
1764
1857
|
msg = "error getting number on init: " + JSON.stringify(e2);
|
|
1765
|
-
|
|
1858
|
+
warn(msg);
|
|
1766
1859
|
if (poolConfig.initCallback) {
|
|
1767
1860
|
poolConfig.initCallback({ status: NUMBER_POOL_ERROR, msg });
|
|
1768
1861
|
}
|
|
1769
1862
|
return poolIntervals;
|
|
1770
1863
|
}
|
|
1771
1864
|
}
|
|
1772
|
-
|
|
1865
|
+
window.zarPoolData = poolData;
|
|
1866
|
+
if (poolActive()) {
|
|
1867
|
+
try {
|
|
1868
|
+
initPoolDataLayerObserver(apiUrl);
|
|
1869
|
+
} catch (e2) {
|
|
1870
|
+
warn("data layer observer error: " + JSON.stringify(e2));
|
|
1871
|
+
}
|
|
1773
1872
|
afterDOMContentLoaded(function() {
|
|
1774
1873
|
var overlayElements = document.querySelectorAll(poolConfig.overlayQuerySelector);
|
|
1775
1874
|
if (!overlayElements) {
|
|
1776
1875
|
var msg2 = "No elems found for:" + poolConfig.overlayQuerySelector;
|
|
1777
|
-
|
|
1876
|
+
warn(msg2);
|
|
1778
1877
|
if (poolConfig.initCallback) {
|
|
1779
1878
|
poolConfig.initCallback({ status: NUMBER_POOL_ERROR, msg: msg2 });
|
|
1780
1879
|
}
|
|
@@ -1784,15 +1883,13 @@ function initTrackingPool() {
|
|
|
1784
1883
|
var interval = setInterval(function() {
|
|
1785
1884
|
try {
|
|
1786
1885
|
renewTrackingPool({
|
|
1787
|
-
poolId: poolData.pool_id,
|
|
1788
|
-
number: poolData.number,
|
|
1789
1886
|
overlayElements,
|
|
1790
1887
|
apiUrl,
|
|
1791
1888
|
contextCallback: poolConfig.contextCallback
|
|
1792
1889
|
});
|
|
1793
1890
|
} catch (e2) {
|
|
1794
1891
|
var msg3 = "error on interval: " + JSON.stringify(e2);
|
|
1795
|
-
|
|
1892
|
+
warn(msg3);
|
|
1796
1893
|
}
|
|
1797
1894
|
}, poolConfig.renewalInterval || NUMBER_POOL_RENEWAL_TIME_MS);
|
|
1798
1895
|
poolIntervals[poolData.pool_id] = interval;
|
|
@@ -1831,12 +1928,13 @@ function zar({ apiUrl, poolConfig }) {
|
|
|
1831
1928
|
var pcfg = config.poolConfig;
|
|
1832
1929
|
if (pcfg && pcfg.poolId) {
|
|
1833
1930
|
payload.properties.pool_id = getPoolId(pcfg.poolId);
|
|
1931
|
+
var context = drainPoolDataLayer() || {};
|
|
1834
1932
|
if (pcfg.contextCallback) {
|
|
1835
|
-
payload.properties.pool_context = pcfg.contextCallback() || {};
|
|
1933
|
+
payload.properties.pool_context = pcfg.contextCallback(context) || {};
|
|
1836
1934
|
}
|
|
1837
1935
|
}
|
|
1838
1936
|
} catch (e2) {
|
|
1839
|
-
|
|
1937
|
+
warn("error getting pool id: " + JSON.stringify(e2));
|
|
1840
1938
|
}
|
|
1841
1939
|
return payload;
|
|
1842
1940
|
},
|
|
@@ -1853,14 +1951,18 @@ function zar({ apiUrl, poolConfig }) {
|
|
|
1853
1951
|
} catch (e2) {
|
|
1854
1952
|
tries++;
|
|
1855
1953
|
if (tries >= maxTries) {
|
|
1856
|
-
|
|
1954
|
+
warn("error posting page: " + JSON.stringify(e2));
|
|
1857
1955
|
throw e2;
|
|
1858
1956
|
}
|
|
1859
1957
|
yield new Promise((r2) => setTimeout(r2, 1e3));
|
|
1860
1958
|
}
|
|
1861
1959
|
}
|
|
1862
1960
|
if (res && res.pool_data) {
|
|
1863
|
-
initTrackingPool({
|
|
1961
|
+
initTrackingPool({
|
|
1962
|
+
poolData: res.pool_data,
|
|
1963
|
+
poolConfig: config.poolConfig,
|
|
1964
|
+
apiUrl: config.apiUrl
|
|
1965
|
+
});
|
|
1864
1966
|
}
|
|
1865
1967
|
});
|
|
1866
1968
|
},
|
|
@@ -1907,6 +2009,16 @@ function zar({ apiUrl, poolConfig }) {
|
|
|
1907
2009
|
apiUrl: plugin.apiUrl()
|
|
1908
2010
|
});
|
|
1909
2011
|
},
|
|
2012
|
+
updateTrackingNumberContext({ number, context }) {
|
|
2013
|
+
var plugin = this.instance.plugins.zar;
|
|
2014
|
+
var poolConfig2 = plugin.poolConfig();
|
|
2015
|
+
return updateTrackingNumberContext({
|
|
2016
|
+
apiUrl: this.instance.plugins.zar.apiUrl(),
|
|
2017
|
+
poolId: getPoolId(poolConfig2.poolId),
|
|
2018
|
+
number,
|
|
2019
|
+
context
|
|
2020
|
+
});
|
|
2021
|
+
},
|
|
1910
2022
|
getPoolIntervals() {
|
|
1911
2023
|
return poolIntervals;
|
|
1912
2024
|
},
|
|
@@ -1931,12 +2043,22 @@ function zar({ apiUrl, poolConfig }) {
|
|
|
1931
2043
|
revertOverlayNumbers({ elems: overlayElements });
|
|
1932
2044
|
},
|
|
1933
2045
|
getPoolStats({ key = null, with_contexts = false }) {
|
|
1934
|
-
return getPoolStats({
|
|
2046
|
+
return getPoolStats({
|
|
2047
|
+
apiUrl: this.instance.plugins.zar.apiUrl(),
|
|
2048
|
+
key,
|
|
2049
|
+
with_contexts
|
|
2050
|
+
});
|
|
1935
2051
|
}
|
|
1936
2052
|
}
|
|
1937
2053
|
};
|
|
1938
2054
|
}
|
|
1939
|
-
function init({
|
|
2055
|
+
function init({
|
|
2056
|
+
app,
|
|
2057
|
+
ga4Config = null,
|
|
2058
|
+
facebookConfig = null,
|
|
2059
|
+
apiUrl = null,
|
|
2060
|
+
poolConfig = null
|
|
2061
|
+
}) {
|
|
1940
2062
|
if (!apiUrl) {
|
|
1941
2063
|
apiUrl = getDefaultApiUrl();
|
|
1942
2064
|
}
|