Possibility to get unique id per object instance in the grid?
Hi!
Currently busy implementing a GTM (Google Tag Manager) solution for our client. They requested that for every element on the page an unique id has to be generated in order to let SEO do its work properly (so for example, a button with an attribute "data-gtm="uniqueID")
However, after spending some time analyzing the possibilities with Umbraco it seems that there is not a way to find the instance of a grid element - this is needed because there are situations where buttons will have the same appearance, text and perhaps even the same href. So after trying a couple of possibilities to combine these properties I have concluded the only way is to have some sort of instance ID of the grid object.
Using Javascript/Jquery would be to late for GTM (as GTM needs to be loaded before the page loads). Instead, even though it is not the cleanest way to do it, I made a helper class and used httpcontext for it:
public static class GtmHelper
{
public static int GetIndex()
{
var gtmIndex = HttpContext.Current.Items["GtmIndex"] as int?;
if (gtmIndex == null)
{
gtmIndex = 1;
}
else
{
gtmIndex++;
}
HttpContext.Current.Items["GtmIndex"] = gtmIndex;
return gtmIndex.Value;
}
}
Then for each element it is needed on I used this helper in the elements code. That works perfectly. :-)
Possibility to get unique id per object instance in the grid?
Hi!
Currently busy implementing a GTM (Google Tag Manager) solution for our client. They requested that for every element on the page an unique id has to be generated in order to let SEO do its work properly (so for example, a button with an attribute "data-gtm="uniqueID")
However, after spending some time analyzing the possibilities with Umbraco it seems that there is not a way to find the instance of a grid element - this is needed because there are situations where buttons will have the same appearance, text and perhaps even the same href. So after trying a couple of possibilities to combine these properties I have concluded the only way is to have some sort of instance ID of the grid object.
Does anyone has something for this?
Thanks in advance!
Hi Emiel
As far as i know there is no way to get an id for the grid element. You could do it with javascript/jquery though.
Something like
Using Javascript/Jquery would be to late for GTM (as GTM needs to be loaded before the page loads). Instead, even though it is not the cleanest way to do it, I made a helper class and used httpcontext for it:
Then for each element it is needed on I used this helper in the elements code. That works perfectly. :-)
is working on a reply...