@adobe/alloy 2.21.0-beta.6 → 2.21.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.
Files changed (76) hide show
  1. package/libEs5/components/ActivityCollector/attachClickActivityCollector.js +4 -0
  2. package/libEs5/components/ActivityCollector/configValidators.js +17 -2
  3. package/libEs5/components/ActivityCollector/createClickActivityStorage.js +35 -0
  4. package/libEs5/components/ActivityCollector/createClickedElementProperties.js +215 -0
  5. package/libEs5/components/ActivityCollector/createGetClickedElementProperties.js +64 -0
  6. package/libEs5/components/ActivityCollector/createInjectClickedElementProperties.js +70 -0
  7. package/libEs5/components/ActivityCollector/createRecallAndInjectClickedElementProperties.js +46 -0
  8. package/libEs5/components/ActivityCollector/{createLinkClick.js → createStorePageViewProperties.js} +6 -21
  9. package/libEs5/components/ActivityCollector/getLinkName.js +9 -24
  10. package/libEs5/components/ActivityCollector/getLinkRegion.js +2 -2
  11. package/libEs5/components/ActivityCollector/index.js +54 -19
  12. package/libEs5/components/ActivityCollector/utils/activityMapExtensionEnabled.js +20 -0
  13. package/libEs5/components/ActivityCollector/utils/createTransientStorage.js +28 -0
  14. package/libEs5/components/ActivityCollector/utils/determineLinkType.js +28 -0
  15. package/libEs5/components/ActivityCollector/utils/dom/elementHasClickHandler.js +17 -0
  16. package/libEs5/components/ActivityCollector/utils/dom/extractDomain.js +22 -0
  17. package/libEs5/components/ActivityCollector/utils/dom/findClickableElement.js +28 -0
  18. package/libEs5/components/ActivityCollector/utils/dom/getAbsoluteUrlFromAnchorElement.js +42 -0
  19. package/libEs5/components/ActivityCollector/utils/dom/isButtonSubmitElement.js +17 -0
  20. package/libEs5/components/ActivityCollector/utils/dom/isDownloadLink.js +28 -0
  21. package/libEs5/components/ActivityCollector/utils/dom/isExitLink.js +25 -0
  22. package/libEs5/components/ActivityCollector/utils/dom/isInputSubmitElement.js +28 -0
  23. package/libEs5/components/ActivityCollector/utils/dom/isSupportedAnchorElement.js +20 -0
  24. package/libEs5/components/ActivityCollector/utils/dom/isSupportedTextNode.js +30 -0
  25. package/libEs5/components/ActivityCollector/utils/hasPageName.js +21 -0
  26. package/libEs5/components/ActivityCollector/utils/isDifferentDomains.js +20 -0
  27. package/libEs5/components/ActivityCollector/utils/trimQueryFromUrl.js +25 -0
  28. package/libEs5/components/ActivityCollector/utils/truncateWhiteSpace.js +24 -0
  29. package/libEs5/components/ActivityCollector/utils/urlStartsWithScheme.js +17 -0
  30. package/libEs5/constants/libraryVersion.js +1 -1
  31. package/libEs5/constants/sessionDataKeys.js +15 -0
  32. package/libEs5/core/config/createCoreConfigs.js +1 -1
  33. package/libEs5/utils/validation/createDeprecatedValidator.js +8 -23
  34. package/libEs5/utils/validation/createRenamedValidator.js +44 -0
  35. package/libEs5/utils/validation/index.js +7 -3
  36. package/libEs6/components/ActivityCollector/attachClickActivityCollector.js +4 -0
  37. package/libEs6/components/ActivityCollector/configValidators.js +17 -2
  38. package/libEs6/components/ActivityCollector/createClickActivityStorage.js +34 -0
  39. package/libEs6/components/ActivityCollector/createClickedElementProperties.js +218 -0
  40. package/libEs6/components/ActivityCollector/createGetClickedElementProperties.js +69 -0
  41. package/libEs6/components/ActivityCollector/createInjectClickedElementProperties.js +69 -0
  42. package/libEs6/components/ActivityCollector/createRecallAndInjectClickedElementProperties.js +45 -0
  43. package/libEs6/components/ActivityCollector/{createLinkClick.js → createStorePageViewProperties.js} +7 -22
  44. package/libEs6/components/ActivityCollector/getLinkName.js +2 -16
  45. package/libEs6/components/ActivityCollector/getLinkRegion.js +1 -1
  46. package/libEs6/components/ActivityCollector/index.js +50 -14
  47. package/libEs6/components/ActivityCollector/utils/activityMapExtensionEnabled.js +14 -0
  48. package/libEs6/components/ActivityCollector/utils/createTransientStorage.js +26 -0
  49. package/libEs6/components/ActivityCollector/utils/determineLinkType.js +26 -0
  50. package/libEs6/components/ActivityCollector/utils/dom/elementHasClickHandler.js +15 -0
  51. package/libEs6/components/ActivityCollector/utils/dom/extractDomain.js +20 -0
  52. package/libEs6/components/ActivityCollector/utils/dom/findClickableElement.js +26 -0
  53. package/libEs6/components/ActivityCollector/utils/dom/getAbsoluteUrlFromAnchorElement.js +42 -0
  54. package/libEs6/components/ActivityCollector/utils/dom/isButtonSubmitElement.js +15 -0
  55. package/libEs6/components/ActivityCollector/utils/dom/isDownloadLink.js +26 -0
  56. package/libEs6/components/ActivityCollector/utils/dom/isExitLink.js +23 -0
  57. package/libEs6/components/ActivityCollector/utils/dom/isInputSubmitElement.js +26 -0
  58. package/libEs6/components/ActivityCollector/utils/dom/isSupportedAnchorElement.js +18 -0
  59. package/libEs6/components/ActivityCollector/utils/dom/isSupportedTextNode.js +27 -0
  60. package/libEs6/components/ActivityCollector/utils/hasPageName.js +19 -0
  61. package/libEs6/components/ActivityCollector/utils/isDifferentDomains.js +18 -0
  62. package/libEs6/components/ActivityCollector/utils/trimQueryFromUrl.js +23 -0
  63. package/libEs6/components/ActivityCollector/utils/truncateWhiteSpace.js +22 -0
  64. package/libEs6/components/ActivityCollector/utils/urlStartsWithScheme.js +15 -0
  65. package/libEs6/constants/libraryVersion.js +1 -1
  66. package/libEs6/constants/sessionDataKeys.js +12 -0
  67. package/libEs6/core/config/createCoreConfigs.js +1 -1
  68. package/libEs6/utils/validation/createDeprecatedValidator.js +7 -20
  69. package/libEs6/utils/validation/createRenamedValidator.js +37 -0
  70. package/libEs6/utils/validation/index.js +7 -3
  71. package/package.json +15 -16
  72. package/scripts/alloyBuilder.js +3 -1
  73. package/libEs5/components/ActivityCollector/createGetLinkDetails.js +0 -68
  74. package/libEs5/components/ActivityCollector/utils.js +0 -104
  75. package/libEs6/components/ActivityCollector/createGetLinkDetails.js +0 -70
  76. package/libEs6/components/ActivityCollector/utils.js +0 -104
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright 2023 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import isObject from "../isObject.js";
13
+ import { assertValid } from "./utils.js";
14
+ export default ((oldField, oldSchema, newField) => function deprecated(value, path) {
15
+ assertValid(isObject(value), value, path, "an object");
16
+ const {
17
+ [oldField]: oldValue,
18
+ [newField]: newValue,
19
+ ...otherValues
20
+ } = value;
21
+ const validatedOldValue = oldSchema(oldValue, path);
22
+ if (validatedOldValue !== undefined) {
23
+ let message = `The field '${oldField}' is deprecated. Use '${newField}' instead.`;
24
+ if (path) {
25
+ message = `'${path}': ${message}`;
26
+ }
27
+ if (newValue !== undefined && newValue !== validatedOldValue) {
28
+ throw new Error(message);
29
+ } else if (this && this.logger) {
30
+ this.logger.warn(message);
31
+ }
32
+ }
33
+ return {
34
+ [newField]: newValue || validatedOldValue,
35
+ ...otherValues
36
+ };
37
+ });
@@ -71,6 +71,7 @@ governing permissions and limitations under the License.
71
71
  import { chain, nullSafeChain, reverseNullSafeChainJoinErrors } from "./utils.js";
