Marketing Integrations

julian_kramer
Member

Google Analytics - Event Tracking

SOLVE

Hi,

does anyone know how to implement GA even tracking on different buttons on a HubSpot page, so that every click on each button will be counted as separate goal conversion completions?

Help on this would be much appreciated.

Julian

 

 

3 Accepted solutions
ndwilliams3
Solution
Key Advisor

Google Analytics - Event Tracking

SOLVE

It's implemented via javascript. the simplest way is to add an onclick attribute to the links. Set the category, action, label and value to what you want to record in GA.

<a href="http://www.example.com" onClick="ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, value);">Link Text</a>

You can also get more anvanced and use jQuery to add tracking dynamically.

View solution in original post

0 Upvotes
ndwilliams3
Solution
Key Advisor

Google Analytics - Event Tracking

SOLVE

Use jQuery

 

$(document).ready(function() {
    $('#id_of_cta').click(function() {
        ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, value);
    });
});

View solution in original post

0 Upvotes
ndwilliams3
Solution
Key Advisor

Google Analytics - Event Tracking

SOLVE

Add this script to your page to track the single CTA.

$(document).ready(function() {
    $('#hs-cta-wrapper-867c8ff0-74cf-4925-9458-7b66f551c52c a').click(function() {
        ga('send', 'event', 'CTA', 'click', '867c8ff0-74cf-4925-9458-7b66f551c52c');
    });
});

Or add this to track all CTA click events with ID as the indentifier.

$(document).ready(function() {
    $('.hs-cta-wrapper').click(function() {
        ga('send', 'event', 'CTA', 'click', this.attr('id'));
    });
});

 

GA will record the CTA ID as the indentifier. You can use that to match back to the CTA in Hubspot.

View solution in original post

26 Replies 26
zScreen1
Member

Google Analytics - Event Tracking

SOLVE

Use the data layer. It's read by Google Tag Manager so you can then send our conversion event anywhere you want, not just universal analytics.  Here is a listener that handles the CTA button clicks automatically, along with their ID etc: https://www.listenlayer.com/listeners/hubspot-cta/ they also have listeners for hubspot chat and forms.  They are amazing, our agency uses them and we save so much time on tracking and get the data where we need fast.

alyssaomara
Contributor | Partner
Contributor | Partner

Google Analytics - Event Tracking

SOLVE

@donrua this is all correct. If you use Google Tag Manager you can have both GA3 and GA4 running at the same time. It would allow you to see if GA4 is automatically tracking what you want it to track without rebuilding anything. I dread the day that I have to switch everything over to GA4! I was told on a webinar today that GA4 is not robust yet and we shouldn't completely switch.

alyssaomara
Contributor | Partner
Contributor | Partner

Google Analytics - Event Tracking

SOLVE

You might look into Google Analytics 4. If you add a GA4 property to analytics, it might track those buttons automatically. I am using might here as I have not fully researched this myself, but I think it's supposed to work that way. You would still have to convert the Events into Goals, but the tracking would be done, so that part is easy.

0 Upvotes
donrua
Top Contributor

Google Analytics - Event Tracking

SOLVE

I spoke to a Google support person that told me if I switch to GA4, that I will need to swap out the code on site, since HS field only allows the old style ID, and that it will end our previous GA tracking, and the GA4 tracking will start with no history. In otherwords, all history will be lost between the two, and they told me that  I didn't really need GA4 for the level of site/focus we have.

I also read this input on whether sites should switch to GA4:
"For the majority of people, the short answer is no. At least, not completely. But, if you are a massive global brand with both a website and an app, you should probably get this on your roadmap sooner rather than later."

I'm worrisome for me as I'm not comfortable with the ins/outs of GA, don't have a web admin/dev resource, and Google also said we would have to recrete every view, filter, segments, customizations, that we have across our current GA properties/views.

If I have bad info, open to input.

0 Upvotes
ralphioooo
Contributor | Diamond Partner
Contributor | Diamond Partner

Google Analytics - Event Tracking

SOLVE


We have just created a HubSpot APP called Analytics Amplifier that helps you do this + push offline events to Google Analytics when they happen.

 

Check it out here:
https://ecosystem.hubspot.com/marketplace/apps/marketing/analytics-data/google-analytics-amplifier-2...

0 Upvotes
ndwilliams3
Solution
Key Advisor

Google Analytics - Event Tracking

SOLVE

It's implemented via javascript. the simplest way is to add an onclick attribute to the links. Set the category, action, label and value to what you want to record in GA.

<a href="http://www.example.com" onClick="ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, value);">Link Text</a>

You can also get more anvanced and use jQuery to add tracking dynamically.

0 Upvotes
EHemmings
Participant

Google Analytics - Event Tracking

SOLVE

Hi @ndwilliams3! Surfacing a very old thread here, but I'm hitting similar walls a previous HS user. Any insight you could provide would be GREATLY  appreciated!

 

My Google Ads Manager gave us event tags to implement within buttons. You say here to add onclick attribute to the links. Done this way, 

1. How do I ensure this tracking is brought into GA the way my ad manager wants?

2. Do I not need the GA-generated tags she sent through?

0 Upvotes
donrua
Top Contributor

Google Analytics - Event Tracking

