@zsoltcsaszti/lens 0.2.0 → 0.2.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/README.md +6 -6
- package/package.json +9 -3
- package/wordpress/lens-analytics/lens-analytics.php +160 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Lens SDK
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@zsoltcsaszti/lens)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
|
|
6
6
|
Reader intelligence for publishers. One script tag. Zero tracking cookies.
|
|
@@ -13,7 +13,7 @@ Reader intelligence for publishers. One script tag. Zero tracking cookies.
|
|
|
13
13
|
|
|
14
14
|
```html
|
|
15
15
|
<script
|
|
16
|
-
src="https://unpkg.com/@
|
|
16
|
+
src="https://unpkg.com/@zsoltcsaszti/lens/dist/lens.umd.js"
|
|
17
17
|
data-site-id="YOUR_SITE_ID"
|
|
18
18
|
data-api="https://your-lens-server.com"
|
|
19
19
|
data-mode="emphasis">
|
|
@@ -25,14 +25,14 @@ Paste before `</body>` on every page. That's it — no API keys for readers, no
|
|
|
25
25
|
**Via npm (for bundler-based setups):**
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
npm install @
|
|
28
|
+
npm install @zsoltcsaszti/lens
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
```js
|
|
32
|
-
import '@
|
|
32
|
+
import '@zsoltcsaszti/lens' // side-effect import — auto-initialises from data-* attributes
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
**WordPress:** copy
|
|
35
|
+
**WordPress:** the plugin is included in the npm package. After `npm install @zsoltcsaszti/lens`, copy `node_modules/@zsoltcsaszti/lens/wordpress/lens-analytics/` into `wp-content/plugins/`, activate, and configure under **Settings → Lens Analytics**.
|
|
36
36
|
|
|
37
37
|
---
|
|
38
38
|
|
|
@@ -172,7 +172,7 @@ Then point `data-api` in your script tag to your deployed URL.
|
|
|
172
172
|
- [x] Section interest heatmap in dashboard
|
|
173
173
|
- [x] WordPress plugin
|
|
174
174
|
- [x] Multi-format demo (tech, news, magazine, tutorial)
|
|
175
|
-
- [x] npm package (`@
|
|
175
|
+
- [x] npm package (`@zsoltcsaszti/lens`)
|
|
176
176
|
- [ ] Multi-page interest graph (track topics across your whole publication)
|
|
177
177
|
- [ ] A/B mode — adapted vs. non-adapted to 50/50 of visitors, measure engagement delta
|
|
178
178
|
- [ ] Weekly publisher digest — "what your readers actually cared about this week"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zsoltcsaszti/lens",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Reader intelligence for publishers. One script tag. Zero tracking cookies.",
|
|
5
5
|
"main": "dist/lens.umd.js",
|
|
6
6
|
"module": "dist/lens.esm.js",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist/",
|
|
16
16
|
"sdk/lens.js",
|
|
17
|
+
"wordpress/",
|
|
17
18
|
"README.md"
|
|
18
19
|
],
|
|
19
20
|
"sideEffects": true,
|
|
@@ -34,13 +35,18 @@
|
|
|
34
35
|
"build": "node build.js",
|
|
35
36
|
"start": "node server/index.js",
|
|
36
37
|
"dev": "node --watch server/index.js",
|
|
37
|
-
"prepublishOnly": "npm run build"
|
|
38
|
+
"prepublishOnly": "npm run build",
|
|
39
|
+
"test": "jest"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"esbuild": "^0.21.5"
|
|
42
|
+
"esbuild": "^0.21.5",
|
|
43
|
+
"jest": "^30.4.2"
|
|
41
44
|
},
|
|
42
45
|
"dependencies": {
|
|
43
46
|
"cors": "^2.8.5",
|
|
44
47
|
"express": "^4.19.2"
|
|
48
|
+
},
|
|
49
|
+
"jest": {
|
|
50
|
+
"testEnvironment": "node"
|
|
45
51
|
}
|
|
46
52
|
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Plugin Name: Lens Analytics
|
|
4
|
+
* Plugin URI: https://github.com/zsoltcsaszti/lens-sdk
|
|
5
|
+
* Description: Reader intelligence for your WordPress site. No tracking cookies. No PII. One script tag.
|
|
6
|
+
* Version: 0.2.0
|
|
7
|
+
* Author: Zsolt Csaszti
|
|
8
|
+
* License: MIT
|
|
9
|
+
* Text Domain: lens-analytics
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
if ( ! defined( 'ABSPATH' ) ) exit;
|
|
13
|
+
|
|
14
|
+
define( 'LENS_VERSION', '0.2.0' );
|
|
15
|
+
define( 'LENS_CDN_URL', 'https://unpkg.com/@zsoltcsaszti/lens@' . LENS_VERSION . '/dist/lens.umd.js' );
|
|
16
|
+
define( 'LENS_OPTION_KEY', 'lens_analytics_settings' );
|
|
17
|
+
|
|
18
|
+
function lens_defaults() {
|
|
19
|
+
return [
|
|
20
|
+
'site_id' => '',
|
|
21
|
+
'api_endpoint' => '',
|
|
22
|
+
'mode' => 'emphasis',
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ── Inject SDK on all front-end pages ─────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
add_action( 'wp_footer', function() {
|
|
29
|
+
$opts = wp_parse_args( get_option( LENS_OPTION_KEY, [] ), lens_defaults() );
|
|
30
|
+
if ( empty( $opts['site_id'] ) ) return;
|
|
31
|
+
|
|
32
|
+
$valid_modes = [ 'emphasis', 'collapse', 'both', 'off' ];
|
|
33
|
+
$site_id = esc_attr( $opts['site_id'] );
|
|
34
|
+
$api_url = esc_attr( $opts['api_endpoint'] );
|
|
35
|
+
$mode = esc_attr( in_array( $opts['mode'], $valid_modes ) ? $opts['mode'] : 'emphasis' );
|
|
36
|
+
$cdn = esc_url( LENS_CDN_URL );
|
|
37
|
+
|
|
38
|
+
echo "\n<script src=\"{$cdn}\" data-site-id=\"{$site_id}\" data-api=\"{$api_url}\" data-mode=\"{$mode}\"></script>\n";
|
|
39
|
+
}, 20 );
|
|
40
|
+
|
|
41
|
+
// ── Admin settings page ────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
add_action( 'admin_menu', function() {
|
|
44
|
+
add_options_page(
|
|
45
|
+
'Lens Analytics',
|
|
46
|
+
'Lens Analytics',
|
|
47
|
+
'manage_options',
|
|
48
|
+
'lens-analytics',
|
|
49
|
+
'lens_settings_page'
|
|
50
|
+
);
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
add_action( 'admin_init', function() {
|
|
54
|
+
register_setting( 'lens_analytics_group', LENS_OPTION_KEY, [
|
|
55
|
+
'sanitize_callback' => 'lens_sanitize_settings',
|
|
56
|
+
] );
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
function lens_sanitize_settings( $input ) {
|
|
60
|
+
$clean = lens_defaults();
|
|
61
|
+
$clean['site_id'] = sanitize_text_field( $input['site_id'] ?? '' );
|
|
62
|
+
$clean['api_endpoint'] = esc_url_raw( $input['api_endpoint'] ?? '' );
|
|
63
|
+
$valid_modes = [ 'emphasis', 'collapse', 'both', 'off' ];
|
|
64
|
+
$clean['mode'] = in_array( $input['mode'] ?? '', $valid_modes )
|
|
65
|
+
? $input['mode'] : 'emphasis';
|
|
66
|
+
return $clean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function lens_settings_page() {
|
|
70
|
+
if ( ! current_user_can( 'manage_options' ) ) return;
|
|
71
|
+
$opts = wp_parse_args( get_option( LENS_OPTION_KEY, [] ), lens_defaults() );
|
|
72
|
+
$modes = [
|
|
73
|
+
'off' => 'Off (analytics only)',
|
|
74
|
+
'emphasis' => 'Emphasis — highlight relevant sections (recommended)',
|
|
75
|
+
'collapse' => 'Collapse — hide low-relevance sections',
|
|
76
|
+
'both' => 'Both — emphasise and collapse',
|
|
77
|
+
];
|
|
78
|
+
?>
|
|
79
|
+
<div class="wrap">
|
|
80
|
+
<h1>Lens Analytics</h1>
|
|
81
|
+
<p style="color:#666;max-width:520px;margin-bottom:24px;line-height:1.6">
|
|
82
|
+
Reader intelligence without the surveillance. Lens learns what each visitor cares about
|
|
83
|
+
and adapts your content locally — no accounts, no PII, no tracking cookies.
|
|
84
|
+
<a href="https://unpkg.com/@zsoltcsaszti/lens" target="_blank" rel="noopener">View SDK docs ↗</a>
|
|
85
|
+
</p>
|
|
86
|
+
|
|
87
|
+
<?php if ( empty( $opts['site_id'] ) ): ?>
|
|
88
|
+
<div class="notice notice-warning inline"><p>Enter a Site ID below to activate Lens on your site.</p></div>
|
|
89
|
+
<?php else: ?>
|
|
90
|
+
<div class="notice notice-success inline"><p>Lens is active on your site with site ID <strong><?= esc_html( $opts['site_id'] ) ?></strong>.</p></div>
|
|
91
|
+
<?php endif; ?>
|
|
92
|
+
|
|
93
|
+
<form method="post" action="options.php" style="margin-top:20px">
|
|
94
|
+
<?php settings_fields( 'lens_analytics_group' ); ?>
|
|
95
|
+
<table class="form-table" role="presentation">
|
|
96
|
+
|
|
97
|
+
<tr>
|
|
98
|
+
<th scope="row"><label for="lens_site_id">Site ID</label></th>
|
|
99
|
+
<td>
|
|
100
|
+
<input type="text" id="lens_site_id"
|
|
101
|
+
name="<?= LENS_OPTION_KEY ?>[site_id]"
|
|
102
|
+
value="<?= esc_attr( $opts['site_id'] ) ?>"
|
|
103
|
+
class="regular-text"
|
|
104
|
+
placeholder="e.g. my-blog" />
|
|
105
|
+
<p class="description">A short identifier for this site (letters, numbers, hyphens). Used to group analytics data.</p>
|
|
106
|
+
</td>
|
|
107
|
+
</tr>
|
|
108
|
+
|
|
109
|
+
<tr>
|
|
110
|
+
<th scope="row"><label for="lens_api">Analytics Server URL</label></th>
|
|
111
|
+
<td>
|
|
112
|
+
<input type="url" id="lens_api"
|
|
113
|
+
name="<?= LENS_OPTION_KEY ?>[api_endpoint]"
|
|
114
|
+
value="<?= esc_attr( $opts['api_endpoint'] ) ?>"
|
|
115
|
+
class="regular-text"
|
|
116
|
+
placeholder="https://your-lens-server.com" />
|
|
117
|
+
<p class="description">URL of your self-hosted Lens server. Leave blank to disable event sending (adaptation still works locally).</p>
|
|
118
|
+
</td>
|
|
119
|
+
</tr>
|
|
120
|
+
|
|
121
|
+
<tr>
|
|
122
|
+
<th scope="row"><label for="lens_mode">Adaptation Mode</label></th>
|
|
123
|
+
<td>
|
|
124
|
+
<select id="lens_mode" name="<?= LENS_OPTION_KEY ?>[mode]">
|
|
125
|
+
<?php foreach ( $modes as $value => $label ): ?>
|
|
126
|
+
<option value="<?= esc_attr( $value ) ?>" <?php selected( $opts['mode'], $value ); ?>>
|
|
127
|
+
<?= esc_html( $label ) ?>
|
|
128
|
+
</option>
|
|
129
|
+
<?php endforeach; ?>
|
|
130
|
+
</select>
|
|
131
|
+
<p class="description">How Lens visually adapts the reading experience for each visitor.</p>
|
|
132
|
+
</td>
|
|
133
|
+
</tr>
|
|
134
|
+
|
|
135
|
+
</table>
|
|
136
|
+
<?php submit_button( 'Save Settings' ); ?>
|
|
137
|
+
</form>
|
|
138
|
+
|
|
139
|
+
<hr style="margin:32px 0 24px">
|
|
140
|
+
|
|
141
|
+
<h2 class="title">Manual installation snippet</h2>
|
|
142
|
+
<p style="color:#666;margin-bottom:12px">
|
|
143
|
+
If you prefer to add the script tag yourself (e.g. via a theme or another plugin):
|
|
144
|
+
</p>
|
|
145
|
+
<pre style="background:#1e1e1e;color:#d4d4d4;padding:16px 20px;border-radius:6px;font-size:12px;overflow-x:auto;line-height:1.6"><?php
|
|
146
|
+
$sid = $opts['site_id'] ?: 'YOUR_SITE_ID';
|
|
147
|
+
$api = $opts['api_endpoint'] ?: 'https://your-lens-server.com';
|
|
148
|
+
$mode = $opts['mode'];
|
|
149
|
+
echo esc_html(
|
|
150
|
+
'<script' . "\n" .
|
|
151
|
+
' src="' . LENS_CDN_URL . '"' . "\n" .
|
|
152
|
+
' data-site-id="' . $sid . '"' . "\n" .
|
|
153
|
+
' data-api="' . $api . '"' . "\n" .
|
|
154
|
+
' data-mode="' . $mode . '">' . "\n" .
|
|
155
|
+
'</script>'
|
|
156
|
+
);
|
|
157
|
+
?></pre>
|
|
158
|
+
</div>
|
|
159
|
+
<?php
|
|
160
|
+
}
|