(#5278) Blog Analytics Helper#5291
Conversation
1f342ad to
76fe1c4
Compare
There was a problem hiding this comment.
Pull request overview
Adds dedicated analytics tracking for NCIDS blog experiences (blog series list, right-rail links, and pager links) to meet the new EDDL event requirements from issues #5278–#5280, while preventing legacy dynamic-list tracking from firing on legacy blog series pages.
Changes:
- Introduces
blog-analytics-helperwith three analytics helpers that emit the required EDDLtrackOtherevents. - Adds Jest tests validating payload shape, truncation, pageType handling, and “only once per click” behavior.
- Updates the blogs entrypoint to initialize the new helpers and adjusts legacy jQuery analytics to skip blog series dynamic-list tracking.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| docroot/profiles/custom/cgov_site/themes/custom/ncids_trans/front-end/src/lib/core/analytics/blog-analytics-helper.ts | Implements new EDDL click events for blog series list, right rail, and pager interactions. |
| docroot/profiles/custom/cgov_site/themes/custom/ncids_trans/front-end/src/lib/core/analytics/tests/blog-analytics-helper.test.ts | Adds unit tests covering new tracking behavior and duplicate-handler prevention. |
| docroot/profiles/custom/cgov_site/themes/custom/ncids_trans/front-end/src/entrypoints/blogs/blogs.ts | Wires the new analytics helpers into the blogs bundle on DOMContentLoaded. |
| docroot/profiles/custom/cgov_site/themes/custom/cgov/cgov_common/src/libraries/analytics/analytics.js | Prevents legacy DynamicListItemClick tracking from attaching on legacy blog series pages. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const getBlogTitle = (collectionItem: HTMLElement): string => | ||
| collectionItem | ||
| .querySelector('.usa-collection__heading a') | ||
| ?.textContent?.trim() || '_ERROR_'; | ||
|
|
||
| const blogSeriesListClickHandler = | ||
| (collectionItems: HTMLElement[]) => | ||
| (evt: Event): void => { | ||
| const target = evt.currentTarget as HTMLElement; | ||
| const collectionItem = target.closest( | ||
| COLLECTION_ITEM_SELECTOR | ||
| ) as HTMLElement; | ||
|
|
||
| if (!collectionItem) { | ||
| return; | ||
| } | ||
|
|
||
| const collectionItemIndex = collectionItems.indexOf(collectionItem); | ||
|
|
||
| trackOther(BLOG_SERIES_LIST_EVENT_NAME, BLOG_SERIES_LIST_EVENT_NAME, { | ||
| location: 'Body', | ||
| componentType: 'Blog Series List', | ||
| title: getBlogTitle(collectionItem).slice(0, 50), | ||
| linkArea: 'Title', |
1469be3 to
06d2166
Compare
Closes #5278 update for 5278 commit updates analytics per copilot feedback
06d2166 to
1b9f733
Compare
ODE DeploymentCode has been deployed to ODE 1152. |
|
@dlescarbeau Blog Series List Clicks and Blog Pager Clicks both look good! |
- adds tracking to blog categories - adds tracking to blog archive box Closes #5279
1b9f733 to
e27c2cd
Compare
This is being addressed |
Closes #5278
Closes #5279
Closes #5280