Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLScriptElement
  4. attributionSrc

HTMLScriptElement: attributionSrc property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see thecompatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

TheattributionSrc property of theHTMLScriptElement interface gets and sets theattributionsrc attribute on a<script> element programmatically, reflecting the value of that attribute.attributionsrc specifies that you want the browser to send anAttribution-Reporting-Eligible header along with the script resource request.

On the server-side this is used to trigger sending anAttribution-Reporting-Register-Source orAttribution-Reporting-Register-Trigger header in the response, to register a JavaScript-basedattribution source orattribution trigger, respectively. Which response header should be sent back depends on the value of theAttribution-Reporting-Eligible header that triggered the registration.

Note:Alternatively, JavaScript-based attribution sources or triggers can be registered by sending afetch() request containing theattributionReporting option (either set directly on thefetch() call or on aRequest object passed into thefetch() call), or by sending anXMLHttpRequest withsetAttributionReporting() invoked on the request object.

See theAttribution Reporting API for more details.

Value

A string. There are two versions of this property that you can get and set:

  • Empty string, i.e.,scriptElem.attributionSrc="". This specifies that you want theAttribution-Reporting-Eligible header sent to the same server as thesrc attribute points to. This is fine when you are handling the attribution source or trigger registration on the same server. When registering an attribution trigger this property is optional, and an empty string value will be used if it is omitted.

  • Value containing one or more URLs, for example:

    js
    scriptElem.attributionSrc =  "https://a.example/register-source https://b.example/register-source";

    This is useful in cases where the requested resource is not on a server you control, or you just want to handle registering the attribution source on a different server. In this case, you can specify one or more URLs as the value ofattributionSrc. When the resource request occurs theAttribution-Reporting-Eligible header will be sent to the URL(s) specified inattributionSrc in addition to the resource origin. These URLs can then respond with anAttribution-Reporting-Register-Source orAttribution-Reporting-Register-Trigger header as appropriate to complete registration.

    Note:Specifying multiple URLs means that multiple attribution sources can be registered on the same feature. You might for example have different campaigns that you are trying to measure the success of, which involve generating different reports on different data.

Examples

Setting an empty attributionSrc

html
<script src="advertising-script.js"></script>
js
const scriptElem = document.querySelector("script");scriptElem.attributionSrc = "";

Setting an attributionSrc containing URLs

html
<script src="advertising-script.js"></script>
js
// encode the URLs in case they contain special characters// such as '=' that would be improperly parsed.const encodedUrlA = encodeURIComponent("https://a.example/register-source");const encodedUrlB = encodeURIComponent("https://b.example/register-source");const scriptElem = document.querySelector("script");scriptElem.attributionSrc = `${encodedUrlA} ${encodedUrlB}`;

Specifications

Specification
Attribution Reporting
# dom-htmlattributionsrcelementutils-attributionsrc

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp