Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

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

form

Started by Anders 5 years ago · 3 replies · 712 views
5 years ago

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
googleAnalyticsEvent:
tagname: 'emailsent'

5 years ago

@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.

5 years ago

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.

last edited 07/11/21 by Anders
5 years ago

@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.

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1136 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 61 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 135 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 129 7 months ago