{
- "name": "cubist\/gtag",
+ "name": "cubist/gtag",
"description": "Google analytics tracking code for Laravel",
"type": "library",
"license": "proprietary",
],
"require": {
"php": ">=5.5.0",
- "laravel/framework": "5.8.*"
+ "laravel/framework": "^5.8"
},
"repositories": [
{
--- /dev/null
+require('element-closest');
+
+document.addEventListener('DOMContentLoaded', function () {
+ Array.prototype.forEach.call(document.querySelectorAll('meta[data-ga]'), function (el, i) {
+ handleGtag(el)
+ });
+});
+
+document.addEventListener('click', function (e) {
+
+ if (e.target.matches('[data-ga]')) {
+ handleGtag(e.target);
+ }
+ if (e.target.closest('[data-ga]')) {
+ handleGtag(e.target.closest('[data-ga]'));
+ }
+}, false);
+
+function handleGtag(el) {
+ if (el.getAttribute('data-ga') === 'event') {
+ console.log(el);
+ let action = el.getAttribute('data-ga-action');
+ let category = el.getAttribute('data-ga-category');
+ let label = el.getAttribute('data-ga-label');
+ let value = el.getAttribute('data-ga-value');
+ let options = {non_interaction: el.getAttribute('data-ga-noninteraction') === 1};
+ if (null !== category) {
+ options.event_category = category;
+ }
+ if (null !== label) {
+ options.event_label = label;
+ }
+ if (null !== value) {
+ options.value = value;
+ }
+ gtag('event', action, options)
+ }
+}