@automattic/jetpack-shared-extension-utils 0.8.4 → 0.9.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/CHANGELOG.md +5 -0
- package/package.json +1 -1
- package/src/hooks/readme.md +33 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.9.0] - 2023-02-20
|
|
9
|
+
### Added
|
|
10
|
+
- Add a new section to describe including assets from backend [#29016]
|
|
11
|
+
|
|
8
12
|
## [0.8.4] - 2023-02-15
|
|
9
13
|
### Changed
|
|
10
14
|
- Update to React 18. [#28710]
|
|
@@ -169,6 +173,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
169
173
|
### Changed
|
|
170
174
|
- Core: prepare utility for release
|
|
171
175
|
|
|
176
|
+
[0.9.0]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.8.4...0.9.0
|
|
172
177
|
[0.8.4]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.8.3...0.8.4
|
|
173
178
|
[0.8.3]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.8.2...0.8.3
|
|
174
179
|
[0.8.2]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.8.1...0.8.2
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/jetpack-shared-extension-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Utility functions used by the block editor extensions",
|
|
5
5
|
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/shared-extension-utils/#readme",
|
|
6
6
|
"bugs": {
|
package/src/hooks/readme.md
CHANGED
|
@@ -10,6 +10,37 @@ use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
|
|
|
10
10
|
wp_add_inline_script( 'your-app-script-handle-in-editor', Connection_Initial_State::render(), 'before' );
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
Adding Tracks related class and including the check function in your admin ui page:
|
|
14
|
+
```php
|
|
15
|
+
use Automattic\Jetpack\Status as Status;
|
|
16
|
+
use Automattic\Jetpack\Terms_Of_Service;
|
|
17
|
+
use Automattic\Jetpack\Tracking;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns whether we are in condition to track to use
|
|
21
|
+
* Analytics functionality like Tracks, MC, or GA.
|
|
22
|
+
*/
|
|
23
|
+
public static function can_use_analytics() {
|
|
24
|
+
$status = new Status();
|
|
25
|
+
$connection = new Connection_Manager();
|
|
26
|
+
$tracking = new Tracking( 'jetpack', $connection );
|
|
27
|
+
|
|
28
|
+
return $tracking->should_enable_tracking( new Terms_Of_Service(), $status );
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then adding the assets in the `enqueue_admin_scripts` function after the `Assets::register_script` function:
|
|
33
|
+
```php
|
|
34
|
+
public function enqueue_admin_scripts() {
|
|
35
|
+
...
|
|
36
|
+
// Required for Analytics.
|
|
37
|
+
if ( self::can_use_analytics() ) {
|
|
38
|
+
Tracking::register_tracks_functions_scripts( true );
|
|
39
|
+
}
|
|
40
|
+
...
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
13
44
|
## Usage
|
|
14
45
|
|
|
15
46
|
```es6
|
|
@@ -23,7 +54,7 @@ tracks.recordEvent( 'jetpack_editor_block_upgrade_click', {
|
|
|
23
54
|
```
|
|
24
55
|
|
|
25
56
|
The hook function also accepts parameters to record a "page view" event when the component renders.
|
|
26
|
-
You can also import a wrapped version of `recordEvent` that checks for a Jetpack connected user before actually recording the event.
|
|
57
|
+
You can also import a wrapped version of `recordEvent` that checks for a Jetpack connected user before actually recording the event.
|
|
27
58
|
|
|
28
59
|
```es6
|
|
29
60
|
const Component = () => {
|
|
@@ -33,7 +64,7 @@ const Component = () => {
|
|
|
33
64
|
pageViewSuffix: '',
|
|
34
65
|
} );
|
|
35
66
|
const recordClick = useCallback( () => { recordEvent( 'event_name', {} ) }, [] );
|
|
36
|
-
|
|
67
|
+
|
|
37
68
|
return (
|
|
38
69
|
<Button
|
|
39
70
|
onClick={ recordClick }
|