Skip to content

Commit

Permalink
Merge pull request #415 from adobe/sidekick-rc-036069c
Browse files Browse the repository at this point in the history
Sidekick Bookmarklet RC
  • Loading branch information
rofe authored Nov 10, 2023
2 parents 036069c + 0935ed5 commit 364ddb9
Showing 1 changed file with 54 additions and 6 deletions.
60 changes: 54 additions & 6 deletions tools/sidekick/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,52 @@ import sampleRUM from './rum.js';
CUSTOM: 1,
};

/**
* Detects the platform.
* @private
* @param {string} userAgent The user agent
* @returns {string} The platform
*/
function detectPlatform(userAgent) {
userAgent = userAgent.toLowerCase();
if (userAgent.includes('(windows')) {
return 'windows';
} else if (userAgent.includes('(iphone') || userAgent.includes('(ipad')) {
return 'ios';
} else if (userAgent.includes('(macintosh')) {
return 'macos';
} else if (userAgent.includes('android')) {
return 'android';
} else if (userAgent.includes('linux')) {
return 'linux';
}
return 'other';
}

/**
* Detects the browser.
* @private
* @param {string} userAgent The user agent
* @returns {string} The browser
*/
function detectBrowser(userAgent) {
userAgent = userAgent.toLowerCase();
if (userAgent.includes('edg/')) {
return 'edge';
} else if (userAgent.includes('opr/')) {
return 'opera';
} else if (userAgent.includes('samsung')) {
return 'samsung';
} else if (userAgent.includes('chrome/')) {
return 'chrome';
} else if (userAgent.includes('safari/')) {
return 'safari';
} else if (userAgent.includes('firefox/')) {
return 'firefox';
}
return 'other';
}

/**
* Retrieves project details from a host name.
* @private
Expand Down Expand Up @@ -2958,6 +3004,14 @@ import sampleRUM from './rum.js';
this.root.classList.remove('hlx-sk-advanced');
}
});
// platform and browser data
const platform = detectPlatform(navigator.userAgent);
const browser = detectBrowser(navigator.userAgent);
const mode = this.config.scriptUrl.startsWith('https://') ? 'bookmarklet' : 'extension';
sampleRUM('sidekick:loaded', {
source: this.location.href,
target: `${platform}:${browser}:${mode}`,
});
// announce to the document that the sidekick is ready
document.dispatchEvent(new CustomEvent('sidekick-ready'));
document.dispatchEvent(new CustomEvent('helix-sidekick-ready')); // legacy
Expand Down Expand Up @@ -3107,12 +3161,6 @@ import sampleRUM from './rum.js';
config: this.config,
location: this.location,
});

const skMode = this.config.scriptUrl.startsWith('https://www.hlx.live/')
? 'bookmarklet' : 'extension';
sampleRUM(`sidekick:load:${skMode}`, {
source: this.location.href,
});
return this;
}

Expand Down

0 comments on commit 364ddb9

Please sign in to comment.