Skip to content

Add Segment track calls to code copy button #178

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

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
clean up sample code sent to segment
  • Loading branch information
colegoldsmith committed Dec 19, 2024
commit 192212d1b24e282aa8df79e08dd94fe035fc42cf
6 changes: 3 additions & 3 deletions src/js/07-copy-to-clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@
copy.addEventListener('click', function () {
var text = code.innerText.replace(TRAILING_SPACE_RX, '')
if (code.dataset.lang === 'console' && text.startsWith('$ ')) text = extractCommands(text)
var codeSample = text.slice(0, 50).trim()
writeToClipboard(text, copy)
trackCopy(code.dataset.lang, title?.childNodes[0]?.nodeValue, codeSample)
trackCopy(code.dataset.lang, title?.childNodes[0]?.nodeValue, text)
})
content.prepend(toolbox)
}
Expand Down Expand Up @@ -92,8 +91,9 @@
)
}

function trackCopy (language, title, sample) {
function trackCopy (language, title, text) {
if (window.analytics) {
var sample = text.slice(0, 50).replace(/\s+/g, ' ').trim()
window.analytics.track('Code Snippet Copied', {
snippetLanguage: language,
snippetTitle: title,
Expand Down
Loading