Google Tag Manager... Will data layer for server side rendering override the data layer for web? - google-tag-manager

I am looking to add server side rendering for google tag mananger. We already have web rendering, and if I just add another for server side will it override the data layer?
web layer: https://developers.google.com/tag-platform/tag-manager/web/datalayer
server layer: https://developers.google.com/tag-platform/tag-manager/server-side/send-data
current code:
so will window.dataLayer.push({ event: name }) go to both or it will only go to 1?
I tried reading the documentation but it wasn't clear

It will go both of the container.
Since server side is waiting sending data from your webiste.
The DataLayer is kind of something providing the information.
DataLayer -> GTM Web container -> GA, GA4, Other market tool.
DataLayer -> GTM Web container or other way -> GTM Server container
The rough direction should be above.

Related

hide or show an element on client with using signalR

I'm trying to hide or show an element on the client by updating a parameter on db. Is that possible with signalR? Or is there any other way to do it?
Note: my application is based on asp.net core mvc (entity framework)
Asp.net core SignalR is used to create real-time web functionality, are you sure you want to achieve this behavior?
"hide or show an element on the client by updating a parameter on db."
For this question, it depends on how you want to hide or show the element, real time or just one time?
If you just want to hide or show the element when page load (one time per page load), you can query the database and get the condition (parameter from the database), and then use an if-else statement to hide or show the element.
If you want to change the element status real-time, you can use SignalR.
Create a scheduled task on the back end and trace the database parameter status, if the parameter changes, call the client method and show or hide the element.
Reference:
Background tasks with hosted services
How can I execute a method every year using BackgroundService in ASP.NET core Application?
Send messages from outside a hub

Tracing Telemetry in Application Insights across different layers

I'm currently using App insights for logging exceptions and tracing.
My project is Asp.net MVC based and I've 3 different layers. One is front end (MVC with angular) and rest two are Web API service layers.
I've default telemetry logging enabled for all the 3 layers and it is logging all the operations.My problem is that I'm not able to correlate the operation on all the 3 layers. How can I achieve this. I've read that one option is to set the custom property (userID in session) on Telemetry Initializer , but I don't have that information on my Web API layers as they are stateless.
One solution I can think about:
You can generate an internal identifier (e.g. a GUID) for each operation in your MVC layer, add it as a custom parameter (using the Telemetry Initializer) and pass that same ID to the Web API layers for each API call you make. For every telemetry event these Web API layers send, add the identifier as a custom parameter in the same fashion as above.
This way you will be able to correlate the events based on your internal ID.
Besides the already mentioned alternatives, there's already partial support for this built into AI through the ParentOperationId and OperationId context fields. However, there's nothing in place right now that can propagate the fields through Http calls automatically.
It should be possible to have your code add the necessary headers when making outgoing HTTP calls and if you use the right ones, and the other side has the necessary telemetry initializers, it should be better.

Message Handlers and the Http Module?

In ASP.NET Web API, HTTP requests and responses are processed in a
pipeline on the server.
If I want to add some logic or global behaviour at the very early stages of the pipeline , I should do it in the Message Handler. ( for example : authentication)
But what about the Http module pipeline ? where it fits in this whole story ?
Looking at this numbered stages of web api life cycle :
http://i.stack.imgur.com/jkQe8.jpg
But looking at the Http module general events ( contains more but...)
Question :
— How those 2 systems combine and where ? I mean if there was 1 picture which contains web api and http module , how would the numbers be ? (I added numbers in the images for easy referencing)
— I always hear that If i want to do things earlier at the pipeline I should use message handlers , but what about HttpModule's BeginRequest for example ? I know that there are objects which are null at this stage but still , later phases at the httpmodule does inflate HttpContetxt's objects - and yet , webapi's guys says : use MessageHandlers....(is it relate to the fact of selfhoster environment) ?
To combine the figure below into the top one, imagine IHttpHandler box in the top figure corresponds to ASPX in the below image so that you put the down image to the bottom left of the top one. So, 8 and 9 are part of the IIS ASP.NET pipeline. IIS pipeline runs modules, etc and terminates when a handler handles the request. With web API, that handler happens to be HttpControllerHandler and this is where Web API pipeline starts. If you look at HttpControllerHandler, the request and response are ASP.NET specific to its left and to its right it becomes HttpRequestMesssage which is Web API specific.
To your second question, the earliest you could do in Web API pipeline will be a message handler. HttpModule will be even more earlier but is not part of Web API but the hosting. Trade-off is that if you have an HttpModule, you can use it only in IIS whereas a message handler can run in any host, since it is Web API specific and host-specific. I keep referring to my MSDN article in my recent SO replies but then it so happens that the article is relevant to the questions being asked. So, I have no other go but to again link it. Here you go. I have comparison of different options in that article.

