Skip to content
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

Add GA4 form tracker and section value to survey banner #3158

Merged
merged 4 commits into from
Sep 27, 2023

Conversation

AshGDS
Copy link
Contributor

@AshGDS AshGDS commented Sep 26, 2023

What

  • Adds the section value to the GA4 object for the survey banner events, with the value of section being the survey's heading text.
  • Adds the GA4 form tracker to the email survey banner to track submitting the form.
  • Adds a form_complete event using Ga4AutoTracker when the survey is sent to the user. This adds a <span> to the DOM with GA4 auto on it, rather than adding GA4 code to surveys.js. I thought this would be better as it prevents us adding a bunch of GA4 code in static which checks if GA4 modules exists, if cookie consent exists, and then more code to push the event. Instead we add a <span> with the auto tracker on it, then run window.GOVUK.Modules.start().

Why

How to test

  • Run a local version of static with this branch checked out
  • In surveys.js go to the function isSurveyToBeDisplayed and set it to just return true, e.g.:
 isSurveyToBeDisplayed: function (survey) { return true }
  • In gem_base.html.erb, add the HTML element somewhere:
<div id="user-satisfaction-survey-container"></div>

@AshGDS AshGDS changed the title Ga4 survey banner additions Add GA4 form tracker and section value to survey banner Sep 27, 2023
@AshGDS AshGDS force-pushed the ga4-survey-banner-additions branch from fe4c129 to 8744cf2 Compare September 27, 2023 09:23
@AshGDS AshGDS self-assigned this Sep 27, 2023
@AshGDS AshGDS force-pushed the ga4-survey-banner-additions branch from 8744cf2 to 5fec8f9 Compare September 27, 2023 09:31
@AshGDS AshGDS force-pushed the ga4-survey-banner-additions branch from 5fec8f9 to 5c4566a Compare September 27, 2023 09:32
@AshGDS AshGDS marked this pull request as ready for review September 27, 2023 10:05
@AshGDS AshGDS requested a review from andysellick September 27, 2023 10:11
tool_name: emailSurveyHeading
}))
emailSurveyElement.appendChild(span)
window.GOVUK.modules.start(emailSurveyElement)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good but I'm wondering if we should think about our modules in this context a bit more. This isn't a criticism of the work you've done here, more something maybe for us to think about in general.

It feels slightly clumsy to create an element, attach attributes to it, then call start modules on it, when perhaps we could be calling the module directly and just pass it what it needs? Maybe a bit more like we do when we run tests...

var attributes = { 'ga4': 'attributes' }
var module = new GOVUK.Modules.Ga4AutoTracker({ attributes: attributes })
module.init()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @andysellick - that's a good idea, I think we should implement that 👍

@AshGDS AshGDS merged commit 4434860 into main Sep 27, 2023
6 checks passed
@AshGDS AshGDS deleted the ga4-survey-banner-additions branch September 27, 2023 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants