Google Analytics Button Tracking - google-analytics

In Google Analytics I have set up a Goal for a button to be pressed on a sign up contact form. It is to collect email addresses for a mailing list. The problem is that it does not work. I have followed three guides on this offering slightly different code for alternate approaches but have not got it to work.
In GA the Goal is setup as follow...
Goal setup: Custom
Name: Contact
Type: Event
Category Equals to Contact
Action Equals to signup
GA is tracking the page and analytics from users can be viewed so we can see it is working. We are using CloudFlare and GA is added on the fly to all pages served through their cloud.
The code for the button is below.
<button type="submit" onclick=”_gaq.push([‘_trackEvent’, ‘Contact’, ’signup’])” class="btn btn-success">Sign up</button>
Any help on this would be appreciated.

If that is the exact code you are using for the button, then at least you would need to change the smart quotes (ie. the angled quotes) to straight quotes, so it should look like this:
<button type="submit" onclick="_gaq.push(['_trackEvent', 'Contact', 'signup'])" class="btn btn-success">Sign up</button>
I believe there are issues when the smart quotes are used.

Related

How to close sign post content using directive *clrIfOpen

I am using clarity signpost, I am using this signpost for showing multiple applications, how to close this sign post when i am click on the application.
For example I am adding three buttons in this sign post, if I click on the button this need to be close. Please check my stackblitz
To keep track of whether the signpost is open or not, and then be able to dynamically close it, you should use the de-sugarized syntax of clrIfOpen to utilize two-way binding:
<ng-template [(clrIfOpen)]="signPost">
<clr-signpost-content>
<button class="btn btn-outline" (click)="close()">Hr</button>
...
</clr-signpost-content>
</ng-template>
Here is your example with this change, working fine: https://stackblitz.com/edit/signpost-dynamic-close?file=src/app/app.component.html

Is it possible to extract data from Google Tag Manager without using datalayer?

I have this piece of code on my site:
<div class="product-cta">
<span class="price">2.998,-</span>
<div class="btn-wrapper">
<a class="btn btn-primary btn-addtocart btn-xlarge" href="#" data-basket-url="/kassen/kurv/" data-product-id="25984"><i class="icon icon-cart"></i>Add to cart</a>
</div>
Is it possible to extract the numbers that come after data-product-id= to Google Tag Manager without pushing it through datalayer, only using what is in the existing code? This is on a product page and is to be used with the Facebook Pixel.
Yes, you can try couple methods without pushing it to the dataLayer. You could use JS (natively or jQuery) to scrape that info, or you could also use a built-in auto-event variable like this:
If you want to use the AEV, then you would likely be capturing that data on a click or something as the AEVs are "essentially [macros] that can be used to refer to, for example, the DOM element where a click occurred" (cf. https://www.simoahava.com/analytics/auto-event-tracking-google-tag-manager/).

Google Analytics Events Tracking not working

I've being tried to install google events tracking on several sites but with no luck. I really want to know why its not working.
I installed events tracking on this site http://bedsndrinks.com/, the second "Book Now" button, here is the code I added to the button onClick=”ga(‘send’, ‘event’, ‘book form’, ‘click’, ‘book now’);“
I tried to use Google Analytics Debugger, but I don't see any "event" hitType. one thing I noticed is that the tracking code looks okay in source code but different when I inspect it in Chrome.
You need to check how your onclick is being rendered. When I loaded the page I saw the following:
<input id="sendBook" type="submit" value="Book Now"
onclick="”ga(‘send’," ‘event’,="" ‘book="" form’,="" ‘click’,="" now’);“="">
As you stated in your question, the format should be as below:
onclick="ga('send', 'event', 'book form', 'click', 'book now');

Google analytics Event tracking with an onclick=$('link')

I'm trying to add event tracking to my two buttons, but my button code looks like the following. I'm popping the user down to the section they clicked and hiding the other button's section:
<button class="btn btn-primary btn-lg" onclick="$('#order-form').show();$('#digital-download').hide();location.href='#Print'">
Order Print
Version
</button>
Anyone know how would I add the GA tracking code?
// Form Tracking for Google Analytics
$('.form-track').click(function(e){_gaq.push(['_trackEvent', 'Form', 'Completions', 'Form_'+$(this).attr('title')+'_'+location.href]); });
You can try something similar to this, adding the following code to your buttons:
$('.btn.btn-primary.btn-lg').click(function(e){
ga('send','event','your_category', 'your_action',$(this).text().trim());
})
When the button is clicked, it will send the event with your specified category, action, and the button text as the label. Note that you are using UA, so the event tracking syntax in your example is incorrect.

GA Event Tracking + onClick="document.location.href='

The developer who made a site we're working on has buttons linking to PDF downloads using:
<button onClick="document.location.href='doc.pdf'"> Doc Name </button>
However, we also need to track events for these (we don't want to inflate pageviews with PDF downloads), using:
<button onClick="_gaq.push(['_trackEvent', 'PDFs', 'Download', 'Doc Name']);""> Doc Name </button>
So, the issue is, how can I do GA event tracking without having the two requisite 'onClick's conflicting?
I was thinking about triggering the GA Event with 'onMouseDown,' but this would be less accurate, no?
Many thanks in advance.
<button class="download-pdf" onclick="document.location.href='doc.pdf';_gaq.push(['_trackEvent', 'PDFs', 'Download', 'Doc Name']);"> Doc Name </button>

Resources