Simplest way to have email form submission generate Google Analytics goal event?

I’m using the plugin "Google Analytics (gtag.js) v1.1.0, no trouble there, it’s tracking properly. Seems like the most natural thing to want the form submission to trigger an Analytics goal/event. What’s the most straightforward way here? Can I call the plugin directly via an additional line after “process:” in my contact page?

I see that I could use the “redirect:” parameter to send them to a different page, and call that a goal in GA, that’s one option.

It would be excellent if there were already a Custom Action in the Google Analytics plugin. It seems like onOutputGenerated() might be this, but I’m unsure how to glue it together or if that’s the intent.

Ideas? The sweetest would be something like
tagname: ‘emailsent’

@anders8, Did you have a look at Google Tag Manager?

Manage all your website tags without editing code. Google Tag Manager delivers simple, reliable, easily integrated tag management solutions— for free.

I had not. Looking at it now, I see that I need to inject two pieces of tracking script, one in head, the other in body.

I looked at “Headers by Tag” and “Custom HTTP Headers”, both seem to target the meta tags. The “Page Inject” seems to be focused on content, not script, injection.

Any recommendations on how to best go about the injections? It seems that I can directly edit the /user/themes/typhoon/templates/partials/base.html.twig and insert the js there.

@anders8, Since Typhoon is closed source, I have no idea how its templates look like, but… I presume it follows the usual template structures.

I’m not familiar with the Analytics plugins, so I would have a look at Extend base template of inherited theme and inject both GTM scripts into the ‘base.html.twig’ template. You will have to create an inherited theme of Typhoon for this, but only need to create you own ‘base.html.twig’ which extends the base.html.twig from Typhoon.