Skip to content

Commit f626de5

Browse files
authored
feat(js): Add reportPageLoaded() documentation (#15006)
1 parent 2191128 commit f626de5

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

docs/platforms/javascript/common/apis.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,39 @@ See <PlatformLink to="/tracing/instrumentation/">Tracing Instrumentation</Platfo
712712
`browserTracingIntegration` has not been enabled.
713713
</SdkApi>
714714

715+
<SdkApi
716+
name="reportPageLoaded"
717+
signature="function reportPageLoaded(): void"
718+
categorySupported={["browser"]}
719+
availableSince="10.13.0"
720+
>
721+
722+
Signals to the Sentry SDK that the initial page was fully loaded.
723+
Requires the <PlatformLink to="/tracing/instrumentation/automatic-instrumentation/#enableReportPageLoaded">`enableReportPageLoaded` option</PlatformLink> in `browserTracingIntegration` to
724+
be set to `true`. Once called, the SDK ends the pageload span automatically,
725+
726+
By default, the SDK takes care of ending the pageload span automatically, based on
727+
a period of inactivity where no new child spans are added to the pageload trace.
728+
You can alternatively use explicit pageload reporting if the inactivity heuristics of
729+
`browserTracingIntegration` don't work well for your use case.
730+
However, you must ensure that you call `reportPageLoaded` in every situation.
731+
If `reportPageLoaded` is not called, the pageload span will be ended after 30 seconds
732+
or whatever custom value is set on the <PlatformLink to="/tracing/instrumentation/automatic-instrumentation/#enableReportPageLoaded">`finalTimeout` option</PlatformLink>.
733+
734+
735+
<Expandable title="Examples">
736+
```javascript
737+
Sentry.init({
738+
// 1. Enable manual page load reporting:
739+
integrations: [browserTracingIntegration({ enableReportPageLoaded: true })]
740+
})
741+
742+
// 2. Whenever you consider the page loaded:
743+
Sentry.reportPageLoaded();
744+
```
745+
</Expandable>
746+
</SdkApi>
747+
715748
## Tracing Utilities
716749

717750
These utilities can be used for more advanced tracing use cases.

docs/platforms/javascript/common/tracing/instrumentation/automatic-instrumentation.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ This flag enables or disables creation of `pageload` span on first pageload.
131131

132132
</SdkOption>
133133

134+
135+
<SdkOption name="enableReportPageLoaded" type='boolean' defaultValue='false' availableSince='10.13.0'>
136+
137+
This option determines whether the <PlatformLink to="/apis/#reportPageLoaded">`Sentry.reportPageLoaded()` function</PlatformLink> is enabled.
138+
139+
</SdkOption>
140+
134141
<SdkOption name="markBackgroundSpans" type='boolean' defaultValue='true'>
135142

136143
This option flags pageload/navigation spans when tabs are moved to the background with "cancelled". Because browser background tab timing is not suited for precise measurements of operations and can affect your statistics in nondeterministic ways, we recommend that this option be enabled.

src/components/sdkApi.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Props = {
2626
name: string;
2727
parameters: ParameterDef[];
2828
signature: string;
29+
availableSince?: string;
2930
categorySupported?: PlatformCategory[];
3031
children?: React.ReactNode;
3132
language?: string;
@@ -35,6 +36,7 @@ export function SdkApi({
3536
name,
3637
children,
3738
signature,
39+
availableSince,
3840
parameters = [],
3941
language,
4042
categorySupported = [],
@@ -51,9 +53,12 @@ export function SdkApi({
5153
{showServerLikeOnly && (
5254
<div className="italic text-sm">Only available on Server</div>
5355
)}
54-
5556
<pre className="mt-2 mb-2 text-sm">{codeToJsx(signature, lang)}</pre>
56-
57+
{availableSince && (
58+
<p className="italic">
59+
Available Since: <code>{availableSince}</code>
60+
</p>
61+
)}
5762
{parameters.length ? (
5863
<Expandable title="Parameters">
5964
<div className="space-y-3">
@@ -63,7 +68,6 @@ export function SdkApi({
6368
</div>
6469
</Expandable>
6570
) : null}
66-
6771
{children}
6872
</SdkDefinition>
6973
);

0 commit comments

Comments
 (0)