gtag not pulling URL in label - google-analytics

I'm trying to pull the URL dynamically as a label when an event is triggered. I've set the gtag like as below:
gtag('event', 'Lead generation', {
'event_category': 'ACT',
'event_label': **url**
});

You need to pull the URL :
gtag('event', 'Lead generation', {
'event_category': 'ACT',
'event_label': document.location.href
});
But in terms of GA, this is a bad approach. You can always add secondary dimension page, to know the URL where it was fired ;)

Related

How do I view the values in Track_URL defined by Google Javascript events

This is the following event I am capturing in Google Analytics.
How do I view the event_label in Report or Explore options. What is the dimension that I need to select?
When I was viewing custom report/explore I simply done see any event category
gtag('event', 'Track_URL', {
'event_category': 'URL Tracking',
'event_label': window.location.href
});
Cannot find event_category dimension

Google Analytics 4: custom dimensions in gtag.js

I am trying to send some custom dimension together with my event.
This is my code:
gtag('config', 'G-XXXXXXXXXX', {
'custom_map': { 'dimension1': 'age' }
});
gtag('event', 'age_dimension', {
'event_category': category,
'event_label': action,
'value': data(),
'nonInteraction': 1,
'age': '666'
});
This is my dimension on UI:
I am sending my events together with my custom dimension, on UI I see all my data as parameters in the event,
but when I try to make something with my dimension GA just says me that there is no data for this dimension.
I don't know, probably I configured the map incorrectly or probably something wrong with the dimension which I created.
So the question, is my configuration and dimension correct? and if no, what is wrong? thanks!

Contact Form 7 with Google Analytics - gtag event tracking (Goals)

I am trying to set up event tracking with Contact Form 7 in Google Analytics. Google Tag Assistant seems to see the event but it does bot seem to be tracking in Google Analytics. Please see below:
document.addEventListener('wpcf7mailsent', function(event) {
gtag('config', 'UA-********-*', {
'send_page_view': false
});
// https://developers.google.com/gtagjs/reference/api#event
gtag('event', 'form_submitted', {
'event_category': 'lead',
'event_action': 'Submit',
'event_action': 'Form',
'event_value': 1,
});
console.log('Form Submitted');
}, false);
Goal Set Up
Google Tag Assist
You have several errors in your event code (for example you have written the action twice) however the construct is wrong since the syntax for send an event in gtag is the following:
gtag('event', <action>, {
'event_category': <category>,
'event_label': <label>,
'value': <value>
});
https://developers.google.com/analytics/devguides/collection/gtagjs/events
So you have to change you code like this:
gtag('event', 'Submit', {
'event_category': 'form_submitted',
'event_label': 'Form',
'value': 1
});

Migration from ga to gtag.js scripts

Couldn't find direct migration tutorial or clear description on https://developers.google.com/gtagjs/reference.
Have limitation to analitic portal access and can't properly to test it.
Need to change next ga scripts under my SPA app to gtag.
1. ga('set', 'page', url)
2. ga('send', 'pageview')
3. ga('send', 'event', 'button-interest-request', 'submit-request')
I didn't find how should works set on gtag.
I supposed should be something like next strings for strings 1 and 2
gtag('event', 'page_view', { page_location: url })
And next for string 3
gtag('event', 'button-interest-request', {
'value': 'submit-request'
});
Am I right?
You have to define at least event category and event action in gtag with this syntax:
gtag('event', <action>, {
'event_category': <category>,
'value': <value>
});
In your situation, like this:
gtag('event', 'submit-request', {
'event_category': 'button-interest-request'
});

Getting events to be dependent on the completion of another event

A part of my site generates a handful of events from the same action. The default for Google Analytics is to have the events run independently. However, one of the events needs to happen last. Is there a way to force an order of event completion or at the least have an event dependent on another event?
I have found no documentation on the subject. Thanks in advance for the help.
Could you do a simple flag?
Event #1
var flag = false;
function eventOne(){
ga('send', 'event', 'Event Chain', 'Trigger', 'First Event');
flag = true;
}
function eventTwo(){
if (flag) {
ga('send', 'event', 'Event Chain', 'Trigger', 'Last Event');
}
}
Google Universal Analytics has hit callbacks , functions that are called when a tracking call is completed. You can at least try to nest event tracking calls within event hits
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action', // Required.
'eventLabel': 'label',
'hitCallback': function() {
ga('send', {
'hitType': 'event', // Required.
'eventCategory': 'category', // Required.
'eventAction': 'action 2', // Required.
'eventLabel': 'label 2'
});
}
});
Untested, but judging from the documentation I don't see why this wouldn' work.
There is no built-in way of doing that in Analytics. To implement this sort of behavior, you would have to design it yourself based on your requirements and/or application logic.
If you are implementing a website using JavaScript, you might be interested in using the q library, which could help you in creating and composing asynchronous promises in JavaScript.
Without going into too many details (because it might be out of the scope of your question), that could yield something like:
Q.all([handleEventOne(), handlerEventTwo()]) // Wait for 2 handlers to complete
.done(function (values) { // Execute this callback once the 2 handlers have completed
ga('send', 'event', 'Event Chain', 'Trigger', 'Last Event');
});

Resources