How to access window.screen from within a GTM custom template using sandboxed JavaScript - google-tag-manager

I'm trying to use copyFromWindow to get the read only screen.width and screen.height properties from within a custom template in GTM.
In the code I have used copyFromWindow('screen.width'), and in the permissions tab I have tried to add screen.width to the keys, but I get the error:
The value must not start with any key predefined on global scope (i.e. in Window), or any JavaScript keywords.
I've also tried adding just width to the permissions tab but then I get a permissions error thrown by the tag itself when it runs:
failed access_globals permission check. Prohibited read on global variable: screen.width
How do I get access to these built in global variables from the sandboxed JS?

Related

NuxtJS Cannot read property "property_name" of undefined

I am using this.$router.push('/route/path') to change routes in nuxt.
However, when I get to the new route, the page gives an error:
Nuxt Cannot read property propertyname of undefined
However, the property it is referring to is on the previous page on a component which is not loaded in the current page !
I am using nuxt in SPA mode.
when I use location.replace('/route/path'), I dont get the issue, but obviously we dont want that because then a new page is refreshed.

Angular component jenkins build issue for 'auto' css property

In template file for angular component, I am using 'auto' css property with ngStyle, as:
'height' : (some_condition) ? '16px' : auto
Component works as epxected.
But in jenkins build, I get error as:
Property 'auto' does not exist on type 'MyComponent'.
What's the reason for this error?And how can to get rid of it?
Not single quotes ' around auto is what causes the issue.
Angular thinks auto is a variable in your component because you're setting the property of your DOM element via binding, which sort of expects something like this: [property]=yourVariable.
To fix it, you can either have a variable in your component that holds the string "auto" or you can simply type 'auto', with single quotes, in your template.
Also, when serving your app, try using the --aot flag (ng serve --aot). Doing so should prompt you with the same error you get with Jenkins but you won't have to actually build.
This flag is great and should always be used when possible in my opinion.

Is it ok to pass objects requiring evaluation to the GTM dataLayer variable

When using the GTM (Google Tag Manager) dataLayer variable, is it ok to pass objects whose properties are revealed via getters? In the image below, the last item pushed to the dataLayer array shows ellipses (...) for the properties. When hovering over the ellipses you get the message "Invoke property getter".
I want to confirm whether this can be a problem for GTM or not.
It will cause the issues in GTM because it's expecting simple JS properties and not getters. In gtm.js it just reading properties and not executing them

Setting a Dynamic Macro in Google Tag Manager

I have two types Universal Analytics (UA) accounts: a rollup property ID that goes on all subdomains, and a subdomain-specific ID that only appears on that subdomain. There are a total of 7 subdomain properties.
I was wondering, instead of setting up 2 tags (ecomm transaction tag and the regular UA tag) for each subdomain/property - a total of 16 - if I could set up just those two tags and have the UA-ID dynamically changed for the corresponding property.
Example: set up the tag with the id as "UA-XXXXXXXX-{{UA ID}}" where "{{UA ID}}" is defined by me and set with a rule depending on what the current subdomain is. Somewhere - without asking the devs to create a new variable pair - have property one associated to "1", property two associated to "2" and so forth, so that the right tracker is fired on the right subdomain.
Thanks!
I did this via the following workaround:
I created a custom html tag that loads when the DOM is ready ( rule "{{event}} == gtm.dom)
inside that custom tag I put some javascript to determine the subdomain (or whatever dynamic property) and set a variable - let's call it "ua" - accordingly
inside the same tag I push the ua variable and a custom event to the datalayer :
dataLayer.push({
'ua':ua,
'event': 'INIT'
});
I created a macro "UA ID" that gets it's value from the push variable above
I created a rule "on init" ( {{event}} == INIT
I used that rule to fire all subsquent tags (so they would be executed only after the UA variable has been set)
So far (i.e. for the last 2 months) this is working rather well, so it might work for you, too.
Actually I think it will be a lot easier for you if create a lookup table with hostname as a base. Then just add the UA properties for all of your subdomains, each on new row in the lookup table. Afterwards you just use this lookup table as the variable for your UA:
It's a cleaner option to manage a lot of GA properties.

Accessing properties of AdvancedDataGrid runtime vs. design time

I am new to Flex and trying to modify some existing code. I am trying to It uses and AdvancedDataGrid. In the click event, the ListEvent is passed in, and the code is able to access properties such as event.itemRenderer.data.feature.
I would like to check whether the user has clicked on a parent (group) record or the child record; at runtime, I can see that the property I want to access is event.itemRenderer.listData.hasChildren. However, the listData property of itemRenderer does not show up in intellisense, and when I try to access that at design time, the project will not build because of the error "Access of possibly undefined property listData". But the property .data.feature doesn't show up in intellisense at design time either, and that builds and runs just fine.
What do I need to do to access event.itemRenderer.listData without throwing errors when I build the project? Do I need to capture a different event, or cast the event object or one of its properties into another object that will have the properties I need at runtime (I've investigated these options but cannot find info on how to do that).
Many thanks for any insight.
You probably have to perform a cast using IDropInListItemRenderer and AdvancedDataGridListData. Something like this:
((event.itemRenderer as IDropInListItemRenderer).listData as AdvancedDataGridListData).hasChildren

Resources