Sending event to specific property - google-analytics

I am trying to send an event to a specific property on a page. The page has multiple properties on it and I only want to raise this event in one specific property.
I have used ga.getAll() to see the properties on the page and the one I want is labeled gtm3 so this is code I am trying:
ga("gtm3.send", {
hitType: "event",
eventCategory: "Heartbeat",
eventAction: "Beat",
eventLabel: "Heartbeat",
nonInteraction: true
});
This does not work, debug mode gives me the message:
command ignored. unknown target undefined
What did I do wrong?
I am testing this in console also so the tag is definitely registered. Am I referencing it wrong? In the getAll() I can see the property name: "gtm3".
I am running this code on doc ready but have also tested direct in console so I don't think it is a timing issue. What is proper way to reference this property and reference an event?
edit:
I also get the same message when I just run a simple: ga('send', 'pageview');
Why is target undefined?

OP was using Google Tag Manager as the method for GA implementation. Suggested to use DataLayer events to send the heart-beat event to GTM and utilize triggers within GTM to send the heart beat event to the appropriate GA property.
DataLayer Trigger on page:
....
DataLayer.push('event':'heart-beat');
....
The above is captured within GTM in a Custom Event trigger.
The Custom Event trigger is then used on a GA Event Tag set to non-interaction.

Related

How to send specific information from client side to Google Analytic 4 (NOT Universal)?

While defining tag and triggers in Google Tag Manager, is there a way I could define that specific information from my client goes into GA4? for example I want to send the so-called store code whenever a user click on a button, so that I can understand exactly which store has had this click. The click event is not my point, I have already defined the tag and trigger, my problem is that why in the response GA4 gives me some info is missing.
in my Tag I have defined a new event with the parameter shown in photo:
then the trigger is
Thank you in advance
You can just modify the parameter name like this
If this setting is not working. Then the problem will be the {{Click Text}} is not returning as you expected.
Ok I found a way to send info, based on this link [GA4] Custom events which is a JavaScript code. However this is not what I was searching for because it is dependent to coding part and I wanted something which I can do from GTM
<script>
/**
* The following event is sent when the page loads. You could
* wrap the event in a function to call the event when certain
* events (e.g., a click event) happen on your site.
*/
gtag('event', 'Your Event Name', {
'your_param1': 'value 1',
'your_param2': 'value 2',
});
</script>

Is it possible to detect keypresses using Google Tag Manager (GTM)?

The idea is to check if someone started filling in the form but hasn't submitted it. Is it possible to detect physical keypresses with GTM?
Yes, quite easily, with the following:
HTML:
<input type="text" onkeyup="dataLayer.push({event:'textChanged', eventAction: this.value, eventLabel: location.href, eventValue: 0.0});">
Note that the eventAction, eventLabel and eventValue are optional and customizable.
GTM Tag: Google Analytics, "Event"
GTM trigger: Custom Event: "textChanged"
GTM is Javascript, and in Javascript it is possible to detect key presses, so it is possible to detect key presses in GTM by using a custom HTML tag to implement your own keyup/keydown event handler. Documentation for the event handler is here.
A more typical way to detect form interaction is to implement event handler for the change event on text fields. Warning, this might lead to excessive firing of events (but then, so might tracking keystrokes).

Prevent Google Tag Manager event based on dataLayer variable

I have a Google Tag Manager tag configured to fire on all page views. However, on some pages, I may need to disable the tag based on internal data. To me, this sounds like a job for the dataLayer.
My initial thought was to create a dataLayer variable called "disableGTMTag" and give it a value to validate against. Then GTM could evaluate that value and take appropriate action.
So, in the dataLayer I created a disableGTMTag variable and hard-coded it to always have a value of "google" (for testing purposes). Running the page in GTM debug mode, I can confirm that the disableGTMTag variable is present in the dataLayer with the value "google".
To set up the tag, I updated the tag's trigger to fire only when disableGTMTag does not contain "google". But the tag still fired. I then tried setting the trigger to fire on All Pages but added an exception when disableGTMTag contains "google". The tag still fired.
My understanding is that a trigger exception must be the same type as the firing trigger. But I went ahead and created a secondary exception for a custom event that matches the regex ".*" that looked at the disableGTMTag value. Still, the tag fired when the page loaded.
This seems like a straightforward thing: always run this tag, unless this dataLayer variable tells you not to. But it's just not working for me.
Is there a different approach to restrict page view firing? How do I prevent page view-based tags from firing using a dataLayer variable?
I've found a solution. The recommended way to reference the dataLayer is as:
window.dataLayer = window.dataLayer || []
But I found that when I used this convention, my Page View event fired first and then all my data messages happened after making the dataLayer values unavailable. Changing it to:
window.dataLayer = []
forced the messages to happen before the page view event, making the dataLayer values available to be evaluated. I understand that this is going to re-declare the dataLayer, but this worked.

Google Tag Manager dataLayer variables are undefined

When my page is displayed, I push some data to Google Tag Manager (GTM) dataLayer:
dataLayer.push({
event: "MY_EXPERIMENT",
variant: "A",
result: "FORM_DISPLAYED"
});
When the form is submitted, I push some new data:
dataLayer.push({
event: "MY_EXPERIMENT",
variant: "A",
result: "FORM_SUBMITTED"
});
I've created dataLayer variables in GTM, and I've inserted those in the category/action/label fields of my tag in GTM. One of the variables is setup like this:
The tag is triggered by URL path, and in preview mode it works.
However, when I look the event up in the live dashboard of Google Analytics, only "undefined" is displayed in the category/label/event columns. It seems to me the variables are not set up correctly, but I've looked through everything and it seems just fine.
What am I doing wrong?
It's hard to tell without any screenshots or further details but what's most likely happening is that your tags are firing too early. You said that the GA event tag is triggered based on a URL path. This most likely means that you're using the All Pages trigger in GTM with an optional filter to only fire on specific pages. However, you're most likely only executing those dataLayer pushes after the GTM container code. This means that at the time of tag firing, those dataLayer pushes haven't executed yet and that's why you're getting undefined in the values of the variables.
To fix this you should change the trigger of your GA event tag from All Pages to a Custom Event. In your case, the custom event name would be MY_EXPERIMENT.
I figured this out. I hadn't checked the "Use Datalayer" checkbox under More settings -> E-commerce in my event tag in GTM. Hard to find the checkbox, and I haven't seen it documented in any tutorials. But that solved my problem!
Sorry for no screenshots.

Custom Event Not Firing in Google Tag Manager

I am trying to fire a custom event in Google Tag Manager for a Virtual Page View. I want to be able to track a conversion in a dynamic shopping cart page where the actual URL does not change.
I added the following code for a dataLayer and set it up to fire when the event= VirtualPageView but it's not working.
Any ideas?
dataLayer.push({
'event':'VirtualPageView',
'virtualPageURL':'/thankyou',
'virtualPageTitle':'Thank You'
'conversionValue':'value'
'currencyCode':'currency'
});
Google Tag Setup
Custom Event Setup
Looking at your code I see a lot of missing commas after everything but the second line. This will cause the JS to fail which means no event is pushed into the dataLayer which means GTM won't see anything happening and therefore not fire any tags.
I.e. add a comma after 'virtualPageTitle':'Thank You and after 'conversionValue':'value'. Keep in mind that if you actually pass 'value' as a string and an AdWords Conversion Tag looks for a float, it will fail that tag.
GTM is fairly finicky and will just stop execution when JS code related to it fails.

Resources