Track GA4 custom event - google-analytics

I am sending a custom event ("ebook") with a parameter ("titolo") to GA4. After that, I have set the parameter as a Custom Dimension in GA UI.
I am sending the event from my website with this code:
function ebooksGA4new(title) {
gtag('event', 'ebooks', {
'titolo': title
});
}
Then I have set an Exploration on the custom dimension, but after 3 days it still reports "not_set. If I fire the event, I can see it in the real-time report.

Here are 2 ways to find out why
Modify the code a bit, make sure it won't trigger the event if it doesn't have title parameter.
But please make sure this is what you want. You need to decide it is ok or not to receive the event without title parameter.
function ebooksGA4new(title) {
if(!title || title=="")
return false;
gtag('event', 'ebooks', {
'titolo': title
});
}
Open the chrome devtool or something similar with it. Here is the screenshot about how to check it. This should appear on your GA4 real time report as well.

Related

Wix: Events Tracking in Google Analytics

I went through the tutorial to set this up (at https://support.wix.com/en/article/wix-code-tutorial-sending-tracking-and-analytics-events) but I can't see the events in Google Analytics. My configuration is the following:
I have a button on one of my pages with the id of downloadButtonNewbornBrochure which as its name says is linked to a file download. I placed the following code on the page:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixWindow from 'wix-window';
export function downloadButtonNewbornBrochure_click(event) {
wixWindow.trackEvent("CustomEvent", {
"event": "Download",
"eventCategory": "Newborn",
"eventAction": "Brochure Download"
} );
}
$w.onReady(function () {
//TODO: write your page related code here...
});
In Google Analytics I have a Goal specified and enabled:
Custom goal
Goal name: Download
Type: Event
Category Equal To Newborn
Action Equal To Brochure Download
Label empty
Value empty
Use the Event value as the Goal Value for the conversion: yes
When I verify or test this button, no events are captured. Where have I gone wrong?

Google AdWords click conversion is "unverified"

I've got an online store build on ASP.NET web forms. When a customer goes to the checkout page, there is a form, where they have to provide their details, like postage address etc. After they filled the form in they have to click "Pay now" button to be prompted to go to Paypal checkout page.
I need to track those clicks for the Google AdWords conversion statistics.
The usual code for tracking clicks would look like:
// some data
goog_report_conversion = function(url) {
goog_snippet_vars();
window.google_conversion_format = "3";
var opt = new Object();
opt.onload_callback = function() {
if (typeof(url) != 'undefined') {
window.location = url;
}
But because of the way the website was implemented, the destination link is being generated dynamically, so I couldn't pass it as as argument for "goog_report_conversion".
So I've slightly changed the conversion function to this:
// some data
goog_report_conversion = function(id) {
goog_snippet_vars();
window.google_conversion_format = "3";
var opt = new Object();
opt.onload_callback = function() {
if (typeof(id) != 'undefined') {
// I use custom function to trigger click on the actual button
event_fire(document.getElementById(id), 'click');
}
}
And I have this HTML structure:
<span class="GeneralFormButton" onClick="goog_report_conversion('submit_all')">Pay Now</span>
<input type="button" name="submit_all" value="Pay Now" onclick="this.disabled=true; this.value='Plase wait';__doPostBack('submit_all','')" id="submit_all" style="display: none;" />
Where <span> is being used to trigger the conversion function and then to emulate "click" on the actual submit button.
It works well and the customer is redirected to Paypal. However, the conversion isn't tracked and in Google AdWords account my "Pay with Paypal" option is marked as "Unverified" (It's been going for a way longer than 24 hors)
I tested what data is sent to google on submit:
https://www.googleadservices.com/pagead/conversion/*correct conversion id*/?random=1459744659796
&cv=8
&fst=1459744659796
&num=1
&fmt=3
&label=*correct conversion label*
&guid=ON
&u_h=800
&u_w=1280
&u_ah=777
&u_aw=1280
&u_cd=24
&u_his=11
&u_tz=570
&u_java=false
&u_nplug=5
&u_nmime=7
&frm=0
&url=http%3A//www.website.com/store_checkout2.aspx%3Fpay_service%3DPayPal%26promo_code%3D%26voucher%3D
&ref=http%3A//www.website.com/store_checkout2.aspx%3Fpay_service%3DPayPal%26promo_code%3D%26voucher%3D
&tiba=Contact%20and%20Delivery%20Address
&async=1
The conversion id and label are correct, the rest of the data seems to be okay too, but the conversion is still not tracked. I just can't figure out why.
Where did I go wrong and what do you think needs to be changed?
Thanks very much in advance
It turned out that the form was never completed and sent before, therefore Google couldn't verify the code. While I was testing for response data I sent the form and the code got verified.

Social shares tracking in GA

This is pretty much covered topic for original FB/Twitter buttons. But what if I have my own "share on fb" button? Like this:
<div id="fb_share"><a target="_blank" href="http://www.facebook.com/share.php?u=blah-blah">Share on FB</a></div>
so I've come up with the folloing solution:
var FBbtn = document.getElementById("fb_share");
FBbtn.addEventListener('click', function() {
ga('send', 'social', {
'socialNetwork': 'facebook',
'socialAction': 'share',
'socialTarget': window.location
});
//console.log('tracked');
});
That is placed AFTER the Google Analytics code.
Despite the fact it wont catch FB callback - it is supposed to do the trick but for some reason I still cannot see any results in Analytics so the question is this: will the solution actually work? In fact it could be even like this I believe:
FB
Your 'share on Facebook' links causes the page to navigate (and not open a new window/tab). When this navigation happens, most mainstream browsers cancel all pending HTTP requests for the current page and then navigates to the new page (fb.com)
In this scenario, one of the pending HTTP requests will be the GA event tracking call which will therefore never complete and never be received by the GA servers.
What you need to use is the GA hit callback functionality, this essentially cancels the native navigation (to FB), sends the tracking call and waits enough time for it to complete and then does a JavaScript redirection to the next page.
You should read the google docs here
In your case your event tracking function should be similar to this:
var FBbtn = document.getElementById("fb_share");
FBbtn.addEventListener('click', function() {
ga('send', 'social', {
'socialNetwork': 'facebook',
'socialAction': 'share',
'socialTarget': window.location,
'hitCallback': function(){
window.location = this.href;
}
});
//console.log('tracked');
return false;
});
So I've made the following changes:
Added the hitCallback property to the event tracking call. this is an anonymous function that is called once the GA servers have sent their response to the event tracking.
added a 'return false' statement which cancels the native functionality and then relies on the hitCallback function to do the navigating.

Trigger event using dataLayer does not work

I have problems with trigger my event. In my code:
<script>
dataLayer.push({
'event' : 'GAEvent',
'eventCategory' : 'overlayer',
'eventAction' : 'popup [overlayer]',
'eventLabel' : undefined,
'eventValue' : undefined
});
</script>
In the preview mode my custom event isn`t trigger because of _event rule
which I didnt create in GTM. My trigger from GTM:
Any ideas what I did wrong?
You are passing in "GAEvent" as a dataLayer event, but had the incorrect field in your GTM trigger looking for it. (Screenshot shows "GaEvent").
You also don't need the filter field, which is where you originally put in the uppercase verion.
Change that to the same as the event you are passing in, "GAEvent".
There is always confusion on which events we are talking of, GA, GTM or JavaScript :)

Change action in Contact Form 7

Would modify the action of Contact Form 7 once sent the mail.
I follow this post and woks fine. But my fom is in a Bootstrap Modal, and I wish they would keep open on submit.
My code is.
In function PHP
add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url'); function wpcf7_custom_form_action_url() { return 'http://saviacomunicacion.com.ar/test2014#sala-de-prensa'; }
And in the Aditional Settings field
add_filter('wpcf7_form_action_url', 'wpcf7_custom_form_action_url');
This redirect the URL, but it´s not sending the mail.
I wish i could send the mail and keep the modal open to show the response: Your mail was send correctly.
Thanks
According to the doc there is another way to accomplish the redirect. Just add some piece of code to the plugin dashboard.
Or you can do custom js function
in the plugin options
on_sent_ok: "customFunction();"
and somewhere in the code
<script>
function customFunction() {
// show your modal here
$('#myModal').modal();
}
</script>
I found my solution with this code. When form submit, the Modal closes after 1 second.
Instead of keeping Modal open, i wait 1 second after close, to show the response of the sending.
j(".form-horizontal").live("submit", function(){
j.post(this.action, j(this).serialize(), function(){
//this callback is executed upon success full form submission close modal here
}, "script");
//this is to wait 1 second until close
setTimeout(function() {j('.modal').modal('hide');}, 1000);
return false;
});

Resources