-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
report(links): utm params for all developer.google.com links #4972
Conversation
lighthouse-core/environment/cli.js
Outdated
|
||
module.exports = { | ||
name: 'CLI', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also considering having one const ENVIRONMENT = 'replace-me'
in the runner.js
instead of three environment/
files, but replacing imports instead of values seemed a tiny bit cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I agree abstractly, unfortunately it doesn't seem as easy as I expected in browserify 😆
is there any simpler way with less manual? I'm no browserify expert, maybe something similar to the webpack define plugin or simple shim replacement without custom transform?
with the audits/gatherers we manually do something fancy without a transform which is what makes me hopeful :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webpack define plugin
that was a good tip, thanks! (after a lot of googling) I found similar solution for browserify 👌
docs/understanding-results.md
Outdated
@@ -10,7 +10,8 @@ The top-level Lighthouse Result object (LHR) is what the lighthouse node module | |||
|
|||
| Name | Description | | |||
| - | - | | |||
| lighthouseVersion | The version of Lighthouse with which this result were generated. | | |||
| lighthouseVersion | The version of Lighthouse with which this result was generated. | | |||
| lighthouseEnvironment | The environment in which Lighthouse result was generated (CLI, extension, DevTools). | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll be happy to change that name, I couldn't figure out anything better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should figure out where this fits into the LHR reshuffling. Like the discussion on runtimeConfig
, maybe this should move into the settings
property (whatever we end up calling it) that's copied over from the config settings and has all the flags, throttling settings, etc, used in this run
lighthouse-core/runner.js
Outdated
@@ -110,6 +110,7 @@ class Runner { | |||
// Entering: conclusion of the lighthouse result object | |||
// @ts-ignore - Needs json require() support | |||
const lighthouseVersion = /** @type {string} */ (require('../package.json').version); | |||
const lighthouseEnvironment = /** @type {string} */ (require('./environment/cli').name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'./environment/cli'
this part gets replaced by browserify
'use strict'; | ||
|
||
module.exports = { | ||
name: 'extension', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since these seems to be display-oriented how about 'Extension' alternatively we make all these lowercase and just switch in the report to compute the display version
either seems ok with me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, changing this to 'Extension' SGTM 👍
lighthouse-extension/gulpfile.js
Outdated
const environment = file.path.includes('-ext-') ? 'Extension' : 'DevTools'; | ||
let bundle = browserify(file.path, { | ||
insertGlobalVars: { | ||
'global.ENVIRONMENT': () => `"${environment}"`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I won't be able to answer any questions starting with "why" regarding this line. It's just how it's done in browserify e.g. we can't just have () => environment
here because we will end up with {"ENVIRONMENT": DevTools}
(note missing quotes) in the result code 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hurray much easier! :D 🎉
yeah webpack works similarly where it's basically straight up string replacement, FWIW I've usually seen JSON.stringify(environment)
to try to get this message across but I don't have a strong opinion
@brendankenny @paulirish either way make more sense to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to add another possibility, we could use https://github.com/hughsk/envify and then use process.env.LH_ENVIRONMENT
or whatever. That would avoid the mystery global variable and allow overriding on the CLI side if for some reason you'd want to do that (WPT or something?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sticking with insertGlobalVars is in my opinion a better ideas as it's native browserify. We can still use env vars with process.env
which makes it a bit more verbose. I would try to use JSON.stringify as it's more common due webpacks implementation as patrick suggested.
@patrickhulce I replaced custom browserify transform with something less manual + added tests for convertMarkdownLinkSnippets. PTAL |
lighthouse-core/runner.js
Outdated
@@ -110,6 +110,8 @@ class Runner { | |||
// Entering: conclusion of the lighthouse result object | |||
// @ts-ignore - Needs json require() support | |||
const lighthouseVersion = /** @type {string} */ (require('../package.json').version); | |||
// @ts-ignore - ENVIRONMENT varialble is not declared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brendankenny not sure how to best handle that. Should we have a separate ts file with interface Global
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're already stomping all over the global scope in
lighthouse/typings/externs.d.ts
Lines 11 to 17 in 4b1f2bb
declare global { | |
// Augment global Error type to include node's optional `code` property | |
// see https://nodejs.org/api/errors.html#errors_error_code | |
interface Error { | |
code?: string; | |
} | |
global
(or Window
, or however they do the global mapping for node) like Error
is being augmented in those lines
cli, ext, cdt, nm, wpt, lr |
What's the status of this PR? |
7c310ad
to
3e006b9
Compare
// Fix an issue with imported speedline code that doesn't brfs well. | ||
return bundle.transform('./fs-transform', {global: true}) | ||
// Replace LH_CHANNEL enviroment variable with a string | ||
.transform('./lh-channel-transform', {channel, global: true}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a custom find&replace transform. I couldn't use envify because it's based on esprima 4 (latest) which doesn't support object rest/spread :(
@rviscomi just updated! @patrickhulce @paulirish Sorry it took so long, but I updated this PR as discussed in April (see the description) |
lighthouse-extension/gulpfile.js
Outdated
// Fix an issue with imported speedline code that doesn't brfs well. | ||
return bundle.transform('./fs-transform', {global: true}) | ||
// Replace LH_CHANNEL enviroment variable with a string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/enviroment/environment/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'll defer to @patrickhulce @brendankenny or @brendankenny if they have any technical feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks @kdzwinel!!
lighthouse-core/runner.js
Outdated
@@ -106,7 +106,12 @@ class Runner { | |||
} | |||
|
|||
// Entering: conclusion of the lighthouse result object | |||
const lighthouseVersion = require('../package.json').version; | |||
|
|||
// @ts-ignore - Needs json require() support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brendankenny do you have any tips for him here?
not sure why this would be be necessary now when it wasn't before 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is just a bad merge or rebase. I just removed this ts-ignore
in the last week or two
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I removed it 👍
if (metadata && metadata.channel) { | ||
url.searchParams.set('utm_medium', metadata.channel); | ||
} | ||
if (metadata && metadata.rating) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh my, I'm really regretting us calling that pass/fail string rating now 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few last things.
Can you also add a check to extension-test.js
, so it gets a test through the full pipeline? It should be straightforward to grab a description or two and make sure the URL has the utm params and channel is set to ext
Thanks for sticking with this!!
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
@brendankenny Hey, I'm taking over this PR from Konrad. I've addressed your comments, can you take a look? |
@mattzeunert Sorry for being slow. Also sent you a message out of band, but I think we're going to move this to chillin and wait on it for a little while. There's been a lot of churn in the bundle/channel entry points, file names, and control flow, so things have changed a good bit in this area since the PR started. The changes needed for |
Let's close instead of chilling indefinitely. I'll leave a note on #4663 |
Closes #4663
Appends additional params to all developer.google.com links for easier tracking:
utm_source
- hardcoded to 'lighthouse'utm_medium
- "cli", "ext" (extension), "cdt" (devtools), "nm" (node module) depending on how LH was runutm_content
- "pass", "fail" depending on audit result (if available)Example:
Explanation
As discussed in April, channel is now part of the lighthouseVersion in the output object (e.g. '3.0.3+cli'). Applications can pass channel value via LH_CHANNEL environment variable.
The algorithm is as follows: