@oneie/plugin-track 0.1.0 → 0.1.1
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 +4 -8
- package/src/index.ts +37 -8
package/package.json
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/plugin-track",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "ONE tracking pixel — served from one.ie, zero bundle cost, no source in your repo",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "src/index.ts",
|
|
8
8
|
"exports": {
|
|
9
|
-
".": "./src/index.ts"
|
|
9
|
+
".": "./src/index.ts",
|
|
10
|
+
"./OneTrack.astro": "./src/OneTrack.astro"
|
|
10
11
|
},
|
|
11
12
|
"peerDependencies": {
|
|
12
13
|
"astro": ">=6.0.0",
|
|
13
|
-
"@oneie/frontend": "
|
|
14
|
+
"@oneie/frontend": "^0.1.1"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"astro": "^6.2.2",
|
|
17
18
|
"typescript": "^5.7.3"
|
|
18
|
-
},
|
|
19
|
-
"peerDependenciesMeta": {
|
|
20
|
-
"@oneie/frontend": {
|
|
21
|
-
"optional": true
|
|
22
|
-
}
|
|
23
19
|
}
|
|
24
20
|
}
|
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 }
|