SOLVE

This said "it is implemented via javascript" in the answer, but I see no javascript in your answer. How is it implemented with javascript, where do I get that, where do I place it. Non-developer here.

 

If I put the onclick tag in the a href, does Google find it without me adding more?

I saw some some solutions about adding scripts to CTA, but when I look at src code in HS blog editor, i see no opportunity for javascript, just a call to a cta call between p tags.
{{cta('867c8ff0-74cf-4925-9458-7b66f551c52c','justifycenter')}}

Do I get into the source via some other method, app, corner of Hubspot?

I feel there's another level of instructions, step by step, not assuming anything, leaving no doubts. Screen shots, arrows. Has anyone seen that? Looking for step by step tracking Hubscpot CTA in GA (not using GTM because site wasn't set up using GTM for the GA code). 

0 Upvotes
jennysowyrda
Community Manager
Community Manager

Google Analytics - Event Tracking

SOLVE

Hi @donrua,

 

I want to tag in some thought leaders to see if they can provide any further clarity. @ndwilliams3 and @lincé do you have any further suggestions for @donrua?

 

cc @IsaacTakushi do you have any more detailed resources for @donrua regarding this matter? 

 

Thanks,
Jenny

ndwilliams3
Solution
Key Advisor

Google Analytics - Event Tracking

SOLVE

Add this script to your page to track the single CTA.

$(document).ready(function() {
    $('#hs-cta-wrapper-867c8ff0-74cf-4925-9458-7b66f551c52c a').click(function() {
        ga('send', 'event', 'CTA', 'click', '867c8ff0-74cf-4925-9458-7b66f551c52c');
    });
});

Or add this to track all CTA click events with ID as the indentifier.

$(document).ready(function() {
    $('.hs-cta-wrapper').click(function() {
        ga('send', 'event', 'CTA', 'click', this.attr('id'));
    });
});

 

GA will record the CTA ID as the indentifier. You can use that to match back to the CTA in Hubspot.

donrua
Top Contributor

Google Analytics - Event Tracking

SOLVE

Thank you all very much.

0 Upvotes
eddy17
Participant | Platinum Partner
Participant | Platinum Partner

Google Analytics - Event Tracking

SOLVE

Sorry, is it possible tracking also an image or a text (with background) link?

In one way or another.

0 Upvotes
alyssaomara
Contributor | Partner
Contributor | Partner

Google Analytics - Event Tracking

SOLVE

I have used the Click-Text variable which is just the text that you use in the button. The problem is if you ahve a couple of difference CTAs that you want to track dfferently (like a Contact Us button on your product pages and another on your Support pages), then you may not know which button it is in Analytics. (You would in HS of course) We got around it by being more specific in our Click /Button txt: Contact Sales or Contact Support.

 

Hope this helps!

0 Upvotes
julian_kramer
Member

Google Analytics - Event Tracking

SOLVE

Hi,

 

many thanks for that reply.

 

The trouble is that I can't seem to be able to get the source code of the button as this is a pre-defined HubSpot module which does not appear to be editable (this is a page which has been built in HubSpot).

 

How do I get to the button's HTML source code?

 

Many thanks

 

Julian

0 Upvotes
ndwilliams3
Key Advisor

Google Analytics - Event Tracking

SOLVE

If you are using Firefox or Chrome, you can right click and chose the "Inspect Element" option to view the source code.

0 Upvotes
MagdaSzuster
Member

Google Analytics - Event Tracking

SOLVE

Hello,

 

we have CTA on the page created in Hubspot Landing Pages module.

 

Where exactly should I insert jQuery code or, alternatively, how can I add an OnClick attribute to link?

0 Upvotes
alyssaomara
Contributor | Partner
Contributor | Partner

Google Analytics - Event Tracking

SOLVE

Thanks for this answer. Would I put unique values for all of the items between the ' ? I have two buttons with the same button text and am trying to set up a second event in GTM to track each button's clicks separately. Becasuer the click text for both buttons is the same (I am testing button position) I'm having trouble finding somethng unique to use to track the event. I just need to force a different click text for the second button.

 

Thank you!!

0 Upvotes
ndwilliams3
Key Advisor

Google Analytics - Event Tracking

SOLVE

Use the below code. set the category to 'CTA' and use a unique_identifier for the label. everything within the category 'CTA' will be grouped together in GA. The unique_identifier for the label will track as separate events. The unique_identifier can be anything you want for each CTA you want to track.

 

$(document).ready(function() {
    $('#id_of_cta').click(function() {
        ga('send', 'event', 'CTA', 'click', 'unique_identifier');
    });
});
amjackson
Participant

Google Analytics - Event Tracking

SOLVE

Hi can you expand on this set up in GTM?

0 Upvotes
Daniel_Bleich
Key Advisor

Google Analytics - Event Tracking

SOLVE

Hi I added this in the page body:

$(document).ready(function() {
$('cta_button_1841855_c4c4b434-3651-4de4-813b-aafa19802b3a').click(function() {
ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’, value);
});
});

Is this correct or do I need to change any of the variables?

Daniel Bleichman
Marketing | AudioCodes

Danielbleichman@gmail.com
Did my post help answer your query? Help the Community by marking it as a solution
0 Upvotes