72
72
  import booleanValidator from "./booleanValidator.js";
73
73
  import callbackValidator from "./callbackValidator.js";
74
+ import createAnyOfValidator from "./createAnyOfValidator.js";
74
75
  import createArrayOfValidator from "./createArrayOfValidator.js";
75
76
  import createDefaultValidator from "./createDefaultValidator.js";
76
77
  import createDeprecatedValidator from "./createDeprecatedValidator.js";
@@ -81,7 +82,7 @@ import createMaximumValidator from "./createMaximumValidator.js";
81
82
  import createNoUnknownFieldsValidator from "./createNoUnknownFieldsValidator.js";
82
83
  import createNonEmptyValidator from "./createNonEmptyValidator.js";
83
84
  import createObjectOfValidator from "./createObjectOfValidator.js";
84
- import createAnyOfValidator from "./createAnyOfValidator.js";
85
+ import createRenamedValidator from "./createRenamedValidator.js";
85
86
  import createUniqueValidator from "./createUniqueValidator.js";
86
87
  import createUniqueItemsValidator from "./createUniqueItemsValidator.js";
87
88
  import domainValidator from "./domainValidator.js";
@@ -104,6 +105,9 @@ base.default = function _default(defaultValue) {
104
105
  base.required = function required() {
105
106
  return chain(this, requiredValidator);
106
107
  };
108
+ base.deprecated = function deprecated(message) {
109
+ return chain(this, createDeprecatedValidator(message));
110
+ };
107
111
 
108
112
  // helper validators
109
113
  const domain = function domain() {
@@ -195,10 +199,10 @@ const createObjectOfAdditionalProperties = schema => ({
195
199
  };
196
200
  return nullSafeChain(this, otherObjectOfValidator, createObjectOfAdditionalProperties(newSchema));
197
201
  },
198
- deprecated: function deprecated(oldField, oldSchema, newField) {
202
+ renamed: function renamed(oldField, oldSchema, newField) {
199
203
  // Run the deprecated validator first so that the deprecated field is removed
200
204
  // before the objectOf validator runs.
201
- return reverseNullSafeChainJoinErrors(this, createDeprecatedValidator(oldField, oldSchema, newField));
205
+ return reverseNullSafeChainJoinErrors(this, createRenamedValidator(oldField, oldSchema, newField));
202
206
  },
203
207
  schema
204
208
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/alloy",
3
- "version": "2.21.0-beta.6",
3
+ "version": "2.21.0",
4
4
  "description": "Adobe Experience Platform Web SDK",
5
5
  "type": "module",
6
6
  "main": "libEs5/index.js",
@@ -38,6 +38,7 @@
38
38
  "test:scripts": "jasmine --config=scripts/specs/jasmine.json",
39
39
  "sandbox:build": "rollup -c --environment SANDBOX && cd sandbox && npm run build",
40
40
  "dev": "concurrently --names build,sandbox \"rollup -c -w --environment SANDBOX\" \"cd sandbox && export REACT_APP_NONCE=321 && npm start\"",
41
+ "dev:standalone": "npm run clean && rollup -c -w --environment STANDALONE",
41
42
  "build": "npm run clean && rollup -c --environment BASE_CODE_MIN,STANDALONE,STANDALONE_MIN && echo \"Base Code:\" && cat distTest/baseCode.min.js",
42
43
  "build:cli": "node scripts/build-alloy.js",
43
44
  "prepare": "husky && cd sandbox && npm install",
@@ -77,14 +78,10 @@
77
78
  "@adobe/reactor-load-script": "^1.1.1",
78
79
  "@adobe/reactor-object-assign": "^1.0.0",
79
80
  "@adobe/reactor-query-string": "^1.0.0",
80
- "@babel/cli": "^7.24.7",
81
81
  "@babel/core": "^7.24.7",
82
82
  "@babel/eslint-parser": "^7.24.7",
83
- "@babel/plugin-proposal-object-rest-spread": "^7.3.2",
84
- "@babel/plugin-transform-runtime": "^7.24.7",
85
83
  "@babel/plugin-transform-template-literals": "^7.24.7",
86
84
  "@babel/preset-env": "^7.24.7",
87
- "@babel/types": "^7.24.7",
88
85
  "@rollup/plugin-babel": "^6.0.4",
89
86
  "@rollup/plugin-commonjs": "^26.0.1",
90
87
  "@rollup/plugin-node-resolve": "^15.2.3",
@@ -97,13 +94,15 @@
97
94
  "rollup": "^4.18.0",
98
95
  "rollup-plugin-glob-import": "^0.5.0",
99
96
  "rollup-plugin-istanbul": "^5.0.0",
100
- "rollup-plugin-license": "^3.4.0",
101
- "uuid": "^9.0.1"
97
+ "rollup-plugin-license": "^3.5.0",
98
+ "uuid": "^10.0.0"
102
99
  },
103
100
  "devDependencies": {
104
- "@adobe/alloy": "^2.21.0-beta.5",
105
- "@eslint/js": "^9.4.0",
106
- "@octokit/rest": "^20.1.1",
101
+ "@adobe/alloy": "^2.21.0-beta.12",
102
+ "@babel/cli": "^7.24.7",
103
+ "@babel/plugin-transform-runtime": "^7.24.7",
104
+ "@eslint/js": "^9.5.0",
105
+ "@octokit/rest": "^21.0.0",
107
106
  "bundlesize": "^0.18.2",
108
107
  "chai": "^5.1.1",
109
108
  "chalk": "^5.3.0",
@@ -118,8 +117,8 @@
118
117
  "eslint-plugin-prettier": "^5.1.3",
119
118
  "eslint-plugin-testcafe": "^0.2.1",
120
119
  "force-resolutions": "^1.0.11",
121
- "glob": "^10.4.1",
122
- "globals": "^15.4.0",
120
+ "glob": "^10.4.2",
121
+ "globals": "^15.6.0",
123
122
  "handlebars": "^4.7.8",
124
123
  "husky": "^9.0.11",
125
124
  "jasmine": "^5.1.0",
@@ -136,8 +135,8 @@
136
135
  "karma-safari-launcher": "^1.0.0",
137
136
  "karma-sauce-launcher": "^4.3.6",
138
137
  "karma-spec-reporter": "0.0.36",
139
- "lint-staged": "^15.2.5",
140
- "prettier": "^3.3.1",
138
+ "lint-staged": "^15.2.7",
139
+ "prettier": "^3.3.2",
141
140
  "promise-polyfill": "^8.3.0",
142
141
  "read-cache": "^1.0.0",
143
142
  "recursive-readdir": "^2.2.3",
@@ -146,10 +145,10 @@
146
145
  "semver": "^7.6.2",
147
146
  "staged-git-files": "^1.3.0",
148
147
  "start-server-and-test": "^2.0.4",
149
- "testcafe": "^3.6.0",
148
+ "testcafe": "^3.6.1",
150
149
  "testcafe-browser-provider-saucelabs": "^3.0.0",
151
150
  "testcafe-reporter-junit": "^3.0.2",
152
- "testcafe-reporter-saucelabs": "^3.1.0",
151
+ "testcafe-reporter-saucelabs": "^3.2.0",
153
152
  "url-exists-nodejs": "^0.2.4",
154
153
  "url-parse": "^1.5.10"
155
154
  },
@@ -16,11 +16,13 @@ import path from "path";
16
16
  import { rollup } from "rollup";
17
17
  import { Command, Option, InvalidOptionArgumentError } from "commander";
18
18
  import inquirer from "inquirer";
19
+ import { fileURLToPath } from "url";
19
20
  import { buildConfig } from "../rollup.config.js";
20
21
  import conditionalBuildBabelPlugin from "./helpers/conditionalBuildBabelPlugin.js";
21
22
  import components from "./helpers/alloyComponents.js";
22
23
 
23
- const dirname = import.meta.dirname;
24
+ const dirname = path.dirname(fileURLToPath(import.meta.url));
25
+
24
26
  let sourceRootPath = `${dirname}/../src`;
25
27
  if (!fs.existsSync(sourceRootPath)) {
26
28
  sourceRootPath = `${dirname}/../libEs6`;
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- exports.default = void 0;
4
- /*
5
- Copyright 2022 Adobe. All rights reserved.
6
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License. You may obtain a copy
8
- of the License at http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software distributed under
11
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- OF ANY KIND, either express or implied. See the License for the specific language
13
- governing permissions and limitations under the License.
14
- */
15
- var _default = exports.default = function _default(_ref) {
16
- var window = _ref.window,
17
- getLinkName = _ref.getLinkName,
18
- getLinkRegion = _ref.getLinkRegion,
19
- getAbsoluteUrlFromAnchorElement = _ref.getAbsoluteUrlFromAnchorElement,
20
- findSupportedAnchorElement = _ref.findSupportedAnchorElement,
21
- determineLinkType = _ref.determineLinkType;
22
- return function (_ref2) {
23
- var targetElement = _ref2.targetElement,
24
- config = _ref2.config,
25
- logger = _ref2.logger;
26
- var anchorElement = findSupportedAnchorElement(targetElement);
27
- if (!anchorElement) {
28
- logger.info("This link click event is not triggered because the HTML element is not an anchor.");
29
- return undefined;
30
- }
31
- var linkUrl = getAbsoluteUrlFromAnchorElement(window, anchorElement);
32
- if (!linkUrl) {
33
- logger.info("This link click event is not triggered because the HTML element doesn't have an URL.");
34
- return undefined;
35
- }
36
- var linkType = determineLinkType(window, config, linkUrl, anchorElement);
37
- var linkRegion = getLinkRegion(anchorElement);
38
- var linkName = getLinkName(anchorElement);
39
- var onBeforeLinkClickSend = config.onBeforeLinkClickSend;
40
- var options = {
41
- xdm: {
42
- eventType: "web.webinteraction.linkClicks",
43
- web: {
44
- webInteraction: {
45
- name: linkName,
46
- region: linkRegion,
47
- type: linkType,
48
- URL: linkUrl,
49
- linkClicks: {
50
- value: 1
51
- }
52
- }
53
- }
54
- },
55
- data: {},
56
- clickedElement: targetElement
57
- };
58
- if (!onBeforeLinkClickSend) {
59
- return options;
60
- }
61
- var shouldEventBeTracked = onBeforeLinkClickSend(options);
62
- if (shouldEventBeTracked !== false) {
63
- return options;
64
- }
65
- logger.info("This link click event is not triggered because it was canceled in onBeforeLinkClickSend.");
66
- return undefined;
67
- };
68
- };
@@ -1,104 +0,0 @@
1
- "use strict";
2
-
3
- exports.urlStartsWithScheme = exports.truncateWhiteSpace = exports.trimQueryFromUrl = exports.isSupportedAnchorElement = exports.isExitLink = exports.isEmptyString = exports.isDownloadLink = exports.getAbsoluteUrlFromAnchorElement = exports.findSupportedAnchorElement = exports.determineLinkType = void 0;
4
- /*
5
- Copyright 2019 Adobe. All rights reserved.
6
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- you may not use this file except in compliance with the License. You may obtain a copy
8
- of the License at http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software distributed under
11
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- OF ANY KIND, either express or implied. See the License for the specific language
13
- governing permissions and limitations under the License.
14
- */
15
-
16
- var urlStartsWithScheme = exports.urlStartsWithScheme = function urlStartsWithScheme(url) {
17
- return url && /^[a-z0-9]+:\/\//i.test(url);
18
- };
19
- var getAbsoluteUrlFromAnchorElement = exports.getAbsoluteUrlFromAnchorElement = function getAbsoluteUrlFromAnchorElement(window, element) {
20
- var loc = window.location;
21
- var url = element.href ? element.href : "";
22
- var protocol = element.protocol,
23
- host = element.host;
24
- if (!urlStartsWithScheme(url)) {
25
- if (!protocol) {
26
- protocol = loc.protocol ? loc.protocol : "";
27
- }
28
- protocol = protocol ? protocol + "//" : "";
29
- if (!host) {
30
- host = loc.host ? loc.host : "";
31
- }
32
- var path = "";
33
- if (url.substring(0, 1) !== "/") {
34
- var indx = loc.pathname.lastIndexOf("/");
35
- indx = indx < 0 ? 0 : indx;
36
- path = loc.pathname.substring(0, indx);
37
- }
38
- url = "" + protocol + host + path + "/" + url;
39
- }
40
- return url;
41
- };
42
- var isSupportedAnchorElement = exports.isSupportedAnchorElement = function isSupportedAnchorElement(element) {
43
- if (element.href && (element.tagName === "A" || element.tagName === "AREA") && (!element.onclick || !element.protocol || element.protocol.toLowerCase().indexOf("javascript") < 0)) {
44
- return true;
45
- }
46
- return false;
47
- };
48
- var trimQueryFromUrl = exports.trimQueryFromUrl = function trimQueryFromUrl(url) {
49
- var questionMarkIndex = url.indexOf("?");
50
- var hashIndex = url.indexOf("#");
51
- if (questionMarkIndex >= 0 && (questionMarkIndex < hashIndex || hashIndex < 0)) {
52
- return url.substring(0, questionMarkIndex);
53
- }
54
- if (hashIndex >= 0) {
55
- return url.substring(0, hashIndex);
56
- }
57
- return url;
58
- };
59
- var isDownloadLink = exports.isDownloadLink = function isDownloadLink(downloadLinkQualifier, linkUrl, clickedObj) {
60
- var re = new RegExp(downloadLinkQualifier);
61
- var trimmedLinkUrl = trimQueryFromUrl(linkUrl).toLowerCase();
62
- return clickedObj.download ? true : re.test(trimmedLinkUrl);
63
- };
64
- var isExitLink = exports.isExitLink = function isExitLink(window, linkUrl) {
65
- var currentHostname = window.location.hostname.toLowerCase();
66
- var trimmedLinkUrl = trimQueryFromUrl(linkUrl).toLowerCase();
67
- if (trimmedLinkUrl.indexOf(currentHostname) >= 0) {
68
- return false;
69
- }
70
- return true;
71
- };
72
-
73
- /**
74
- * Reduces repeated whitespace within a string. Whitespace surrounding the string
75
- * is trimmed and any occurrence of whitespace within the string is replaced with
76
- * a single space.
77
- * @param {string} str String to be formatted.
78
- * @returns {string} Formatted string.
79
- */
80
- var truncateWhiteSpace = exports.truncateWhiteSpace = function truncateWhiteSpace(str) {
81
- return str && str.replace(/\s+/g, " ").trim();
82
- };
83
- var isEmptyString = exports.isEmptyString = function isEmptyString(str) {
84
- return !str || str.length === 0;
85
- };
86
- var determineLinkType = exports.determineLinkType = function determineLinkType(window, config, linkUrl, clickedObj) {
87
- var linkType = "other";
88
- if (isDownloadLink(config.downloadLinkQualifier, linkUrl, clickedObj)) {
89
- linkType = "download";
90
- } else if (isExitLink(window, linkUrl)) {
91
- linkType = "exit";
92
- }
93
- return linkType;
94
- };
95
- var findSupportedAnchorElement = exports.findSupportedAnchorElement = function findSupportedAnchorElement(targetElement) {
96
- var node = targetElement;
97
- while (node) {
98
- if (isSupportedAnchorElement(node)) {
99
- return node;
100
- }
101
- node = node.parentNode;
102
- }
103
- return null;
104
- };
@@ -1,70 +0,0 @@
1
- /*
2
- Copyright 2022 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
-
13
- export default (({
14
- window,
15
- getLinkName,
16
- getLinkRegion,
17
- getAbsoluteUrlFromAnchorElement,
18
- findSupportedAnchorElement,
19
- determineLinkType
20
- }) => {
21
- return ({
22
- targetElement,
23
- config,
24
- logger
25
- }) => {
26
- const anchorElement = findSupportedAnchorElement(targetElement);
27
- if (!anchorElement) {
28
- logger.info("This link click event is not triggered because the HTML element is not an anchor.");
29
- return undefined;
30
- }
31
- const linkUrl = getAbsoluteUrlFromAnchorElement(window, anchorElement);
32
- if (!linkUrl) {
33
- logger.info("This link click event is not triggered because the HTML element doesn't have an URL.");
34
- return undefined;
35
- }
36
- const linkType = determineLinkType(window, config, linkUrl, anchorElement);
37
- const linkRegion = getLinkRegion(anchorElement);
38
- const linkName = getLinkName(anchorElement);
39
- const {
40
- onBeforeLinkClickSend
41
- } = config;
42
- const options = {
43
- xdm: {
44
- eventType: "web.webinteraction.linkClicks",
45
- web: {
46
- webInteraction: {
47
- name: linkName,
48
- region: linkRegion,
49
- type: linkType,
50
- URL: linkUrl,
51
- linkClicks: {
52
- value: 1
53
- }
54
- }
55
- }
56
- },
57
- data: {},
58
- clickedElement: targetElement
59
- };
60
- if (!onBeforeLinkClickSend) {
61
- return options;
62
- }
63
- const shouldEventBeTracked = onBeforeLinkClickSend(options);
64
- if (shouldEventBeTracked !== false) {
65
- return options;
66
- }
67
- logger.info("This link click event is not triggered because it was canceled in onBeforeLinkClickSend.");
68
- return undefined;
69
- };
70
- });
@@ -1,104 +0,0 @@
1
- /*
2
- Copyright 2019 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
-
13
- const urlStartsWithScheme = url => {
14
- return url && /^[a-z0-9]+:\/\//i.test(url);
15
- };
16
- const getAbsoluteUrlFromAnchorElement = (window, element) => {
17
- const loc = window.location;
18
- let url = element.href ? element.href : "";
19
- let {
20
- protocol,
21
- host
22
- } = element;
23
- if (!urlStartsWithScheme(url)) {
24
- if (!protocol) {
25
- protocol = loc.protocol ? loc.protocol : "";
26
- }
27
- protocol = protocol ? `${protocol}//` : "";
28
- if (!host) {
29
- host = loc.host ? loc.host : "";
30
- }
31
- let path = "";
32
- if (url.substring(0, 1) !== "/") {
33
- let indx = loc.pathname.lastIndexOf("/");
34
- indx = indx < 0 ? 0 : indx;
35
- path = loc.pathname.substring(0, indx);
36
- }
37
- url = `${protocol}${host}${path}/${url}`;
38
- }
39
- return url;
40
- };
41
- const isSupportedAnchorElement = element => {
42
- if (element.href && (element.tagName === "A" || element.tagName === "AREA") && (!element.onclick || !element.protocol || element.protocol.toLowerCase().indexOf("javascript") < 0)) {
43
- return true;
44
- }
45
- return false;
46
- };
47
- const trimQueryFromUrl = url => {
48
- const questionMarkIndex = url.indexOf("?");
49
- const hashIndex = url.indexOf("#");
50
- if (questionMarkIndex >= 0 && (questionMarkIndex < hashIndex || hashIndex < 0)) {
51
- return url.substring(0, questionMarkIndex);
52
- }
53
- if (hashIndex >= 0) {
54
- return url.substring(0, hashIndex);
55
- }
56
- return url;
57
- };
58
- const isDownloadLink = (downloadLinkQualifier, linkUrl, clickedObj) => {
59
- const re = new RegExp(downloadLinkQualifier);
60
- const trimmedLinkUrl = trimQueryFromUrl(linkUrl).toLowerCase();
61
- return clickedObj.download ? true : re.test(trimmedLinkUrl);
62
- };
63
- const isExitLink = (window, linkUrl) => {
64
- const currentHostname = window.location.hostname.toLowerCase();
65
- const trimmedLinkUrl = trimQueryFromUrl(linkUrl).toLowerCase();
66
- if (trimmedLinkUrl.indexOf(currentHostname) >= 0) {
67
- return false;
68
- }
69
- return true;
70
- };
71
-
72
- /**
73
- * Reduces repeated whitespace within a string. Whitespace surrounding the string
74
- * is trimmed and any occurrence of whitespace within the string is replaced with
75
- * a single space.
76
- * @param {string} str String to be formatted.
77
- * @returns {string} Formatted string.
78
- */
79
- const truncateWhiteSpace = str => {
80
- return str && str.replace(/\s+/g, " ").trim();
81
- };
82
- const isEmptyString = str => {
83
- return !str || str.length === 0;
84
- };
85
- const determineLinkType = (window, config, linkUrl, clickedObj) => {
86
- let linkType = "other";
87
- if (isDownloadLink(config.downloadLinkQualifier, linkUrl, clickedObj)) {
88
- linkType = "download";
89
- } else if (isExitLink(window, linkUrl)) {
90
- linkType = "exit";
91
- }
92
- return linkType;
93
- };
94
- const findSupportedAnchorElement = targetElement => {
95
- let node = targetElement;
96
- while (node) {
97
- if (isSupportedAnchorElement(node)) {
98
- return node;
99
- }
100
- node = node.parentNode;
101
- }
102
- return null;
103
- };
104
- export { urlStartsWithScheme, getAbsoluteUrlFromAnchorElement, isSupportedAnchorElement, isDownloadLink, isEmptyString, isExitLink, trimQueryFromUrl, truncateWhiteSpace, findSupportedAnchorElement, determineLinkType };