IBM Worklight 6.1 wlCommonInit() behaviour

I want to know what is exactly the behaviour of wlCommonInit() function.
I have moved my initialization code into this function, but then it seems to be not called in the case of connection to the server failure.
is wlCommonInit() called when the Worklight server is not reachable ?
If I want to use direct update, I want to call WL.Client.updateUserInfo() on my initialization, and I want the app to be working also in offline mode, does this mean I must implement onConnectionFailure in wlInitOptions ?
If I implement onConnectionFailure in wlInitOptions, can I display the default popup that inform about the connection failure, and provide details ?
It really depends on the logic you wrote in your "initialization code" IMO. The question is somewhat cryptic...
The wlCommonInit function is called once the Worklight framework has completed initialization. If you set connectOnStartup to true, only if connection to the server is successful, it will then be called.
Direct Update is not related to any specific API you implement in your application. If you change any web resource in your project (HTML, CSS, JavaScript, images, ...), this will trigger a Direct Update in the application.
A Direct Update is checked in 2 scenarios:
on application launch, and
on return to the foreground (if the app was in the background)
The Direct Update check is performed only if and when the application connects to the Worklight Server. If you did not previously set your application by either using connectOnStartup:true or used WL.Client.connect or invoked an adapter procedure (all three send a request to the server), the Direct Update check will not be done.
If you choose to override the default dialog provided by Worklight by using onConnectionFailure, the Details button (which I assume if what you wanted) - is not available. By overriding, you select to fully customize it.

Attaching an event listener to all URLRequest's

We have a flex application that connects to a proxy server which handles authentication. If the authentication has timeout out the proxy server returns a json formatted error string. What I would like to do is inspect every URLRequest response and check if there's an error message and display it in the flex client then redirect back to login screen.
So I'm wondering if its possible to create an event listener to all URLRequests in a global fashion. Without having to search through the project and add some method to each URLRequest. Any ideas if this is possible?
Unless you're only using one service, there is no way to set a global URLRequest handler. If I were you, I'd think more about architecting your application properly by using a delegate and always checking the result through a particular service which is used throughout the app.
J_A_X has some good suggestions, but I'd take it a bit farther. Let me make some assumptions based on the limited information you've provided.
The services are scattered all over your application means that they're actually embedded in multiple Views.
If your services can all be handled by the same handler, you notionally have one service, copied many times.
Despite what you see in the Adobe examples showing their new Service generation code, it's incredibly bad practice to call services directly from Views, in part because of the very problem you are seeing--you can wind up with lots of copies of the same service code littered all over your application.
Depending on how tightly interwoven your application is (believe me, I've inherited some pretty nasty stuff, so I know this might be easier said than done), you may find that the easiest thing is to remove all of those various services and replace them by having all your Views dispatch a bubbling event that gets caught at the top level. At the top level, you respond to that event by calling one instance of your service, which is again handled in one place.
You may or may not choose to wrap that single service in a delegate, but once you have your application archtected in a way where the service is decoupled from your Views, you can make that choice at any time.
Would you be able to extend the class and add an event listener in the object's constructor? I don't like this approach but it could work.
You would just have to search/replace the whole project.

Resources