Add support for generating custom targets in the attribution build #585
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #561 and #580.
This PR is an alternative approach to #562 (built on top of my proposed changes in #583) that also adds a new top-level
generateTarget
configuration option which allows developers to pass in their own function—as an alternative to the libraries internalgetSelector()
function.All of the "target" attribution fields that previously reported the result of the internal
getSelector()
function will now report whatever value is returned from the passedgenerateTarget()
function.I believe there are two benefits to this approach:
Breaking changes in this PR include (similar to #562):
LCPAttribution.element
has been renamed toLCPAttribution.target
(for consistency, similar to Save a reference to the LCP and CLS targets in case they are removed from the DOM #562).LCPAttribution.interactionTargetElement
has been removed (to address the issue in Keeping elements around for attribution can leak memory #580).TODO: update the types in the README after we get agreement on the method names and descriptions added here.