Skip to content

Conversation

@rosahbruno
Copy link
Contributor

@rosahbruno rosahbruno commented Nov 23, 2023

Description

Configure auto instrumentation for page_load events.

Built-in page_load events can now be recorded in 2 ways

  1. Automatically via the enableAutoPageLoadEvents parameter in the Glean configuration object. Whenever this is set to true, page load events will be collected automatically whenever initialize is called.
  2. Manually via the @mozilla/glean/metrics object. We now expose pageLoad which is a function that a user can call at any time to record the same page load event that would have been collected automatically.

Automatic instrumentation

Glean.initialize("app-name", true, { enableAutoPageLoadEvents: true });

Example: https://debug-ping-preview.firebaseapp.com/pings/glean-from-website/9f6996dc-a336-46eb-8c93-a1278046ae10#L10

Manually call page_load

import GleanMetrics from "@mozilla/glean/metrics";

// ...

GleanMetrics.pageLoad({
  // Any of the values can be overwritten. If they are not overwritten,
  // the values pulled from the browser will be used.
  //
  // If `enableAutoPageLoadEvents` is true, then this call is a no-op.
  title: "Title Override"
});

Example: https://debug-ping-preview.firebaseapp.com/pings/glean-from-website/81fd045b-c8da-4229-8464-2860b054ece7#L10

Pull Request checklist

  • Quality: Make sure this PR builds and runs cleanly.
    • Inside the glean/ folder, run:
      • npm run test Runs all tests
      • npm run lint Runs all linters
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry to CHANGELOG.md or an explanation of why it does not need one
  • Documentation: This PR includes documentation changes, an explanation of why it does not need that or a follow-up bug has been filed to do that work

@rosahbruno rosahbruno requested a review from Dexterp37 November 23, 2023 07:00
@Dexterp37 Dexterp37 requested a review from badboy November 24, 2023 07:24
@rosahbruno rosahbruno changed the title Glean built-in page_load events Bug 1867126 - automatic page load instrumentation Nov 28, 2023
@rosahbruno rosahbruno marked this pull request as ready for review November 29, 2023 20:55
@auto-assign auto-assign bot requested a review from travis79 November 29, 2023 20:55
@rosahbruno rosahbruno requested a review from badboy November 29, 2023 20:55
@rosahbruno rosahbruno merged commit f4beced into mozilla:main Dec 5, 2023
@rosahbruno rosahbruno deleted the page-loads branch December 5, 2023 13:50
@kirill-demtchouk
Copy link

Love this! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants