This is more of a "how to" document that might help others meet the following need:
Situation
Site has webforms being displayed as ctools based modal dialog (popups) using the modal_forms module. These needed to be tracked by Google Analytics.
Solution
Add the attached googleanalytics_modal_forms.js file to your site via your theme (or custom module if so inclined). For the theme based solution:
- Put the file in your theme directory (under the js subdirectory if it exists)
- In your theme's info file (e.g. theme.info) add the line: scripts[] = js/googleanalytics_modal_forms.js
- Clear the site's cache
Notes:
May also work with other forms that modal_forms module supports but has not been tested with them.
Could also be used as a basis for tracking any ctools generated modal dialog with the right jQuery selectors and ajax url matching.
What should happen
Will add "pages" with the following format to the google analytics data:
Page URL format | Meaning |
---|---|
/modal_forms/ajax/webform/[form_number] | Form modal dialog opened |
/modal_forms/ajax/webform/[form_number]/error | Failed form validation |
/modal_forms/ajax/webform/[form_number]/success | The Success page was displayed. |
Where: [form_number] is the webform node id.
Tested with:
googleanalytics-7.x-1.x branch
modal_forms-7.x-1.2
ctools-7.x-1.3
Comment | File | Size | Author |
---|---|---|---|
#3 | googleanalytics_modal_forms_js_ms.zip | 1.08 KB | msizec |
Comments
Comment #1
hass CreditAttribution: hass commentedI'm moving the feature request to modal forms.
It would be extremly useful if we get a event trigger like colobox provides to us. Than we can add an ON trigger for modal_forms and we are done. Maybe a lot better to add this to ctools?
This is the implementation example in GA for Colorbox. We could add the same for other modules if they provide a trigger.
Comment #2
msizec CreditAttribution: msizec commentedThanks for your javascript, it helped me a lot.
Im using it with
Im sharing some modifications here ...
Comment #3
msizec CreditAttribution: msizec commentedAdded one correction to the script, my bad