Skip to content

[WNMGDS-3344] Add Utag data object #3559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 15, 2025

Conversation

jack-ryan-nava-pbc
Copy link
Collaborator

Summary

  • Add new Tealium snippet to body tag via SSR script - this will fire page view events on every page now
  • Update Tealium scripts in the Head

How to test

  1. The best way to test is using the debugger built into your Browser of choice, for Firefox:
  2. Open the doc site locally
  3. Open dev tools and go to the Debugger tab
  4. Press "Command + P" and search for "utag.js"
  5. When that file is opened, search "Command + F" for track:
  6. Place a break point at the line following the definition of the track function
  7. Click on a component, and then click on the Storybook link at the top of the page
  8. In the Browser console, type "a"
  9. Look at the associated object, and expand it to see the data property on that object
  10. Note that for any link you click you will trigger a link event, to see this fire on page load you need to step past that break using the debugger
  11. Confirm that the object contains a field that says "view", along with a "page_name" equal to the name of the page plus the theme name.

Checklist

  • Prefixed the PR title with the Jira ticket number as [WNMGDS-####] Title or [NO-TICKET] if this is unticketed work.
  • Selected appropriate Type (only one) label for this PR, if it is a breaking change, label should only be Type: Breaking
  • Selected appropriate Impacts, multiple can be selected.
  • Selected appropriate release milestone

@jack-ryan-nava-pbc jack-ryan-nava-pbc added the Impacts: Documentation Indicates that this item relates to documentation label May 1, 2025
@jack-ryan-nava-pbc jack-ryan-nava-pbc added the Type: Added Indicates a new feature. label May 1, 2025
@jack-ryan-nava-pbc jack-ryan-nava-pbc self-assigned this May 1, 2025
@jack-ryan-nava-pbc jack-ryan-nava-pbc added this to the 12.3.0 milestone May 1, 2025
@jack-ryan-nava-pbc
Copy link
Collaborator Author

@kim-cmsds @tamara-corbalt This change will necessitate some changes to the Gatsby-Head component in the React 18 branch, but lets hold off doing those changes until Blast confirms these changes.

a=b.getElementsByTagName(c)[0];a.parentNode.insertBefore(d,a);
})();`;

const dangerousTealiumSnippet = makeDangerousHTML(tealiumSnippet);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, but I’m wondering if we need the dedicated makeDangerousHTML function here. Since it’s only used once, would it be worth inlining it?
dangerousTealiumSnippet = { __html: tealiumSnippet }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's a good call. this is more an homage to all the work I did in a previous effort, only to delete. but I shouldn't be so sentimental. thank you!

Copy link
Collaborator

@tamara-corbalt tamara-corbalt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jack-ryan-nava-pbc It looks good, but I'm having trouble verifying the testing steps. When I step through with the debugger, I'm seeing the link event object, but not seeing the fields view or page_name.

@jack-ryan-nava-pbc
Copy link
Collaborator Author

@tamara-corbalt did you get the video of the testing steps I shared via Google Docs?

@tamara-corbalt
Copy link
Collaborator

@tamara-corbalt did you get the video of the testing steps I shared via Google Docs?

Yes, and I was able to walk through the testing steps. Thanks for sharing the screencast!

Everything looks like it's working as expected, so hitting approve!

Copy link
Collaborator

@kim-cmsds kim-cmsds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was able to verify the testing steps! And appreciate the context provided in the PR description and JIRA Ticket.

<script type="text/javascript" dangerouslySetInnerHTML={content}></script>
);

exports.onRenderBody = ({ setPreBodyComponents }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL (/ re-remembered) about this gatsby feature

@@ -66,12 +69,45 @@ const Layout = ({
theme,
tableOfContentsData,
}: LayoutProps) => {
const env = 'prod';
// Using a ref here because this value shouldn't change after the initial render.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the comment here

page_name: tabTitle,
page_type: tabTitle.includes('Page not found') ? 'true' : 'false', //If page is a 404 (error page) this is set to true, otherwise it is false
site_environment: env.current, //Used to include or exclude traffic from different testing environments. Ex: test, test0, imp, production
site_section: location.pathname == '/' ? 'index' : location.pathname, // Set the section to the pathname, except in the case of the index.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: I don't think this matters but why use two equals signs and not three for the "index" check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is me trying out a sorta new thing for me: I've adopted the opinion that if you use == it means you know what the types are in the comparison you are making. The only difference between === and == is that === checks to see if the two items being compared are the same type at first.
So using == here states that we know that location.pathname will only ever return a string so we don't need the type comparison to another string value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is using == to signal confidence in types a widely adopted convention? I haven’t come across that before, so I’m wondering if there’s a more explicit or widely recognized way to communicate type confidence to folks reading the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't, but I think that's ok. Also, I boogered up my explanation a little bit. Here's a good reference and a good quote from that reference: "The implication here then is that both == and === check the types of their operands. The difference is in how they respond if the types don't match."

So basically what I'm saying with this code is coercion is ok here because I know the types are the same, so no coercion occurs. Maybe this isn't the most thought-out application of the principle I intended to apply, but it should function fine. And clearly I should think more (and review) about this pattern going forward. Thanks for pushing me to think more @tamara-corbalt!

@jack-ryan-nava-pbc jack-ryan-nava-pbc merged commit 50f321b into main May 15, 2025
1 check passed
@jack-ryan-nava-pbc jack-ryan-nava-pbc deleted the jryan/wnmgds-3344-add-utag-data-object branch May 15, 2025 00:27
jack-ryan-nava-pbc added a commit that referenced this pull request May 15, 2025
* Add ssr helper

* Make HTML dangerous

* Seems like it works

* Use ref for variable storage and remove unneeded function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impacts: Documentation Indicates that this item relates to documentation Type: Added Indicates a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants