Skip to content

Commit 971f129

Browse files
committed
Enhance social media sharing with PostHog tracking and alternative title support
1 parent 958c6f4 commit 971f129

File tree

11 files changed

+145
-45
lines changed

11 files changed

+145
-45
lines changed

components/blog/SocialMediaShare.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ const props = defineProps({
1717
default: false
1818
}
1919
});
20+
const { $clientPosthog, $serverPosthog } = useNuxtApp();
2021
2122
// The isLargePage prop is passed from the parent component
2223
2324
// Function to track share events (for future PostHog integration)
2425
const trackShareEvent = (platform: string) => {
25-
// This function will be used for PostHog tracking in the future
26-
posthog.capture('social_share', {
27-
platform: platform,
28-
url: props.url,
29-
title: props.title
30-
});
26+
27+
onMounted(() => {
28+
$clientPosthog?.capture('share_event', {
29+
platform,
30+
url: props.url,
31+
title: props.title,
32+
description: props.description,
33+
isLargePage: props.isLargePage
34+
});
35+
})
3136
};
3237
3338
// Function to add tracking parameter for large pages

components/blog/page/card/ArticleCard.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
<script setup lang="ts">
22
import type {BlogDeCollectionItem, BlogEnCollectionItem} from '@nuxt/content';
3+
const {getFeatureFlag } = usePostHogFeatureFlag();
4+
35
46
const {locale} = useI18n();
57
const {blogArticle} = defineProps<{
68
blogArticle: BlogDeCollectionItem | BlogEnCollectionItem;
79
}>();
10+
const title = computed(() => {
11+
if (getFeatureFlag('blog-ethanol-conversion').value === 'test') {
12+
return blogArticle?.alternativeTitle || blogArticle?.title || 'No Title';
13+
} else {
14+
return blogArticle?.title || 'No Title';
15+
}
16+
});
817
</script>
918

