GTM doesn't record event - google-tag-manager

I have mysterious problem. Sometimes GTM records the event and sometimes it doesn't.
It's totally random. When I tested 3/3 it recorded and the next day 1/3, sometimes nothing etc ... I also compared the entire source code on the page to see if there is / isn't something else that might cause a problem in some cases. But in both cases, the source code is exactly the same. In both cases, the datalayer pretends that the event exist but GTM will not record it.
Do you have any idea what this can cause?
Left when it is fired.
Right when it is not fired

I would suggest that perhaps if you're setting up the click event on DOM ready, perhaps the element isn't actually drawn to the page by that time (e.g. if it's an SPA app like Angular or Vue) consistently. So sometimes the event is configured and you see the event fire and sometimes it's not, so you don't.

Related

Inserted iframes are not cleared from the DOM with GTM

I have a GTM script implemented in my Angular application (SPA - Single Page Application).
When I change the page, a Page-View event is triggered via: window.dataLayer.push(obj)
obj represents the whole object.
On GTM side, I have 2 triggers as a result:
Insert to the DOM a Custom HTML element (a script element) that triggers another dataLayer.push with a simple object that indicates the new page view and the previous referer.
Insert to the DOM an iframe of type DoubleClick Floodlight to track certain behaviors for a short lifespan.
Now, to my understanding, these events should have been inserted to the DOM once and get cleared after that.
As it seems, for every page view that a user creates while navigating in the app, linearly, 2 elements are appended to the DOM (scropt element + iframe).
This behavior causes a tremendous amount of js heap size. I see a great memory leak in the Memory tab in chrome DevTools.
Of course, dataLayer keeps track of events and once it gets to 300 events it pops the oldest event, etc...
I would like to know is this is an expected behavior by design and it's just me that is missing a key component in GTM.
Am I supposed to create a cleanup tag to trigger after all of my elements are inserted to the DOM?
Or even better, try to track it and remove it from within my application?
I feel like I did not truly understand my problem so I can only hope you have a clue what I'm aiming to explain here.
Thanks ahead.
I did not try anything.
All I did was to read stackoverflow questions and answers, combined with a lot of articles, videos, dry documentation.
I do have a few leads as to what to try and tackle but I prefer the community to guide me through their experience if possible.

How can I make GTM tags fire "once per page" on a single page application?

I have a single page web app with a third party marketing tool I need to track. The tool implements a form.
What I need to know is:
How many people started filling in the form on a certain page type, i. e. first-clicked any of the fields (once per page)
All of the fields share the same class (at least partly). So I created a trigger that fires on
"[click classes] starts with [classname part]" AND
"[page url] contains [pagetype]".
This trigger is used for an event tag A with the "tag firing options: once per page", so that I do not get all of the element clicks, but only the relevant amount of starts which is per page. *
How many people successfully submit a form (once per page)
This was a little more tricky, since "successfully" means that I am not interested in simple button clicks, since those could also end in error messages if someone missed filling in a required field. Also, I do not get a success page, but a success message. The div this message appears in is always there, it is just not filled until submission. I solved this by creating a custom variable defining that element and an "element visibility trigger" that fires on
"[page url] contains [pagetype]" AND
"[custom variable]" equals [success message]"
+ DOM change observance.
This trigger is used for event tag B with the "tag firing options: once per page". This is necessary, since the marketing tool allows multiple successful submits of the very same form (please don't ask). Therefore, I need to restrict this to once per page as well. *
*) Now here's my struggle: This setup would be working fine for a multi page application with a standard page view tracking. However, I need to have my standard page view trigger to fire at history event changes, and this crashes my setup. I don't know how to restrict the two new event tags A+B for firing "once per page" if I don't have actual page views.
I cannot imagine that I am the only person who needs to solve this case. However, either everyone else just knows how to or I am not searching well enough - I don't find anything on this matter.
Does anyone have any idea on how to solve this?
Any slightest hint would be very much appreciated!
Thanks in advance!

Problem with asp.net C# focus, page_load

I'm really new to asp.net and have a couple of issues I'm trying to get fixed. I have some programming experience, but it is not asp.net. However, I've been able to follow the code enough to make other changes in the code to fix other issues.
The first is this:
I'm working with a form that has a calculate amount method that gets called when the user inputs a value in an amount text box. The same method gets called when the next control, number of payments, has a value.
So in the two controls:
onTextChanged="ctrlName_textChanged"
Then in the code behind, the textchanged method does:
calculateAmount();
The problem is after the amount is calculated and returns, the focus seems to get reset and the user has to tab all the way back through the form to the place they were.
The textboxes in question are in a panel that starts out hidden and is made visible conditionally.
My apologies if I have not used the proper .net terminology.
It looks like the same issue may be causing my second problem. When the user types in an amount and then tabs and quickly adds the number of payments, you can see the amount get calculated correctly and very shortly displays the proper total in the total amount text box. However, even though it shows for that short time, the tab order again gets reset as well as the total amount value.
I've looked at different methods to try and fix the focus issue.
In the textchanged method, I tried using something like:
Session["myval"] = "someval";
Then tried to check against that in Page_Load with something like:
if(Session["myval"] != null) {
this.NextControl_Name.Focus();
}
but it didn't ever work correctly.
I also tried to set a cookie in that same textchanged method using something like this:
Response.Cookies["myval"].Value = "somevalue";
Then tried to check that in Page_Load using something like the previous if block above but using Request.Cookies["myval"] as the source.
Is there a good reference with some really clear code samples I can look at for this type of implementation?
Thank you in advance,
C.
Sounds like you have a postback problem...
Remember that the web is stateless. This means that when you have a web page rendered out in .NET and you attach an event that executes serverside code... it does an HTTP POST back to the server which is effectively a new page request. The Page_Load method will fire again as well as your bound event. So your onTextChanged event is firing a new request back to the server. This is why you see the focus reset and why when you tab quickly, the value seems to disappear magically.
You can do one of several things, you can implement the UpdatePanel in the AjaxControlToolkit
http://www.asp.net/ajax/ajaxcontroltoolkit/samples/
you can use PageMethods and do your validation with javascript and jQuery (or other js library)
see page method info http://www.geekzilla.co.uk/View30F417D1-8E5B-4C03-99EB-379F167F26B6.htm
Hope this helps

Page_PreRender fires twice on first load in session

When I run the web application, I notice that Page_PreRender is fired twice. This only happens the first time in a new session. It does not happen if I refresh the page, or on postbacks.
I use .NET framework 3.5 and the built in ajax functionality.
The problem is not
related to img tag with empty src
attribute (which I have seen other posts with similar problem
has mentioned). I know this because I see this in
both FireFox and IE. The posts I saw
about this stated that this was not a
problem in IE. I have also searched
and found no img tags with empty src
in the generated page source, so it
should not be this.
I have also made a simple test
page where I have included some of
the functionality, and this does not
happen.
Have anyone any suggestions on what happens?
Note:
It is the entire page cycle that is firing twice, not just render.
I've experienced it; it's probably not what you are experiencing, but I'll enter it here anyway; I've noticed it when the application does a Response.Redirect at the PreRender level, which a redirect does not stop current execution, but makes it appear the event happens twice...
Again, probably not related, but including it just in case.
I copied some code that states:
Page.LoadComplete += new EventHandler(Page_PreRender)
I did not realize that this code fire for second time my Page_PreRender event.
When I comment it, never fire twice.

Why does my session variable appear to empty itself in ASP.NET?

I have user control on a ASP.NET web page, which contains a GridView and a radio button selector.
In the underlying middle tier I have a thread which goes to the database and then raises an event to say "I have some data" my User control handles this event and sets a Session Variable.
This works and I can see the event being handled and the Session variable gets the new data.
However when i go to use this session variable when the selected index of the Radio button selector changes the Session variable reports as "Nothing"
I have ensured that the obvious (i.e. spelling, Sessions switched on etc) are correct.
The GridView and radio button selector are encapsulated in the same Update panel.
Check that if your UpdatePanel - updatemode is set to 'Conditional'? also Child as triggers? I would first start by putting a stop in your page load, see whats happening from there. Do a search for all places where you populate that session variable and put a stop. You may be surprised, I have often found that page lifecycle gets confusing even though I thought I understood it. Alt - post some code and we can step through.
Yeah, sounds almost like a problem with order of operations or not checking for postback on a page load or something?
Like JamesM suggested, running your website in debug mode should really help identify the problem. You can bring up your watch window and set it for the Session variable you're looking for, then set breakpoints all over and check the value at each stop to divide and conquer the code.

Resources