Event tracking in Google analytics is not displaying events data - google-analytics

I am adding Google Analytics code in my website, it displays active users but not but displaying the event list empty.
I tried both below codes
1)
jQuery('.btn-cart').click(function() {
ga('send', 'event', 'add-to-cart', 'add','product-added-to-cart');
});
2)
onclick("_gaq.push(['_trackEvent', 'whitepaper', 'add', 'product-added-to-cart']);")
Please let me know where i am doing wrong.

I found the solution.
jQuery('.btn-cart').on('click',function() {
_gaq.push(['_trackEvent', 'Add to Cart', 'Add To Cart Clickthrough', '<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl();?>']);
});

Related

how to capture dynamic conversion values on Google ads?

I am trying to get dynamic the order total price on my thankyou page(the page seeing the user after a successful order) to the google ads report through the goole-tag-manager chrome extension.
The google ads snippet I am using on my thankyou page is this:
*I have follow the google support before (https://support.google.com/google-ads/answer/6095947?hl=en)
<!-- Event snippet for Purchase conversion page -->
<script>
gtag('event', 'conversion', {
'send_to': 'My Conversion ID/My Conversion Label',
'value': 11.50,
'currency': 'EUR',
'transaction_id': ''
});
</script>
and the order total amount is the " 'value': 11.50, "
So instead of 11.50 I am placing the below code
document.querySelector("#cost>.woocommerce-Price-amount.amount").innerText.match(/^.{1}(.*).{0}/i)[1].trim();
so I can take the total for each order every time dynamicaly by scaning the dom, but doesn't work. Are my thoughts right? Is this the right way to do it by addin code manually on my site without use gootle tag manager? Any Ideas about how to do it?
Well its actually quite simple when you do it with php.
// Hook the function in head.
add_action('wp_head', 'bks_head_social_tracking_code');
function bks_head_social_tracking_code() {
// Check if its thank you page.
if(is_wc_endpoint_url( 'order-received' )) {
// Get order object.
$order = wc_get_order(get_query_var('order-received'));
// Get total.
$order_total = $order->get_total();
// Prepare.
$output = "
<script>
gtag('event', 'conversion', {
'send_to': 'My Conversion ID/My Conversion Label',
'value': ". $order_total .", // Use dynamically.
'currency': 'EUR',
'transaction_id': ''
});
</script>";
// echo.
echo $output;
}
}
You can make the currency dynamic too. You can use this to to get different kinds of data. https://www.businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/

How to track R shiny dashboard events from Google Analytics

Hi I am trying to add a event to track in Google Analytics,
Here is one working example:
$(document).on('change', 'select', function(e) {
ga('send', 'event', 'widget', 'select data', $(e.currentTarget).val());
});
And I am trying to track if a download button is clicked in my shiny app, and I tried:
$(link) .on('shiny:filedownload', function(e) {
ga('send', 'event', 'download', e.name, e.href)
});
It didn't work, I cannot find examples online, so just wondering if anyone came cross this problem before.

Event Tracking not Appearing In Analytics

I am trying to use Google Event Tracking to record when a certain user action is taken. I have a JS method called runGABanner that fires the Google Analytics code when conditions are met, but I'm not seeing anything update in GA Admin page.
In my code, I set up the GA code as such:
const runGABanner = () =>{
ga('send', {
hitType: 'event',
eventCategory: 'AdBlocker',
eventAction: 'Ad Blocker Displayed',
eventLabel: 'Ad Blocker'
});
}
I was expecting to see "Banner Displayed" under "Event Action", but as the screenshot shows, nothing is appearing there.
Any thoughts as to why this is happening?

Google Analytics goal tracking with multiple CF7 Forms

I have a WordPress website and use Google Analytics to track submission of a CF7 form via goals. I have recently added a second form and would like to track this as a separate goal. I've tried altering the event create using this following script:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
if (event.detail.contactFormId == '770' {
ga('send', 'event', 'Consultation Request', 'submit');
}
else {
ga('send', 'event', 'Contact Form', 'submit');
}
}, false );
</script>
This still don't seem to separate the forms when I track the events created. Is there something else I can do?
Instead of adding this custom script, I ended up using a plugin called Contact Form 7 Submission DOM tracking This plug added the code needed to create separate goals. Also has a few extra features such as the ability to hind the form after submission.

Event Tracking for Newsletter Sign Up

I want to track how many people sign up for Newsletters. I can do it with event tracking in Google Analytics. But there is an issue. I found the below code on the button
<form name="ccoptin" action="http://visitor.r20.constantcontact.com/d.jsp" target="_blank" method="post" onsubmit="return SubscribeValidate()">
Then where I have to place the following code
onClick="_gaq.push(['_trackEvent', 'newsletter signup', 'email', 'Sidebar',, false]);"
onClick is tracking for buttons. For forms, add the code into a successful "validate" function and/or on the "thank you" page.
var SubscribeValidate = function () {
// Make sure the form is filled out
if ($("#email").text() != "") {
return false;
}
// Track in Google Analytics
_gaq.push(['_trackEvent', 'newsletter signup', 'email', 'Sidebar', , false]);
window.location = "/thanks"; // or $("#modal").modal();
}

Resources