Skip to content

Commit

Permalink
Merge pull request #164 from globeandmail/feature/update-schema-sit-2793
Browse files Browse the repository at this point in the history
Add hostname and path fields to schema
  • Loading branch information
Rahmon authored Jan 12, 2022
2 parents f6e472f + 7378c5d commit 64263f8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions includes/functions/content-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function send_track_event( $tracker, $post, $action ) {

$tracker->trackUnstructEvent(
[
'schema' => 'iglu:com.sophi/content_update/jsonschema/2-0-0',
'schema' => 'iglu:com.sophi/content_update/jsonschema/2-0-3',
'data' => $data,
],
[
Expand Down Expand Up @@ -189,6 +189,7 @@ function get_post_data( $post ) {
$content = str_replace( ']]>', ']]>', $content );
$canonical_url = wp_get_canonical_url( $post );
$keywords = '';
$permalink = get_permalink( $post );

// Support Yoast SEO canonical URL and focus keyphrase.
if ( class_exists( 'WPSEO_Meta' ) ) {
Expand All @@ -200,6 +201,10 @@ function get_post_data( $post ) {
$keywords = get_post_meta( $post->ID, '_yoast_wpseo_focuskw', true );
}

$parsed_url = wp_parse_url( $permalink );
$hostname = $parsed_url['host'] ?? '';
$path = $parsed_url['path'] ?? '';

$data = [
'contentId' => strval( $post->ID ),
'headline' => get_the_title( $post ),
Expand All @@ -211,7 +216,7 @@ function get_post_data( $post ) {
'sectionNames' => Utils\get_post_categories( $post->ID ),
'modifiedAt' => gmdate( \DateTime::RFC3339, strtotime( $post->post_modified_gmt ) ),
'tags' => Utils\get_post_tags( $post ),
'url' => get_permalink( $post ),
'url' => $permalink,
'type' => Utils\get_post_content_type( $post ),
'promoImageUri' => '',
'thumbnailImageUri' => get_the_post_thumbnail_url( $post, 'full' ),
Expand All @@ -226,12 +231,14 @@ function get_post_data( $post ) {
'editorialAccessName' => '',
'subtype' => '',
'redirectToUrl' => '',
'hostname' => $hostname,
'path' => $path,
];

$data = array_filter( $data );

// Add canonical after filtering the falsy items.
$data['isCanonical'] = untrailingslashit( $canonical_url ) === untrailingslashit( get_permalink( $post ) );
$data['isCanonical'] = untrailingslashit( $canonical_url ) === untrailingslashit( $permalink );

/**
* Filter post data for content sync events (aka "CMS updates" in Sophi.io terms) sent to Sophi Collector. This allows control over data before it is sent to Collector in case it needs to be modified for unique site needs. Note that if you add, change, or remove any fields with this that those changes will need to be coordinated with the Sophi.io team to ensure content is appropriately received by Collector.
Expand Down

0 comments on commit 64263f8

Please sign in to comment.