Skip to content

Commit

Permalink
Release 3.1.3 (#725)
Browse files Browse the repository at this point in the history
* Improving type support on categories metadata (#723)

* Improving type support on categories metadata

* Update src/class-parsely.php

Co-authored-by: Gary Jones <[email protected]>

* Update src/class-parsely.php

Co-authored-by: Gary Jones <[email protected]>

Co-authored-by: Gary Jones <[email protected]>

* Fix type errors when getting authors (#722)

* Fix type errors when getting authors

* Update src/class-parsely.php

Co-authored-by: Gary Jones <[email protected]>

* Update src/class-parsely.php

Co-authored-by: Gary Jones <[email protected]>

Co-authored-by: Gary Jones <[email protected]>

* Updating Changelog and version numbers

* Pulling README changes from develop

Co-authored-by: Gary Jones <[email protected]>
  • Loading branch information
pauarge and GaryJones authored Mar 17, 2022
1 parent f94a495 commit 10d4890
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 141 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.1.3] - 2022-03-17

### Fixed

- Fix rare errors when getting authors metadata. The error occurred on posts that contained malformed authors. [#722](https://github.com/Parsely/wp-parsely/pull/722)
- Improve type definitions on categories metadata generation. [#723](https://github.com/Parsely/wp-parsely/pull/723)

## [3.1.2] - 2022-02-24

### Added
Expand Down Expand Up @@ -541,6 +548,7 @@ If you are using the plugin without any code-level customizations (for instance,
- Initial version.
- Add support for parsely-page and JavaScript on home page and published pages and posts as well as archive pages (date/author/category/tag).

[3.1.3]: https://github.com/Parsely/wp-parsely/compare/3.1.2...3.1.3
[3.1.2]: https://github.com/Parsely/wp-parsely/compare/3.1.1...3.1.2
[3.1.1]: https://github.com/Parsely/wp-parsely/compare/3.1.0...3.1.1
[3.1.0]: https://github.com/Parsely/wp-parsely/compare/3.0.4...3.1.0
Expand Down
142 changes: 34 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Parse.ly

Stable tag: 3.1.2
Stable tag: 3.1.3
Requires at least: 5.0
Tested up to: 5.9.1
Tested up to: 5.9.2
Requires PHP: 7.1
License: GPLv2 or later
Tags: analytics, parse.ly, parsely, parsley
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: analytics, content marketing, parse.ly, parsely, parsley
Contributors: parsely, hbbtstar, jblz, mikeyarce, GaryJ, parsely_mike, pauargelaguet, acicovic

The Parse.ly plugin facilitates real-time and historical analytics to your content through a platform designed and built for digital publishing.
Expand All @@ -27,9 +28,15 @@ Join industry leaders -- like Mashable, Slate, News Corp, and Conde Nast -- who

Feedback, suggestions, questions or concerns? Open a new [GitHub issue](https://github.com/Parsely/wp-parsely/issues) or email us at [[email protected]](mailto:[email protected]). We always want to hear from you!

### Documentation

If you are looking for the plugin's documentation and how to set up your WordPress site with Parse.ly, take a look at [the Parse.ly integration docs](https://www.parsely.com/help/integration/wordpress).

In case you are a WordPress VIP customer, [VIP's documentation](https://docs.wpvip.com/technical-references/plugins/parse-ly/) will be also useful for you.

## Installation

The plugin requires an active Parse.ly account. Parse.ly gives creators, marketers, and developers the tools to understand content performance, prove content value, and deliver tailored content experiences that drive meaningful results. [Sign up for a free demo of Parse.ly](https://www.parsely.com/getdemo?utm_medium=referral&utm_source=wordpress.org&utm_content=wp-parsely).
The plugin requires an active Parse.ly account. [Sign up for a free demo of Parse.ly](https://www.parsely.com/getdemo?utm_medium=referral&utm_source=wordpress.org&utm_content=wp-parsely).

### Install the plugin from within WordPress

Expand All @@ -46,104 +53,37 @@ The plugin requires an active Parse.ly account. Parse.ly gives creators, markete
4. Visit the Plugins page from your WordPress dashboard and look for the newly installed Parse.ly plugin.
5. Click _Activate_ to activate the plugin on your site.

## Local development

To run the plugin locally or to contribute to it, please check the instructions in the [CONTRIBUTING](CONTRIBUTING.md) file.

## REST API

The plugin adds a `parsely` field to certain REST API responses. This can be disabled by returning `false` from the `wp_parsely_enable_rest_api_support` filter.

Example:

```
// Disable all REST API output from the Parse.ly plugin.
add_filter( 'wp_parsely_enable_rest_api_support', '__return_false' );
```

The plugin adds the `parsely` field to endpoints corresponding to the Tracked Post Types and Tracked Page Types selected in the plugin settings. By default, this would be the `/wp-json/wp/v2/pages` and `/wp-json/wp/v2/posts` endpoints along with the corresponding single resource endpoints.

This choice of objects types can be further changed by using the `wp_parsely_rest_object_types` filter.

Example:

```
// Disable REST API output from pages, but enable for term archives.
add_filter(
'wp_parsely_rest_object_types',
function( $object_types ) {
$object_types = array_diff( $object_types, array( 'page' ) );
$object_types[] = 'term';
return $object_types;
}
);
```

The `parsely` field contains the following fields:
- `version`, which is a string identifying the version of the REST API output; this will be updated if changes are made to the output, so consuming applications can check against it.
- `meta`, which is an array of metadata for the specific post, page or other object type.
- `rendered`, which is the rendered HTML of the metadata for the post, page or other object type. This will be a JSON-LD `<script>` tag, or a set of `<meta>` tags, depending on the format selected in the plugin settings. The decoupled code can consume and use this directly, instead of building the values from the `meta` field values.

The `rendered` field is a convenience field containing the HTML-formatted metadata which can be printed to a decoupled page as is.

This can be disabled by returning `false` from the `wp_parsely_enable_rest_rendered_support` filter.

Example:

```
// Disable rendered field output from the REST API output.
add_filter( 'wp_parsely_enable_rest_rendered_support', '__return_false' );
```

## Frequently Asked Questions

### Where do I find my Site ID?

Your Site ID is likely your own site domain name (e.g., `mysite.com`). You can find this in your Parse.ly account.

### Why can't I see Parse.ly code on my post when I preview?
Note that this method is the recommended one for installing old versions of the plugin. Those can be downloaded from [WordPress.org](https://wordpress.org/plugins/wp-parsely/advanced/) or the GitHub Releases page.

The code will only be placed on posts and pages which have been published in WordPress to ensure we don't track traffic generated while you're still writing a post or page.

You may also be not tracking logged-in users, via one of the settings.

### How can I edit the values passed to the JSON-LD metadata?

You can use the `wp_parsely_metadata` filter, which sends three arguments: the array of metadata, the post object, and the `parsely_options` array:

add_filter( 'wp_parsely_metadata', 'filter_parsely_metadata', 10, 3 );
function filter_parsely_metadata( $parsely_metadata, $post, $parsely_options ) {
$parsely_metadata['articleSection'] = '...'; // Whatever values you want Parse.ly's Section to be.
return $parsely_metadata;
}

This filter can go anywhere in your codebase, provided it always gets loaded.

### Is the plugin compatible with AMP and Facebook Instant Articles?

It is! The plugin hooks into Automattic's official plugins for [AMP](https://wordpress.org/plugins/amp/) and [Facebook Instant Articles](https://wordpress.org/plugins/fb-instant-articles/).

AMP support is enabled automatically if the Automattic AMP plugin is installed.
## Local development

For Facebook Instant Articles support, enable "Parsely Analytics" in the "Advanced Settings" menu of the Facebook Instant Articles plugin.
Development, code hosting and issue tracking of this plugin happens on the [wp-parsely GitHub repository](https://github.com/Parsely/wp-parsely/). Active development happens on the `develop` branch and releases are made off the `trunk` branch.

### Does the plugin support dynamic tracking?
To run the plugin locally or to contribute to it, please check the instructions in the [CONTRIBUTING](https://github.com/parsely/wp-parsely/blob/trunk/CONTRIBUTING.md) file.

This plugin does not currently support dynamic tracking (the tracking of multiple pageviews on a single page).
## Sample Parse.ly metadata

Some common use-cases for dynamic tracking are slideshows or articles loaded via AJAX calls in single-page applications -- situations in which new content is loaded without a full page refresh.
The standard Parse.ly JavaScript tracker inserted before the closing `body` tag:

Tracking these events requires manually implementing additional JavaScript above [the standard Parse.ly include](http://www.parsely.com/help/integration/basic/) that the plugin injects into your page source. Please consult [the Parse.ly documentation on dynamic tracking](https://www.parsely.com/help/integration/dynamic/) for instructions on implementing dynamic tracking, or contact Parse.ly support for additional assistance.
~~~html
<script id="parsely-cfg" data-parsely-site="example.com" src="https://cdn.parsely.com/keys/example.com/p.js"></script>
~~~

### Cloudflare support
A sample `JSON-LD` structured data for a home page or section page:

If the site is running behind a Cloudflare DNS, their Rocket Loader technology will alter how JavaScript files are loaded. [A JavaScript file can be ignored by Rocket Loader](https://support.cloudflare.com/hc/en-us/articles/200169436-How-can-I-have-Rocket-Loader-ignore-specific-JavaScripts) by using `data-cfasync="false"`.
~~~html
<script type="application/ld+json">
{"@context":"http:\/\/schema.org","@type":"WebPage","headline":"WordPress VIP","url":"http:\/\/wpvip.com\/"}
</script>
~~~

Previous versions of this plugin would mark all scripts with that tag by default. Starting in version 3.0, that behavior has become optional and scripts won't be annotated with `data-cfasync="false"`. The previous behavior can be restored by adding the following filter:
A sample `JSON-LD` meta tag and structured data for an article or post:

```
add_filter( 'wp_parsely_enable_cfasync_attribute', '__return_true' );
```
~~~html
<script type="application/ld+json">
{"@context":"http:\/\/schema.org","@type":"NewsArticle","mainEntityOfPage":{"@type":"WebPage","@id":"http:\/\/wpvip.com\/2021\/04\/09\/how-the-wordpress-gutenberg-block-editor-empowers-enterprise-content-creators\/"},"headline":"How the WordPress Gutenberg Block Editor Empowers Enterprise Content Creators","url":"http:\/\/wpvip.com\/2021\/04\/09\/how-the-wordpress-gutenberg-block-editor-empowers-enterprise-content-creators\/","thumbnailUrl":"https:\/\/wpvip.com\/wp-content\/uploads\/2021\/04\/ladyatdesk.png?w=120","image":{"@type":"ImageObject","url":"https:\/\/wpvip.com\/wp-content\/uploads\/2021\/04\/ladyatdesk.png?w=120"},"dateCreated":"2021-04-09T15:13:13Z","datePublished":"2021-04-09T15:13:13Z","dateModified":"2021-04-09T15:13:13Z","articleSection":"Gutenberg","author":[{"@type":"Person","name":"Sam Wendland"}],"creator":["Sam Wendland"],"publisher":{"@type":"Organization","name":"The Enterprise Content Management Platform | WordPress VIP","logo":"https:\/\/wpvip.com\/wp-content\/uploads\/2020\/11\/cropped-favicon-dark.png"},"keywords":[]}
</script>
~~~

## Screenshots

Expand All @@ -158,23 +98,9 @@ add_filter( 'wp_parsely_enable_cfasync_attribute', '__return_true' );
5. A view of the Parse.ly Dashboard Overview. Parse.ly offers analytics that empowers you to better understand how your content is peforming.
![The Parsely Dashboard Overview](.wordpress-org/screenshot-5.png)

## Sample Parse.ly metadata

The standard Parse.ly JavaScript tracker inserted before the closing `body` tag:

<script id="parsely-cfg" data-parsely-site="example.com" src="https://cdn.parsely.com/keys/example.com/p.js"></script>

A sample `JSON-LD` structured data for a home page or section page:

<script type="application/ld+json">
{"@context":"http:\/\/schema.org","@type":"WebPage","headline":"WordPress VIP","url":"http:\/\/wpvip.com\/"}
</script>

A sample `JSON-LD` meta tag and structured data for an article or post:
## Frequently Asked Questions

<script type="application/ld+json">
{"@context":"http:\/\/schema.org","@type":"NewsArticle","mainEntityOfPage":{"@type":"WebPage","@id":"http:\/\/wpvip.com\/2021\/04\/09\/how-the-wordpress-gutenberg-block-editor-empowers-enterprise-content-creators\/"},"headline":"How the WordPress Gutenberg Block Editor Empowers Enterprise Content Creators","url":"http:\/\/wpvip.com\/2021\/04\/09\/how-the-wordpress-gutenberg-block-editor-empowers-enterprise-content-creators\/","thumbnailUrl":"https:\/\/wpvip.com\/wp-content\/uploads\/2021\/04\/ladyatdesk.png?w=120","image":{"@type":"ImageObject","url":"https:\/\/wpvip.com\/wp-content\/uploads\/2021\/04\/ladyatdesk.png?w=120"},"dateCreated":"2021-04-09T15:13:13Z","datePublished":"2021-04-09T15:13:13Z","dateModified":"2021-04-09T15:13:13Z","articleSection":"Gutenberg","author":[{"@type":"Person","name":"Sam Wendland"}],"creator":["Sam Wendland"],"publisher":{"@type":"Organization","name":"The Enterprise Content Management Platform | WordPress VIP","logo":"https:\/\/wpvip.com\/wp-content\/uploads\/2020\/11\/cropped-favicon-dark.png"},"keywords":[]}
</script>
See [frequently asked questions](https://www.parse.ly/help/integration/wordpress#frequently-asked-questions) on the Parse.ly Technical Documentation.

## Changelog

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-parsely",
"version": "3.1.2",
"version": "3.1.3",
"private": true,
"description": "The Parse.ly plugin facilitates real-time and historical analytics to your content through a platform designed and built for digital publishing.",
"author": "parsely, hbbtstar, jblz, mikeyarce, GaryJ, parsely_mike, pauarge",
Expand Down
54 changes: 27 additions & 27 deletions src/class-parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public function construct_parsely_metadata( array $parsely_options, WP_Post $pos
if ( $parsely_options['cats_as_tags'] ) {
$tags = array_merge( $tags, $this->get_categories( $post->ID ) );
// add custom taxonomy values.
$tags = array_merge( $tags, $this->get_custom_taxonomy_values( $post, $parsely_options ) );
$tags = array_merge( $tags, $this->get_custom_taxonomy_values( $post ) );
}
// the function 'mb_strtolower' is not enabled by default in php, so this check
// falls back to the native php function 'strtolower' if necessary.
Expand Down Expand Up @@ -678,7 +678,7 @@ private function get_tags( int $post_id ): array {
*
* @param int $post_id The id of the post you're trying to get categories for.
* @param string $delimiter What character will delimit the categories.
* @return array All the child categories of the current post.
* @return array<string> All the child categories of the current post.
*/
private function get_categories( int $post_id, string $delimiter = '/' ): array {
$tags = array();
Expand All @@ -691,7 +691,7 @@ private function get_categories( int $post_id, string $delimiter = '/' ): array
// take last element in the hierarchy, a string representing the full parent->child tree,
// and split it into individual category names.
$last_tag = end( $tags );
if ( $last_tag ) {
if ( false !== $last_tag ) {
$tags = explode( '/', $last_tag );
}

Expand Down Expand Up @@ -814,24 +814,22 @@ private function get_bottom_level_term( int $post_id, string $taxonomy_name ): s
* Get all term values from custom taxonomies.
*
* @param WP_Post $post_obj The post object.
* @param array $parsely_options Unused? The parsely options.
* @return array
* @return array<string>
*/
private function get_custom_taxonomy_values( WP_Post $post_obj, array $parsely_options ): array {
private function get_custom_taxonomy_values( WP_Post $post_obj ): array {
// filter out default WordPress taxonomies.
$all_taxonomies = array_diff( get_taxonomies(), array( 'post_tag', 'nav_menu', 'author', 'link_category', 'post_format' ) );
$all_values = array();

if ( is_array( $all_taxonomies ) ) {
foreach ( $all_taxonomies as $taxonomy ) {
$custom_taxonomy_objects = get_the_terms( $post_obj->ID, $taxonomy );
if ( is_array( $custom_taxonomy_objects ) ) {
foreach ( $custom_taxonomy_objects as $custom_taxonomy_object ) {
array_push( $all_values, $custom_taxonomy_object->name );
}
foreach ( $all_taxonomies as $taxonomy ) {
$custom_taxonomy_objects = get_the_terms( $post_obj->ID, $taxonomy );
if ( is_array( $custom_taxonomy_objects ) ) {
foreach ( $custom_taxonomy_objects as $custom_taxonomy_object ) {
$all_values[] = $custom_taxonomy_object->name;
}
}
}

return $all_values;
}

Expand All @@ -841,7 +839,7 @@ private function get_custom_taxonomy_values( WP_Post $post_obj, array $parsely_o
* https://github.com/Automattic/Co-Authors-Plus/blob/master/template-tags.php#L3-35
*
* @param int $post_id The id of the post.
* @return array
* @return array<WP_User>
*/
private function get_coauthor_names( int $post_id ): array {
$coauthors = array();
Expand Down Expand Up @@ -889,39 +887,41 @@ private function get_coauthor_names( int $post_id ): array {
* @return string
*/
private function get_author_name( ?WP_User $author ): string {
// gracefully handle situation where no author is available.
if ( empty( $author ) || ! is_object( $author ) ) {
// Gracefully handle situation where no author is available.
if ( null === $author ) {
return '';
}

$author_name = $author->display_name;
if ( ! empty( $author_name ) ) {
return $author_name;
if ( ! empty( $author->display_name ) ) {
return $author->display_name;
}

$author_name = $author->user_firstname . ' ' . $author->user_lastname;
if ( ' ' !== $author_name ) {
return $author_name;
}

$author_name = $author->nickname;
if ( ! empty( $author_name ) ) {
return $author_name;
if ( ! empty( $author->nickname ) ) {
return $author->nickname;
}

return $author->user_nicename;
if ( ! empty( $author->user_nicename ) ) {
return $author->user_nicename;
}

return '';
}

/**
* Retrieve all the authors for a post as an array. Can include multiple
* authors if coauthors plugin is in use.
*
* @param WP_Post $post The post object.
* @return array
* @return array<string>
*/
private function get_author_names( WP_Post $post ): array {
$authors = $this->get_coauthor_names( $post->ID );
if ( empty( $authors ) ) {
if ( 0 === count( $authors ) ) {
$post_author = get_user_by( 'id', $post->post_author );
if ( false !== $post_author ) {
$authors = array( $post_author );
Expand Down Expand Up @@ -950,8 +950,8 @@ private function get_author_names( WP_Post $post ): array {
* @param WP_Post $post Post object.
*/
$authors = apply_filters( 'wp_parsely_post_authors', $authors, $post );
$authors = array_map( array( $this, 'get_clean_parsely_page_value' ), $authors );
return $authors;

return array_map( array( $this, 'get_clean_parsely_page_value' ), $authors );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { visitAdminPage } from '@wordpress/e2e-test-utils';

export const PLUGIN_VERSION = '3.1.2';
export const PLUGIN_VERSION = '3.1.3';

export const waitForWpAdmin = () => page.waitForSelector( 'body.wp-admin' );

Expand Down
4 changes: 2 additions & 2 deletions wp-parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Parse.ly
* Plugin URI: https://www.parse.ly/help/integration/wordpress
* Description: This plugin makes it a snap to add Parse.ly tracking code to your WordPress blog.
* Version: 3.1.2
* Version: 3.1.3
* Author: Parse.ly
* Author URI: https://www.parse.ly
* Text Domain: wp-parsely
Expand Down Expand Up @@ -40,7 +40,7 @@
return;
}

const PARSELY_VERSION = '3.1.2';
const PARSELY_VERSION = '3.1.3';
const PARSELY_FILE = __FILE__;

require __DIR__ . '/src/class-parsely.php';
Expand Down

0 comments on commit 10d4890

Please sign in to comment.