I use GoogleTagManager script and dataLayer object. I read in documentation that dataLayer object has to be filled above the GTM script.
But I need to add a product detail when the user chooses the product and it happens after the GTM script is loaded.
If I use dataLayer.push(chosenObject) will this action call the Google Tag Manager script? Will it work?
Yes, you can push variables to the dataLayer at any time, the "trick" is in how to access the data from the dataLayer in your tags (plus if you declare you dataLayer above the GTM code you do not call "push" - you declare it as a variable so you can push later).
It's necessary to declare the data in the dataLayer if you want to use it as soon as the page loads - the standard pageview trigger will run as soon as the GTM code has loaded (i.e. before the page has finished loading), so obviously GTM can only access data that preceeded it in the code.
Triggering tags in GTM takes an event (do not confuse with Google Analytics events or Javascript events, event in GTM is just a reserved variable name).
A few events are produced by GTM implicitly - the pageload-event, DOM ready, click and submit events.
If at some later point you want to trigger an element to respond to a value you pushed to the dataLayer you need a custom event:
dataLayer.push({
'event':'i_pushed_a_value',
'payload' : 'this is my data'
})
(please not that data comes in key->value pairs).
Now you can have a trigger that fires on the event i_pushed_a_value, and you can use a custom variable of the type dataLayer (enter the key, in this case payload, as key in the variable configuration) that holds your data.
Related
Wondering the best way to prevent a GTM tag from firing. I found https://rbardini.com/automating-gtm-data-layer-tests/ which tags about fetching the dataLayer variable and comparing it in an assertion, but this looks like a clumsy approach when you want to write to the dataLayer on every page.
For example, it suggests:
const getDataLayer = ClientFunction(() => window.dataLayer)
We use Google Tag Manager to automatically load tags on our website. Unfortunately one of them is CloudIQ (from PayPal) which pops up an iframe overlay offering a newsletter signup or ability to save your shopping basket. The Trigger in our GTM setup for that tag is simply 'All Pages'. When it pops up it generally blocks our test because Selectors cannot be clicked.
Our page flow is over several pages of an online shop, e.g.:
visit home page, click a product - navigates to a product page
click some options on the product page, then add to cart
go through checkout flow
So there might be many pages visited due to click actions.
There is an ability in GTM to define Variables and then use them in Exceptions for a tag, so I could prevent the CloudIQ tag firing either via a/ a global variable or b/ a dataLayer variable. However, I can't see how to elegantly get these set for each page visited during my test, such that they would exist when the GTM examines variables in order to block a Tag from being loaded. Fixture.beforeEach isn't right because it would only run once per fixture, and any data it set on the page's scope would be lost as soon as a page navigation occurs.
Anyone got experience of this sort of thing?
(The alternative of course is to detect the overlay, use switchToIframe to switch into the CloudIQ iframe and close it manually, but it pops up quite erratically and I'd prefer to simply disable the Tag altogether during tests as it's not core functionality of our website that we need to test.)
One way would be to set a custom user agent string to your test suite, create a custom javascript variable that returns the value for navigator.useragent, and make an exception trigger that blocks the tag.
Or any variation on that theme - set a cookie, use a url parameter, or if you test suite allow inject a global js variable, and check for the value in an exception trigger.
There is no need to avoid firing of events on the client side. Just mock the service routes for Google Tag Manager and CloudIQ and imitate correct responses for them.
I have developed a batch that retrieves our site's DB data and import into Marketo custom object with API. I tying to display this custom object’s value in the email body, but it is failing.
Script editor shows the custom object name but My token below returns no value.
$set($var = ${access_post_2_cList.get(0).title})
${var}
When I view the lead details, there is a Custom Objects tab, I can select the name of the custom object and see the records at there.
What did I leave to do?
Is this something about data type?
I am new to Marketo custom objects.
I am tracking PDF download using custom metric. I have written following code
<script>
dataLayer.push({'DLPdfdownload': 1});
</script>
DLPdfdownload is datalayer variable name that I have created in GTM V2.
Script is executing but the problem is that value for PDF download doesn't increment even if I download particular PDF many time. Value in the custom metric remains 1 only it doesn't increment with the download.
What changes do i need to make in script so that value get increment every time I download a PDF
Your question is somewhat incomplete. I'm going to assume from context that you are using Google Analytics with GTM and that you have already created a custom metric in your property settings.
The custom metric will only be incremented if you send it along with a Google Analytics hit. So you need to look up the numeric index for your metric in the property settings. Then you need to set up an Analytics tag that is triggeres when the pdf is downloaded, e.g. by a link click trigger. In that tag you expand the "custom metrics" section, enter the numeric index of your dimension in the index field and your dataLayer variable in the value field.
If that is what you are already doing, or if I have misunderstood your problem, you need to amend your question with more information.
Try to push some 'event' key's value in dataLayer with custom metric data and use custom event with this value as a trigger. Might be that you send data to GA before your custom metric value is pushed to dataLayer.
Is there a way by which I can duplicate or clone dijit widgets?
Basically, idea is to improve page rendering performance by minimizing widget creation time.
We have a single page web application and we do not reload the entire page whenever the user performs any action.
The flow of events is as follows,
The main page is loaded by the browser. It contains a dijit ContentPane which acts as a master container and displays the entire page using various other dijit widgets like textboxes, tabs, datefield, Enhanced grid etc.
The user performs an action (e.g. click on a dijit button)
The application sends an ajax call to server which processes the button click event and generates UI of the next page.
Browser receives successful response from ajax call and calls refresh method of dijit ContentPane. Which triggers destruction of existing widgets and new set of widgets are created and placed at appropriate position. (instead of refreshing the entire page)
The user again performs some action and again the refresh method is called which triggers destruction of existing widgets and new set of widgets are created and placed at appropriate position.
Because of such architecture the browser has to destroy existing widgets and recreate them again and again. Which results in slow performance.
The idea is to have a set of widgets always readily available on the browser clone them and place at appropriate position and update them instead of recreating each time.
Yes this is possible with something called _AttachMixin.
Basically there is no getting around the fact that your widgets would need to attach event listeners to the HTML Document. What can be cut out though is the time in the Dijit Widget's lifecycle to generate the DOM. As we well know, simple Dijit widgets like a dijit/form/Button has a div inside a div inside a div etc.
This is explained in detail here http://dojotoolkit.org/reference-guide/1.9/dijit/_AttachMixin.html
Here is an example using Node.JS as a backend. http://jamesthom.as/blog/2013/01/15/server-side-dijit
This is a tough problem and this concept isn't explained very thoroughly. If you have a backend that is not Node.JS you have to manually make the widget string and pass it as a response to your AJAX and an follow the example from the 1st link (Ref Doc)
We have had lots of widgets of our app render nicely within the client side. A far less complicated approach would be to simply show / hide (instead of render and destroy) widgets as and when they are needed. I assume that you app's access policy would focus on data and not which person has access to which widget.
I want to query the data from content type without using content query webpart. How could I do this?
My scenario is, I have a page layout, from the page layout I have created a page that contains some site columns values. After clicking on the save button I need to update the field in the page library column. How can I query the data in item updating event of the Site Pages Library.
Any help would be appreciated.
The ItemUpdating event method is passed an SPItemEventProperties parameter named property. This object contains information about the item responsible for firing the event handler. You can access this by calling properties.ListItem[Fieldname] or properties.AfterProperties[fieldname].
Something to note. The value of the SPItemEventProperties.BeforeProperties and SPItemEventProperties.AfterProperties as well as the properties of the SPItemEventProperties.ListItem, varies depending on the Event you are overriding and the type of SP List (List or Document Library). This chart shows these relationships.