Skip to content

Commit fa95e4b

Browse files
committed
refactor: remove manual click tracking logic from project and blog components
1 parent fdc9b25 commit fa95e4b

3 files changed

Lines changed: 13 additions & 33 deletions

File tree

‎js/blog.js‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { formatDate, formatDateShort } from './utils.js';
99
import { trackEvent } from './analytics.js';
1010

1111
async function init() {
12-
const params = new URLSearchParams(window.location.search);
12+
const params = new URLSearchParams(window.location.search);
1313
const postPath = params.get('post');
1414

1515
if (postPath) {
@@ -36,11 +36,6 @@ async function initListingView() {
3636
try {
3737
const manifest = await fetchCached(config.blog_manifest);
3838
renderListing(manifest.posts || [], document.getElementById('posts-list'));
39-
// Track post clicks from listing
40-
document.getElementById('posts-list')?.addEventListener('click', e => {
41-
const row = e.target.closest('[data-track]');
42-
if (row) trackEvent('post_read', row.dataset.track);
43-
});
4439
} catch (err) {
4540
console.error(err);
4641
document.getElementById('posts-list').innerHTML =
@@ -72,8 +67,7 @@ function renderListing(posts, container) {
7267
<div class="group-label">— ${cat} —</div>
7368
<div class="project-group-items">
7469
${items.map(p => `
75-
<a class="blog-row" href="/writing?post=${encodeURIComponent(p.path)}"
76-
data-track="${p.title}">
70+
<a class="blog-row" href="/writing?post=${encodeURIComponent(p.path)}">
7771
<span class="blog-title">${p.title}</span>
7872
<span class="blog-meta">
7973
<span class="blog-cat">[ ${cat} ]</span>
@@ -101,11 +95,11 @@ async function initPostView(postPath) {
10195
fetchTextCached(config.blog_base_url + postPath)
10296
]);
10397

104-
const posts = manifest.posts || [];
105-
const meta = posts.find(p => p.path === postPath);
106-
const idx = posts.findIndex(p => p.path === postPath);
107-
const prevPost = idx < posts.length - 1 ? posts[idx + 1] : null;
108-
const nextPost = idx > 0 ? posts[idx - 1] : null;
98+
const posts = manifest.posts || [];
99+
const meta = posts.find(p => p.path === postPath);
100+
const idx = posts.findIndex(p => p.path === postPath);
101+
const prevPost = idx < posts.length - 1 ? posts[idx + 1] : null;
102+
const nextPost = idx > 0 ? posts[idx - 1] : null;
109103

110104
document.title = meta ? `jebin2 — ${meta.title}` : 'jebin2 — writing';
111105
if (meta?.title) trackEvent('post_read', meta.title);
@@ -118,7 +112,7 @@ async function initPostView(postPath) {
118112
}
119113

120114
function renderPost(mdText, meta, prevPost, nextPost, container) {
121-
const cat = meta ? getCategory(meta.path) : '';
115+
const cat = meta ? getCategory(meta.path) : '';
122116
// Rewrite relative links/images to absolute raw GitHub URLs
123117
const baseUrl = meta
124118
? `https://raw.githubusercontent.com/jebin2/blog/main/${getPostDir(meta.path)}/`
@@ -144,13 +138,13 @@ function renderPost(mdText, meta, prevPost, nextPost, container) {
144138
<nav class="post-nav">
145139
<div>
146140
${prevPost
147-
? `<a href="?post=${encodeURIComponent(prevPost.path)}">← ${prevPost.title}</a>`
148-
: ''}
141+
? `<a href="?post=${encodeURIComponent(prevPost.path)}">← ${prevPost.title}</a>`
142+
: ''}
149143
</div>
150144
<div>
151145
${nextPost
152-
? `<a href="?post=${encodeURIComponent(nextPost.path)}">${nextPost.title} →</a>`
153-
: ''}
146+
? `<a href="?post=${encodeURIComponent(nextPost.path)}">${nextPost.title} →</a>`
147+
: ''}
154148
</div>
155149
</nav>
156150
`;

‎js/home.js‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,13 @@ function renderLatestPosts(manifest, container, recentCounts, allTimeCounts) {
134134
container.innerHTML = sorted.map((p, i) => {
135135
const slug = encodeURIComponent(p.path);
136136
return `
137-
<a class="project-row" href="/writing?post=${slug}" data-track="${p.title}">
137+
<a class="project-row" href="/writing?post=${slug}">
138138
<span class="project-num">${String(i + 1).padStart(2, '0')}.</span>
139139
<span class="project-name">${p.title}</span>
140140
<span class="blog-date">${formatDateShort(p.date)}</span>
141141
</a>
142142
`;
143143
}).join('');
144-
145-
container.addEventListener('click', e => {
146-
const row = e.target.closest('[data-track]');
147-
if (row) trackEvent('post_read', row.dataset.track);
148-
});
149144
}
150145

151146
init();

‎js/projects.js‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ async function init() {
2525
allProjects = await fetchCached(config.projects);
2626
render('all');
2727
initFilter();
28-
initTracking();
2928
} catch (err) {
3029
console.error(err);
3130
if (listEl) listEl.innerHTML = '<p class="state-msg">failed to load projects.</p>';
@@ -85,14 +84,6 @@ function projectRow(p) {
8584
`;
8685
}
8786

88-
/* ---- Track project clicks ---- */
89-
function initTracking() {
90-
document.getElementById('project-list')?.addEventListener('click', e => {
91-
const row = e.target.closest('[data-track]');
92-
if (row) trackEvent('project_click', row.dataset.track);
93-
});
94-
}
95-
9687
/* ---- Filter buttons ---- */
9788
function initFilter() {
9889
const buttons = document.querySelectorAll('.filter-btn');

0 commit comments

Comments
 (0)