|
255 | 255 | this.onload = getConfig("onload", ob, []);
|
256 | 256 | this.utm = getConfig("utm", ob, { source: true, medium: true, campaign: true, term: true, content: true });
|
257 | 257 | this.ignore_prefetch = getConfig("ignore_prefetch", ob, true);
|
| 258 | + this.rcAutoOptinAb = getConfig("rc_automatic_optin_for_ab", ob, true); |
| 259 | + this.useExplicitRcApi = getConfig("use_explicit_rc_api", ob, false); |
258 | 260 | this.debug = getConfig("debug", ob, false);
|
259 | 261 | this.test_mode = getConfig("test_mode", ob, false);
|
260 | 262 | this.metrics = getConfig("metrics", ob, {});
|
|
292 | 294 | lsSupport = false;
|
293 | 295 | }
|
294 | 296 |
|
| 297 | + if (!this.rcAutoOptinAb && !this.useExplicitRcApi) { |
| 298 | + log(logLevelEnums.WARNING, "initialize, Auto opting is disabled, switching to explicit RC API"); |
| 299 | + this.useExplicitRcApi = true; |
| 300 | + } |
| 301 | + |
295 | 302 | if (!Array.isArray(ignoreReferrers)) {
|
296 | 303 | ignoreReferrers = [];
|
297 | 304 | }
|
|
426 | 433 | if (this.remote_config) {
|
427 | 434 | log(logLevelEnums.DEBUG, "initialize, remote_config callback provided:[" + !!this.remote_config + "]");
|
428 | 435 | }
|
| 436 | + if (typeof this.rcAutoOptinAb === "boolean") { |
| 437 | + log(logLevelEnums.DEBUG, "initialize, automatic RC optin is enabled:[" + this.rcAutoOptinAb + "]"); |
| 438 | + } |
| 439 | + if (!this.useExplicitRcApi) { |
| 440 | + log(logLevelEnums.WARNING, "initialize, will use legacy RC API. Consider enabling new API during init with use_explicit_rc_api flag"); |
| 441 | + } |
429 | 442 | if (this.track_domains) {
|
430 | 443 | log(logLevelEnums.DEBUG, "initialize, tracking domain info:[" + this.track_domains + "]");
|
431 | 444 | }
|
|
693 | 706 | self.ip_address = undefined;
|
694 | 707 | self.ignore_bots = undefined;
|
695 | 708 | self.force_post = undefined;
|
| 709 | + self.rcAutoOptinAb = undefined; |
| 710 | + self.useExplicitRcApi = undefined; |
696 | 711 | self.remote_config = undefined;
|
697 | 712 | self.ignore_visitor = undefined;
|
698 | 713 | self.require_consent = undefined;
|
|
1609 | 1624 | * @param {function=} callback - Callback to notify with first param error and second param remote config object
|
1610 | 1625 | * */
|
1611 | 1626 | this.fetch_remote_config = function(keys, omit_keys, callback) {
|
1612 |
| - log(logLevelEnums.INFO, "fetch_remote_config, Fetching remote config"); |
1613 |
| - fetch_remote_config_v2(keys, omit_keys, 1, "legacy", callback); |
| 1627 | + // use new RC API |
| 1628 | + if (this.useExplicitRcApi) { |
| 1629 | + log(logLevelEnums.INFO, "fetch_remote_config, Fetching remote config"); |
| 1630 | + // opt in is true(1) or false(0) |
| 1631 | + var opt = this.rcAutoOptinAb ? 1 : 0; |
| 1632 | + fetch_remote_config_explicit(keys, omit_keys, opt, callback); |
| 1633 | + return; |
| 1634 | + } |
| 1635 | + |
| 1636 | + log(logLevelEnums.WARNING, "fetch_remote_config, Fetching remote config, with legacy API"); |
| 1637 | + fetch_remote_config_explicit(keys, omit_keys, "legacy", callback); |
1614 | 1638 | };
|
1615 | 1639 |
|
1616 | 1640 | /**
|
|
1621 | 1645 | * @param {string=} api - which API to use, if not provided would use default ("legacy" is for method="fetch_remote_config", default is method="rc")
|
1622 | 1646 | * @param {function=} callback - Callback to notify with first param error and second param remote config object
|
1623 | 1647 | * */
|
1624 |
| - function fetch_remote_config_v2(keys, omit_keys, optIn, api, callback) { |
1625 |
| - log(logLevelEnums.INFO, "fetch_remote_config_v2, Fetching remote config"); |
| 1648 | + function fetch_remote_config_explicit(keys, omit_keys, optIn, api, callback) { |
| 1649 | + log(logLevelEnums.INFO, "fetch_remote_config_explicit, Fetching sequence initiated"); |
1626 | 1650 | var request = {
|
1627 | 1651 | method: "rc"
|
1628 | 1652 | };
|
|
1653 | 1677 | provivedCall = arguments[j];
|
1654 | 1678 | }
|
1655 | 1679 | }
|
1656 |
| - if (this.check_consent(featureEnums.SESSIONS)) { |
| 1680 | + if (self.check_consent(featureEnums.SESSIONS)) { |
1657 | 1681 | request.metrics = JSON.stringify(getMetrics());
|
1658 | 1682 | }
|
1659 |
| - if (this.check_consent(featureEnums.REMOTE_CONFIG)) { |
| 1683 | + if (self.check_consent(featureEnums.REMOTE_CONFIG)) { |
1660 | 1684 | prepareRequest(request);
|
1661 |
| - sendXmlHttpRequest("fetch_remote_config_v2", this.url + readPath, request, function(err, params, responseText) { |
| 1685 | + sendXmlHttpRequest("fetch_remote_config_explicit", self.url + readPath, request, function(err, params, responseText) { |
1662 | 1686 | if (err) {
|
1663 |
| - log(logLevelEnums.ERROR, "fetch_remote_config_v2, An error occurred: " + err); |
| 1687 | + log(logLevelEnums.ERROR, "fetch_remote_config_explicit, An error occurred: " + err); |
1664 | 1688 | return;
|
1665 | 1689 | }
|
1666 | 1690 | try {
|
|
1678 | 1702 | setValueInStorage("cly_remote_configs", remoteConfigs);
|
1679 | 1703 | }
|
1680 | 1704 | catch (ex) {
|
1681 |
| - log(logLevelEnums.ERROR, "fetch_remote_config_v2, Had an issue while parsing the response: " + ex); |
| 1705 | + log(logLevelEnums.ERROR, "fetch_remote_config_explicit, Had an issue while parsing the response: " + ex); |
1682 | 1706 | }
|
1683 | 1707 | if (provivedCall) {
|
1684 |
| - log(logLevelEnums.INFO, "fetch_remote_config_v2, Callback function is provided"); |
| 1708 | + log(logLevelEnums.INFO, "fetch_remote_config_explicit, Callback function is provided"); |
1685 | 1709 | provivedCall(err, remoteConfigs);
|
1686 | 1710 | }
|
1687 | 1711 | // JSON array can pass
|
1688 | 1712 | }, true);
|
1689 | 1713 | }
|
1690 | 1714 | else {
|
1691 |
| - log(logLevelEnums.ERROR, "fetch_remote_config_v2, Remote config requires explicit consent"); |
| 1715 | + log(logLevelEnums.ERROR, "fetch_remote_config_explicit, Remote config requires explicit consent"); |
1692 | 1716 | if (provivedCall) {
|
1693 | 1717 | provivedCall(new Error("Remote config requires explicit consent"), remoteConfigs);
|
1694 | 1718 | }
|
|
1699 | 1723 | * AB testing key provider, opts the user in for the selected keys
|
1700 | 1724 | * @param {array=} keys - Array of keys opt in FOR
|
1701 | 1725 | * */
|
1702 |
| - function optAB(keys) { |
1703 |
| - log(logLevelEnums.INFO, "optAB, Providing AB test keys to opt in for"); |
| 1726 | + this.enrollUserToAb = function(keys) { |
| 1727 | + log(logLevelEnums.INFO, "enrollUserToAb, Providing AB test keys to opt in for"); |
1704 | 1728 | if (!keys || !Array.isArray(keys) || keys.length === 0) {
|
1705 |
| - log(logLevelEnums.ERROR, "optAB, No keys provided"); |
| 1729 | + log(logLevelEnums.ERROR, "enrollUserToAb, No keys provided"); |
1706 | 1730 | return;
|
1707 | 1731 | }
|
1708 | 1732 | var request = {
|
1709 | 1733 | method: "ab",
|
1710 | 1734 | keys: JSON.stringify(keys)
|
1711 | 1735 | };
|
1712 | 1736 | prepareRequest(request);
|
1713 |
| - sendXmlHttpRequest("optAB", this.url + readPath, request, function(err, params, responseText) { |
| 1737 | + sendXmlHttpRequest("enrollUserToAb", this.url + readPath, request, function(err, params, responseText) { |
1714 | 1738 | if (err) {
|
1715 |
| - log(logLevelEnums.ERROR, "optAB, An error occurred: " + err); |
| 1739 | + log(logLevelEnums.ERROR, "enrollUserToAb, An error occurred: " + err); |
1716 | 1740 | return;
|
1717 | 1741 | }
|
1718 | 1742 | try {
|
1719 | 1743 | var resp = JSON.parse(responseText);
|
1720 |
| - log(logLevelEnums.DEBUG, "optAB, Parsed the response's result: [" + resp.result + "]"); |
| 1744 | + log(logLevelEnums.DEBUG, "enrollUserToAb, Parsed the response's result: [" + resp.result + "]"); |
1721 | 1745 | }
|
1722 | 1746 | catch (ex) {
|
1723 |
| - log(logLevelEnums.ERROR, "optAB, Had an issue while parsing the response: " + ex); |
| 1747 | + log(logLevelEnums.ERROR, "enrollUserToAb, Had an issue while parsing the response: " + ex); |
1724 | 1748 | }
|
1725 | 1749 | // JSON array can pass
|
1726 | 1750 | }, true);
|
1727 |
| - } |
| 1751 | + }; |
1728 | 1752 |
|
1729 | 1753 | /**
|
1730 | 1754 | * Gets remote config object (all key/value pairs) or specific value for provided key from the storage
|
|
4352 | 4376 | * @param {number} [conf.max_stack_trace_line_length=200] - maximum amount of characters are allowed per stack trace line. This limits also the crash message length
|
4353 | 4377 | * @param {array=} conf.ignore_referrers - array with referrers to ignore
|
4354 | 4378 | * @param {boolean} [conf.ignore_prefetch=true] - ignore prefetching and pre rendering from counting as real website visits
|
| 4379 | + * @param {boolean} [conf.rc_automatic_optin_for_ab=true] - opts in the user for A/B testing while fetching the remote config (if true) |
| 4380 | + * @param {boolean} [conf.use_explicit_rc_api=false] - set it to true to use the new remote config API |
4355 | 4381 | * @param {boolean} [conf.force_post=false] - force using post method for all requests
|
4356 | 4382 | * @param {boolean} [conf.ignore_visitor=false] - ignore this current visitor
|
4357 | 4383 | * @param {boolean} [conf.require_consent=false] - Pass true if you are implementing GDPR compatible consent management. It would prevent running any functionality without proper consent
|
|
0 commit comments