@drevops/axel 0.2.0 → 0.3.0

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 CHANGED
@@ -16,6 +16,8 @@
16
16
  ![LICENSE](https://img.shields.io/github/license/drevops/axel)
17
17
  ![Renovate](https://img.shields.io/badge/renovate-enabled-green?logo=renovatebot)
18
18
  [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/drevops/axel/badge)](https://scorecard.dev/viewer/?uri=github.com/drevops/axel)
19
+ [![npm](https://img.shields.io/npm/v/@drevops/axel)](https://www.npmjs.com/package/@drevops/axel)
20
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@drevops/axel/badge)](https://www.jsdelivr.com/package/npm/@drevops/axel)
19
21
 
20
22
  </div>
21
23
 
@@ -164,7 +166,7 @@ Enhanced Measurement covers events Axel doesn't send, such as scrolls, site sear
164
166
 
165
167
  ## 📦 Installation
166
168
 
167
- Every [release](https://github.com/drevops/axel/releases/latest) attaches 1 ready-made bundle per setup. The [`@drevops/axel`](https://www.npmjs.com/package/@drevops/axel) package on npm holds the same bundles in its `build/` folder. Pick the bundle that matches how your site starts scripts and where your events go:
169
+ Axel ships 1 ready-made bundle per setup. Pick the bundle that matches how your site starts scripts and where your events go:
168
170
 
169
171
  | Bundle | Starts | Sends events to |
170
172
  |-------------------------|------------------------------------------|--------------------------------------------------|
@@ -178,41 +180,80 @@ Every [release](https://github.com/drevops/axel/releases/latest) attaches 1 read
178
180
 
179
181
  Each bundle also comes minified, such as `axel.gtm.min.js`. A bundle holds only its own adapter, so `axel.gtm.min.js` carries no Google tag code.
180
182
 
181
- ### Plain page
183
+ ### Where to get the bundles
182
184
 
183
- Add the bundle to your pages:
185
+ Load the bundles from [jsDelivr](https://www.jsdelivr.com/package/npm/@drevops/axel), which serves every file of every release:
184
186
 
185
- ```html
186
- <script src="/path/to/axel.gtm.min.js"></script>
187
+ ```text
188
+ https://cdn.jsdelivr.net/npm/@drevops/axel@VERSION/dist/FILE
187
189
  ```
188
190
 
189
- The script starts tracking as soon as it loads. Its listeners sit on `document`, so it can load in `<head>` before the rest of the page. To change the defaults, see [Settings](#settings).
191
+ The same files are in the `dist/` folder of the [`@drevops/axel`](https://www.npmjs.com/package/@drevops/axel) npm package, and in the assets of each [GitHub release](https://github.com/drevops/axel/releases/latest).
192
+
193
+ Pin an exact version such as `0.3.0`. A range such as `@0` or `@latest` serves a different file after the next release, so its Subresource Integrity hash stops matching and the browser blocks the script. The notes of each release list the jsDelivr URL and hash of every bundle, plus a ready-made `<script>` tag. [`SECURITY.md`](SECURITY.md#verify-a-bundle) explains how to verify a file you downloaded.
190
194
 
191
- To load the bundle from a CDN, such as jsDelivr serving the npm package, add its Subresource Integrity hash. The browser then refuses to run a file that differs from the release:
195
+ ### Plain page
196
+
197
+ To load the bundle from jsDelivr, add it with its Subresource Integrity hash. The browser then refuses to run a file that differs from the release:
192
198
 
193
199
  ```html
194
200
  <script
195
- src="https://cdn.jsdelivr.net/npm/@drevops/axel@VERSION/build/axel.gtm.min.js"
201
+ src="https://cdn.jsdelivr.net/npm/@drevops/axel@VERSION/dist/axel.gtm.min.js"
196
202
  integrity="sha384-HASH"
197
203
  crossorigin="anonymous"
198
204
  ></script>
199
205
  ```
200
206
 
201
- Replace `VERSION` with a release version such as `0.1.1`. Replace `sha384-HASH` with the bundle's hash from that release's notes.
207
+ Replace `VERSION` with a release version such as `0.3.0`. Replace `sha384-HASH` with the bundle's hash from that release's notes.
208
+
209
+ To serve the bundle from your own site, copy it from `node_modules/@drevops/axel/dist/` after `npm install @drevops/axel`, or from the GitHub release. Then add it to your pages:
210
+
211
+ ```html
212
+ <script src="/path/to/axel.gtm.min.js"></script>
213
+ ```
214
+
215
+ The script starts tracking as soon as it loads. Its listeners sit on `document`, so it can load in `<head>` before the rest of the page. To change the defaults, see [Settings](#settings).
202
216
 
203
217
  ### Drupal
204
218
 
205
- Define a library that loads a Drupal bundle:
219
+ To load the bundle from jsDelivr, define a library in your module or theme that points at the CDN, with the bundle's hash:
206
220
 
207
221
  ```yaml
208
222
  axel:
209
223
  js:
210
- js/axel.drupal.gtm.min.js: { minified: true }
224
+ https://cdn.jsdelivr.net/npm/@drevops/axel@VERSION/dist/axel.drupal.gtm.min.js:
225
+ type: external
226
+ minified: true
227
+ attributes:
228
+ integrity: sha384-HASH
229
+ crossorigin: anonymous
211
230
  dependencies:
212
231
  - core/drupal
213
232
  - core/drupalSettings
214
233
  ```
215
234
 
235
+ To serve the bundle from your own site instead, install it with Composer. [Asset Packagist](https://asset-packagist.org) offers npm packages as Composer packages, and `@drevops/axel` is `npm-asset/drevops--axel` there. To install it into `web/libraries`:
236
+
237
+ 1. Add Asset Packagist as a repository and require the package:
238
+
239
+ ```bash
240
+ composer config repositories.asset-packagist composer https://asset-packagist.org
241
+ composer require oomphinc/composer-installers-extender npm-asset/drevops--axel
242
+ ```
243
+
244
+ 2. In `composer.json`, add `npm-asset` to `extra.installer-types` and add `"type:npm-asset"` to the `web/libraries/{$name}` entry in `extra.installer-paths`. Then run `composer install`. The bundles land in `web/libraries/drevops--axel/dist/`.
245
+
246
+ 3. Define a library in your module or theme that loads a Drupal bundle:
247
+
248
+ ```yaml
249
+ axel:
250
+ js:
251
+ /libraries/drevops--axel/dist/axel.drupal.gtm.min.js: { minified: true }
252
+ dependencies:
253
+ - core/drupal
254
+ - core/drupalSettings
255
+ ```
256
+
216
257
  The bundle registers the `axel` behavior. The behavior starts tracking when it first attaches and reads its settings from `drupalSettings.axel`. Later attaches, such as after an AJAX request, change nothing.
217
258
 
218
259
  ### ES module
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drevops/axel",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Turns clicks and form interactions on elements marked with data-axel-* attributes into analytics events.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -16,14 +16,16 @@
16
16
  "homepage": "https://github.com/drevops/axel#readme",
17
17
  "bugs": "https://github.com/drevops/axel/issues",
18
18
  "type": "module",
19
- "main": "build/axel.esm.js",
20
- "module": "build/axel.esm.js",
19
+ "main": "dist/axel.esm.js",
20
+ "module": "dist/axel.esm.js",
21
21
  "exports": {
22
- ".": "./build/axel.esm.js",
23
- "./build/*": "./build/*"
22
+ ".": "./dist/axel.esm.js",
23
+ "./dist/*": "./dist/*"
24
24
  },
25
+ "jsdelivr": "dist/axel.gtm.min.js",
26
+ "unpkg": "dist/axel.gtm.min.js",
25
27
  "files": [
26
- "build",
28
+ "dist",
27
29
  "src"
28
30
  ],
29
31
  "publishConfig": {
@@ -42,7 +44,7 @@
42
44
  "test-coverage": "vitest run --coverage",
43
45
  "pretest-functional": "npm run build",
44
46
  "test-functional": "playwright test",
45
- "reset": "rm -Rf node_modules build .logs"
47
+ "reset": "rm -Rf node_modules dist .logs"
46
48
  },
47
49
  "engines": {
48
50
  "npm": ">=10",
@@ -1,13 +0,0 @@
1
- 91e90bde9c2e2480c37cf0c35356c387f24f11ffdbe74012a4359eda2a98afd8 axel.drupal.gtag.js
2
- 0a95adb6e21257f20b079de967b90bcad0f61d8c1f00d9b70d2bc12ecd54cf38 axel.drupal.gtag.min.js
3
- 91f32822f91b94b0d6f9d9652d4f3cbb70a2f62a501851d72b9a9be1fcfa1605 axel.drupal.gtm.js
4
- 96a5afa7aaf61ca1d31d3339a64027c3329e4fa105c79407c7676e5b803bcf40 axel.drupal.gtm.min.js
5
- 93cf10260ee54462801f61f0286468378c7bb0ea08947aadfa966fdb41428517 axel.drupal.js
6
- 7db393905da736bfc144b14fde3f566519960324baf40d08c5142d5e55cb2823 axel.drupal.min.js
7
- 8c486331fbf9b8229250e07582e2ed84be9ca44254e34685b25aec96407ed3f7 axel.esm.js
8
- 6a408e47149b8faea44e2c2d5e2b126175810a9ef30ec58131bee7fab14b7754 axel.gtag.js
9
- 450a4ec7f98284332ca8008a6185be466181e898ef5690bcac539156508bea7f axel.gtag.min.js
10
- fa392146d502c0288fee88c005332092c6ceca4e65fdd8d4711e724f32a9c6a6 axel.gtm.js
11
- 602587e126909cd0acfcf212d2568257f39ac4ccaab7f9b843f5022d988b9e87 axel.gtm.min.js
12
- 2dca0071297b0ce4684baa8301a9927434fc663fe3c5353db4605a7e4f4c0354 axel.js
13
- e5e2d976430559760b57b872c01598f5d4b1a45f37f85de8951068031e7a3a7b axel.min.js
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes