Skip to content

Commit d8867af

Browse files
Make alt text optional with configurable altText parameter
Co-authored-by: adriaandotcom <[email protected]>
1 parent 9edbfa7 commit d8867af

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

FEATURES.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [✅ Option: Strict UTMs 🔒](https://github.com/ViorelMocanu/astro-simpleanalytics-plugin/blob/main/FEATURES.md#user-content--option-strict-utms-)
1515
- [✅ Option: Allow URL parameters 🔓](https://github.com/ViorelMocanu/astro-simpleanalytics-plugin/blob/main/FEATURES.md#user-content--option-allow-url-parameters-)
1616
- [✅ Option: Ignore metrics 🚫](https://github.com/ViorelMocanu/astro-simpleanalytics-plugin/blob/main/FEATURES.md#user-content--option-ignore-metrics-)
17+
- [✅ Option: Custom alt text for tracking pixel 🏷️](https://github.com/ViorelMocanu/astro-simpleanalytics-plugin/blob/main/FEATURES.md#user-content--option-custom-alt-text-for-tracking-pixel-️)
1718
- [💡 Feature: Embed chart on your site 📈](https://github.com/ViorelMocanu/astro-simpleanalytics-plugin/blob/main/FEATURES.md#user-content--feature-embed-chart-on-your-site-)
1819

1920
Once you [install it](README.md#🚀-installation), the Astro Simple Analytics Plugin should be ready to go with zero config.
@@ -40,6 +41,7 @@ These are all the available parameter options for this plugin where you choose t
4041
ignorePages={undefined} {/* (undefined | string) */}
4142
nonUniqueHostnames={undefined} {/* (undefined | string) */}
4243
ignoreMetrics={undefined} {/* (undefined | string) */}
44+
altText={undefined} {/* (undefined | string) */}
4345
/>
4446
```
4547

@@ -250,6 +252,18 @@ So if, for example, you'd like to ignore `timeonpage` and `scrolled`, you should
250252

251253
You can add any number of metrics to this list if you want to ignore them.
252254

255+
## ✅ Option: Custom alt text for tracking pixel 🏷️
256+
257+
By default, the tracking pixel in the noscript fallback has an empty alt attribute (`alt=""`), which is appropriate for decorative images. However, you may want to provide custom alternative text for accessibility or other reasons.
258+
259+
You can customize the alt text by passing the `altText` parameter:
260+
261+
```Astro
262+
<SimpleAnalytics altText="Simple Analytics tracking pixel" />
263+
```
264+
265+
If you don't provide the `altText` parameter, it will default to an empty string, keeping the original behavior.
266+
253267
## 💡 Feature: Embed chart on your site 📈
254268

255269
The Astro Simple Analytics Plugin allows you to [embed a chart of your public website statistics](https://docs.simpleanalytics.com/embed-chart-on-your-site) on your website.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ These are all the available parameter options for this plugin where you choose t
7575
ignorePages={undefined} {/* (undefined | string) */}
7676
nonUniqueHostnames={undefined} {/* (undefined | string) */}
7777
ignoreMetrics={undefined} {/* (undefined | string) */}
78+
altText={undefined} {/* (undefined | string) */}
7879
/>
7980
```
8081

src/SimpleAnalytics.astro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
sanitizeCSV,
55
sanitizeHostname,
66
sanitizeHostnameList,
7+
sanitizeString,
78
} from "./utilities";
89
910
export interface Props {
@@ -19,6 +20,7 @@ export interface Props {
1920
strictUTMs?: boolean;
2021
allowParams?: string | undefined;
2122
ignoreMetrics?: string | undefined;
23+
altText?: string | undefined;
2224
}
2325
2426
const {
@@ -34,6 +36,7 @@ const {
3436
strictUTMs = false,
3537
allowParams = undefined,
3638
ignoreMetrics = undefined,
39+
altText = undefined,
3740
} = Astro.props;
3841
3942
// prop sanitization
@@ -49,6 +52,7 @@ const sanitizedDebug = sanitizeBoolean(debug);
4952
const sanitizedStrictUTMs = sanitizeBoolean(strictUTMs);
5053
const sanitizedAllowParams = sanitizeCSV(allowParams);
5154
const sanitizedIgnoreMetrics = sanitizeCSV(ignoreMetrics);
55+
const sanitizedAltText = sanitizeString(altText);
5256
5357
// attribute generation
5458
const realURL = new URL(Astro.url.origin);
@@ -159,7 +163,7 @@ if (sanitizedDebug) {
159163
<noscript>
160164
<img
161165
src={imageSrc}
162-
alt="Simple Analytics tracking pixel"
166+
alt={sanitizedAltText || ""}
163167
referrerpolicy="no-referrer-when-downgrade"
164168
/>
165169
</noscript>

0 commit comments

Comments
 (0)