Skip to content

Commit 85d8ccd

Browse files
committed
Allow a UTM code to be passed in the quick editor
1 parent ddcd75d commit 85d8ccd

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

web/packages/quick-editor/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ type QuickEditorOptions = {
128128
- **`avatarRefreshDelay: number`**:
129129
The delay in milliseconds before the avatar image is refreshed after an update. This can help ensure any cache can be busted before the new image is displayed.
130130

131+
- **`utm: string`**:
132+
A code used to determine where the Quick Editor is being used.
133+
131134

132135
> While updating the avatar image, to bypass the browser's cache, the Quick Editor will add a `t` parameter with the current timestamp to the avatar URL.
133136

web/packages/quick-editor/playground/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
2222
email: 'joao.heringer@automattic.com',
2323
scope: [ 'avatars', 'about' ],
2424
locale: 'es',
25+
utm: 'jetpack-comments',
2526
onProfileUpdated: ( type: ProfileUpdatedType ) => {
2627
// eslint-disable-next-line
2728
console.log( type );

web/packages/quick-editor/src/quick-editor-core.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type QuickEditorCoreOptions = Partial< {
3333
onProfileUpdated: OnProfileUpdated;
3434
onOpened: OnOpened;
3535
onClosed: OnClosed;
36+
utm?: string;
3637
} >;
3738

3839
export class GravatarQuickEditorCore {
@@ -43,16 +44,18 @@ export class GravatarQuickEditorCore {
4344
_onProfileUpdated: OnProfileUpdated;
4445
_onOpened: OnOpened;
4546
_onClosed: OnClosed;
47+
_utm: string;
4648
_window: Window | null = null;
4749

48-
constructor( { email, scope = [], locale, onProfileUpdated, onOpened, onClosed }: QuickEditorCoreOptions ) {
50+
constructor( { email, scope = [], locale, onProfileUpdated, onOpened, onClosed, utm }: QuickEditorCoreOptions ) {
4951
this._name = this._getName();
5052
this._email = email;
5153
this._scope = scope;
5254
this._locale = locale;
5355
this._onProfileUpdated = onProfileUpdated;
5456
this._onOpened = onOpened;
5557
this._onClosed = onClosed;
58+
this._utm = utm;
5659

5760
if ( ! this._scope.every( ( s ) => ScopeList.includes( s ) ) ) {
5861
// eslint-disable-next-line
@@ -83,7 +86,8 @@ export class GravatarQuickEditorCore {
8386
const top = window.screenTop + ( window.outerHeight - height ) / 2;
8487
const options = `popup,width=${ width },height=${ height },top=${ top },left=${ left }`;
8588
const host = this._locale ? `https://${ this._locale }.gravatar.com` : 'https://gravatar.com';
86-
const url = `${ host }/profile?email=${ email }&scope=${ scope }&is_quick_editor=true`;
89+
const utm = this._utm ? `&utm=${ encodeURIComponent( this._utm ) }` : '';
90+
const url = `${ host }/profile?email=${ email }&scope=${ scope }&is_quick_editor=true${ utm }`;
8791

8892
this._window = window.open( url, this._name, options );
8993

0 commit comments

Comments
 (0)