@oneie/plugin-track 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +21 -9
- package/src/index.ts +37 -8
package/package.json
CHANGED
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/plugin-track",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "ONE
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Astro integration that injects the ONE analytics pixel — served from one.ie, so nothing ships in your bundle.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"astro-integration",
|
|
8
|
+
"astro-component",
|
|
9
|
+
"astro",
|
|
10
|
+
"withastro",
|
|
11
|
+
"analytics",
|
|
12
|
+
"tracking",
|
|
13
|
+
"pixel",
|
|
14
|
+
"one"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/one-ie/one",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/one-ie/packages.git",
|
|
20
|
+
"directory": "plugin-track"
|
|
21
|
+
},
|
|
6
22
|
"type": "module",
|
|
7
23
|
"main": "src/index.ts",
|
|
8
24
|
"exports": {
|
|
9
|
-
".": "./src/index.ts"
|
|
25
|
+
".": "./src/index.ts",
|
|
26
|
+
"./OneTrack.astro": "./src/OneTrack.astro"
|
|
10
27
|
},
|
|
11
28
|
"peerDependencies": {
|
|
12
29
|
"astro": ">=6.0.0",
|
|
13
|
-
"@oneie/frontend": "
|
|
30
|
+
"@oneie/frontend": "^0.1.2"
|
|
14
31
|
},
|
|
15
32
|
"devDependencies": {
|
|
16
33
|
"astro": "^6.2.2",
|
|
17
34
|
"typescript": "^5.7.3"
|
|
18
|
-
},
|
|
19
|
-
"peerDependenciesMeta": {
|
|
20
|
-
"@oneie/frontend": {
|
|
21
|
-
"optional": true
|
|
22
|
-
}
|
|
23
35
|
}
|
|
24
36
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro'
|
|
1
2
|
import type { OnePluginFactory } from '@oneie/frontend'
|
|
2
3
|
|
|
3
4
|
export interface OneTrackConfig {
|
|
@@ -5,13 +6,41 @@ export interface OneTrackConfig {
|
|
|
5
6
|
agent?: string
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
export const track: OnePluginFactory<OneTrackConfig> = (config = {} as OneTrackConfig) =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export const track: OnePluginFactory<OneTrackConfig> = (config = {} as OneTrackConfig) => {
|
|
10
|
+
const { ws, agent } = config
|
|
11
|
+
|
|
12
|
+
const integration = (): AstroIntegration => ({
|
|
13
|
+
name: '@oneie/plugin-track',
|
|
14
|
+
hooks: {
|
|
15
|
+
'astro:config:setup': ({ injectScript }) => {
|
|
16
|
+
if (!ws) return
|
|
17
|
+
// Analytics scripts must fire on every route with zero manual
|
|
18
|
+
// placement — the standard shape for this kind of integration
|
|
19
|
+
// (cf. @vercel/analytics, @astrojs/partytown). injectScript('page', …)
|
|
20
|
+
// runs once per page load, before hydration.
|
|
21
|
+
injectScript(
|
|
22
|
+
'page',
|
|
23
|
+
`
|
|
24
|
+
const s = document.createElement('script')
|
|
25
|
+
s.async = true
|
|
26
|
+
s.src = 'https://one.ie/p/one.js'
|
|
27
|
+
s.dataset.ws = ${JSON.stringify(ws)}
|
|
28
|
+
${agent ? `s.dataset.agent = ${JSON.stringify(agent)}` : ''}
|
|
29
|
+
document.head.appendChild(s)
|
|
30
|
+
`
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
name: 'plugin-track',
|
|
38
|
+
tier: 'connected',
|
|
39
|
+
serves: 'p/one.js',
|
|
40
|
+
config: undefined,
|
|
41
|
+
integration,
|
|
42
|
+
entitlement: undefined,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
16
45
|
|
|
17
46
|
export type { OneTrackConfig as TrackConfig }
|