1019
<template>
1120
<article v-if="blogArticle" class="bg-white dark:bg-gray-800 rounded-xxl shadow-md overflow-hidden">
12-
<NuxtLink :to="`/${locale}/${blogArticle.slug}`">
21+
<NuxtLink :to="`/${locale}/${blogArticle.slug}`" v-posthog-capture="'blog-article-card-click'">
1322
<NuxtImg v-if="blogArticle?.headerImage"
1423
:src="blogArticle?.headerImage"
1524
:alt="blogArticle?.headerImageAlt"
@@ -21,7 +30,7 @@ const {blogArticle} = defineProps<{
2130
quality='80'
2231
class="w-full h-48 object-cover rounded-xxl" />
2332
<div class="p-4">
24-
<h2 class="text-xl font-semibold text-gray-900 dark:text-gray-100">{{ blogArticle?.title ?? 'Unknwon' }}</h2>
33+
<h2 class="text-xl font-semibold text-gray-900 dark:text-gray-100">{{ title }}</h2>
2534
<time v-if="blogArticle?.pubDate" class="text-sm text-gray-500 dark:text-gray-400"><i18n-d :value="blogArticle?.pubDate"></i18n-d></time>
2635
<ContentRenderer class="text-gray-700 dark:text-gray-300 mt-2" :value="blogArticle" excerpt="true">
2736
</ContentRenderer>

components/blog/page/footer/FooterSection.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
<div>
99
<h2 class="text-lg font-bold">{{ $t('footer.social_media') }}</h2>
1010
<ul>
11-
<li><a href="https://github.com/OneLiteFeatherNET" target="_blank" rel="noopener noreferrer" :aria-label="$t('footer.github_aria')">{{ $t('footer.github') }}</a></li>
12-
<li><a href="https://opencollective.com/onelitefeather" target="_blank" rel="noopener noreferrer" :aria-label="$t('footer.opencollective_aria')">{{ $t('footer.opencollective') }}</a></li>
11+
<li><a href="https://github.com/OneLiteFeatherNET" v-posthog-capture="'github-click'" target="_blank" rel="noopener noreferrer" :aria-label="$t('footer.github_aria')">{{ $t('footer.github') }}</a></li>
12+
<li><a href="https://opencollective.com/onelitefeather" v-posthog-capture="'opencollective-click'" target="_blank" rel="noopener noreferrer" :aria-label="$t('footer.opencollective_aria')">{{ $t('footer.opencollective') }}</a></li>
1313
</ul>
1414
</div>
1515
<div>
1616
<h2 class="text-lg font-bold">{{ $t('footer.legal') }}</h2>
1717
<ul>
18-
<li><NuxtLinkLocale to="/imprint">{{ $t('footer.imprint') }}</NuxtLinkLocale></li>
19-
<li><NuxtLinkLocale to="/privacy">{{ $t('footer.privacy_policy') }}</NuxtLinkLocale></li>
18+
<li><NuxtLinkLocale to="/imprint" v-posthog-capture="'imprint-click'">{{ $t('footer.imprint') }}</NuxtLinkLocale></li>
19+
<li><NuxtLinkLocale to="/privacy" v-posthog-capture="'imprint-privacy'">{{ $t('footer.privacy_policy') }}</NuxtLinkLocale></li>
2020
</ul>
2121
</div>
2222
<div>

content.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default defineContentConfig({
1111
source: 'blog/de/**/*.md',
1212
schema: z.object({
1313
title: z.string(),
14+
alternativeTitle: z.string().optional(),
1415
description: z.string(),
1516
slug: z.string(),
1617
// Transform string to Date object
@@ -31,6 +32,7 @@ export default defineContentConfig({
3132
source: 'blog/en/**/*.md',
3233
schema: z.object({
3334
title: z.string(),
35+
alternativeTitle: z.string().optional(),
3436
description: z.string(),
3537
slug: z.string(),
3638
// Transform string to Date object

content/blog/de/everything-you-need-to-know-about-ethanol.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: 'Alles, was du über Ethanol wissen solltest'
3+
alternativeTitle: 'Schon jetzt auf mehreren hundert Servern, was sich dahinter verbirgt'
34
description: 'Relativ unbekannt und trotzdem schon jetzt auf mehreren hundert Servern. Genauso wie Fractureiser wird diese von dem User mori0 / Riesenrad beworben, um Server zu “trollen”. Was sich dahinter verbirgt.'
45
pubDate: 'Jul 23 2024'
56
headerImage: 'images/blog/cyber-theDigitalArtist-Ethanol-Post.webp'

content/blog/en/everything-you-need-to-know-about-ethanol.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: 'Everything You Need to Know About Ethanol'
3+
alternativeTitle: 'Already present on several hundred servers, what lies behind it'
34
description: 'Relatively unknown yet already present on several hundred servers. Like Fractureiser, it is promoted by the user mori0 / Riesenrad to “troll” servers. What lies behind it.'
45
pubDate: 'Jul 23 2024'
56
headerImage: 'images/blog/cyber-theDigitalArtist-Ethanol-Post.webp'

nuxt.config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export default defineNuxtConfig({
4545
'@nuxtjs/robots',
4646
'nuxt-schema-org',
4747
'nuxt-og-image',
48-
'@nuxt/content'
48+
'@nuxt/content',
49+
'nuxt-posthog'
4950
],
5051
i18n: {
5152
strategy: 'prefix',
@@ -151,10 +152,13 @@ export default defineNuxtConfig({
151152
runtimeConfig: {
152153
public: {
153154
siteUrl: 'https://blog.onelitefeather.net',
154-
posthogPublicKey: 'phc_t9nBlYL9LcDj4LDKZfQ97m5nbvFDTugkdQqAAspfdI',
155-
posthogHost: 'https://eu.i.posthog.com'
156155
}
157156
},
157+
posthog: {
158+
publicKey: 'phc_t9nBlYL9LcDj4LDKZfQ97m5nbvFDTugkdQqAAspfdI',
159+
host: 'https://eu.i.posthog.com',
160+
proxy: true
161+
},
158162
site: {
159163
url: 'https://blog.onelitefeather.net',
160164
},
@@ -194,4 +198,4 @@ export default defineNuxtConfig({
194198
}
195199
}
196200
}
197-
})
201+
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"eslint": "^9.27.0",
2626
"nuxt": "^3.17.4",
2727
"nuxt-og-image": "5.1.4",
28+
"nuxt-posthog": "1.6.3",
2829
"nuxt-schema-org": "5.0.5",
2930
"unstorage": "^1.16.0",
3031
"vue": "^3.5.14",

pages/[...slug].vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SocialMediaShare from "~/components/blog/SocialMediaShare.vue";
44
const { locale, t, locales } = useI18n()
55
const route = useRoute()
66
const config = useRuntimeConfig()
7+
const {getFeatureFlag } = usePostHogFeatureFlag();
78
89
definePageMeta({
910
layout: 'blog-entry',
@@ -106,6 +107,14 @@ useHead({
106107
link: headLinks
107108
})
108109
useHead(article?.value?.head || {})
110+
111+
const title = computed(() => {
112+
if (getFeatureFlag('alternative-title-conversion').value === 'test') {
113+
return article?.value?.alternativeTitle || article?.value?.title || 'No Title';
114+
} else {
115+
return article?.value?.title || 'No Title';
116+
}
117+
});
109118
</script>
110119

111120
<template>
@@ -122,6 +131,7 @@ useHead(article?.value?.head || {})
122131
quality='80'
123132
class="aspect-video object-cover rounded-lg" />
124133
<div class="p-4">
134+
<h1 class="text-3xl font-bold text-gray-900 dark:text-white">{{ title }}</h1>
125135
<time v-if="article?.pubDate" class="text-sm text-gray-500 dark:text-gray-400"><i18n-d :value="article?.pubDate"></i18n-d></time>
126136
<ContentRenderer class="text-gray-700 dark:text-gray-300 mt-2" :value="article">
127137
</ContentRenderer>

plugins/posthog.client.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)