digital-analytics-program / gov-wide-code

Provides a set of javascript files and documentation to implement web analytics on US federal websites
http://www.digital.gov/dap
104 stars 55 forks source link

gas4 method handling of events that aren't in the predefined list #127

Open mhm-va opened 2 months ago

mhm-va commented 2 months ago

Migrated to the new gas4 method. One difference I see is that if the event name isn't in the predefined list: pageview or one that match the regex: /((email|telephone|image|cta|navigation|faq|accordion))?click|file_download|view_searchresults|video(start|pause|progress|complete|play)|official_USA_site_bannerclick|form(start|submit|progress)|content_view|social_share|error|sort|filter|was_this_helpful_submit/

The code sets the event name to 'dap_event'; but it does not set set the event_category to the value of the first parameter. We can do this ourselves but it's a bit tricky because we have to track what the predefined set of event_names are. I'd prefer not filtering to the predefined list (not clear to me the value of the dap_event event name) even though this would mean I have to go rework some of my GA4 analyses/dashboards; alternatively, it would be great if event_category got auto-set for any non-standard names.

function gas4(a, b) { if (void 0 !== a && "" !== a && void 0 !== b && 'object' === typeof b) { a = _cleanGA4Value("e", a); if ("page_view" === a.toLowerCase()) try { if (Object.keys(b).length !== 0) { var ur = ((b.page_location) ? b.page_location : location.href); b.page_location = _URIHandler(_scrubbedURL(ur)).split(/[#]/)[0]; b.page_title = ((b.page_title) ? b.page_title : document.title); _sendEvent("page_view", b), ((isSearch) ? (_sendViewSearchResult({ search_term: isSearch })) : ''); } } catch (n) { } else try { var en = ((/((email|telephone|image|cta|navigation|faq|accordion))?click|file_download|view_searchresults|video(start|pause|progress|complete|play)|official_USA_site_bannerclick|form(start|submit|progress)|content_view|social_share|error|sort|filter|was_this_helpful_submit/gi.test(a)) ? a : 'dap_event'); if (Object.keys(b).length !== 0) { _sendEvent(e_n, b); } else { _sendEvent(e_n); } } catch (n) { } } }