Skip to content

Commit

Permalink
Merge pull request #1385 from dpc-sdp/feature/route-topics-and-tags
Browse files Browse the repository at this point in the history
[SD-504] routeChange topic and tags
  • Loading branch information
lambry authored Nov 19, 2024
2 parents 0d7ebf2 + 3c8f9ae commit bb07d60
Show file tree
Hide file tree
Showing 10 changed files with 1,004 additions and 14 deletions.
8 changes: 6 additions & 2 deletions examples/nuxt-app/test/features/site/analytics.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ Feature: Analytics
And the page endpoint for path "/" returns fixture "/landingpage/home" with status 200
Given I visit the page "/"
Then the dataLayer should include the following events
| event | page_title | page_url | content_type | content_status |
| routeChange | Demo Landing Page | / | landing_page | published |
| event | page_title | page_url | content_type | content_status | content_topic |
| routeChange | Demo Landing Page | / | landing_page | published | Demo Topic |
Then the dataLayer should have the following tags
| name |
| Demo Tag |
| Another Demo Tag |

@mockserver
Scenario: Breadcrumbs
Expand Down
7 changes: 4 additions & 3 deletions examples/nuxt-app/test/features/site/shared-elements.feature
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ Feature: Shared site elements
Given I visit the page "/some-random-page"

Then the page should have the following topic tags
| text | url |
| Demo Topic | /topic/demo-topic |
| Demo Tag | /tags/demo-tag |
| text | url |
| Demo Topic | /topic/demo-topic |
| Demo Tag | /tags/demo-tag |
| Another Demo Tag | /tags/another-demo-tag |

@mockserver
Scenario: Content Rating (visible)
Expand Down
18 changes: 18 additions & 0 deletions examples/nuxt-app/test/fixtures/landingpage/home.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@
{
"text": "Demo Tag",
"url": "/tags/demo-tag"
},
{
"text": "Another Demo Tag",
"url": "/tags/another-demo-tag"
}
],
"topic": {
"text": "Demo Topic",
"url": "/topic/demo-topic"
},
"tags": [
{
"text": "Demo Tag",
"url": "/tags/demo-tag"
},
{
"text": "Another Demo Tag",
"url": "/tags/another-demo-tag"
}
],
"sidebar": {
Expand Down
6 changes: 6 additions & 0 deletions packages/nuxt-ripple-analytics/lib/routeChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import { getBreadcrumbs } from '#imports'
const trimValue = (value: any) =>
typeof value === 'string' ? value.trim() : value

const mapTags = (items: { text: string }[]) => {
return (items || []).map((item) => item?.text)
}

export default function ({ route, site, page }): IRplAnalyticsEventPayload {
const payload: IRplAnalyticsEventPayload = {
event: 'routeChange',
page_title: page?.title,
page_url: route.fullPath,
content_type: page?.type,
content_status: page?.status,
content_topic: page?.topic?.text,
content_tags: mapTags(page?.tags),
publication_name: page?.publication?.text,
search_term: trimValue(route.query?.q),
site_section: page?.siteSection?.name,
Expand Down
2 changes: 2 additions & 0 deletions packages/nuxt-ripple-analytics/lib/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface IRplAnalyticsEventPayload {
status_code?: number
content_type?: string
content_status?: string
content_topic?: string
content_tags?: string[]
search_term?: string
site_section?: string
publication_name?: string
Expand Down
4 changes: 4 additions & 0 deletions packages/nuxt-ripple/mapping/base/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
map as topicTagsMapping,
tagMap as tagMapping,
topicMap as topicMapping,
includes as topicTagsIncludes
} from './topic-tags/topic-tags-mapping.js'
import {
Expand Down Expand Up @@ -68,6 +70,8 @@ export const tidePageBaseMapping = ({
sidebar: sidebar,
status: 'moderation_state',
topicTags: topicTagsMapping,
tags: (src) => tagMapping(src?.field_tags),
topic: (src) => topicMapping(src?.field_topic),
siteSection: async (src) => {
// With the correct site/section id, we can now choose the correct site data from 'field_node_site'
const siteData = getSiteSection(src._sectionId, src)
Expand Down
Loading

0 comments on commit bb07d60

Please sign in to comment.