The same tracking script exists across site.com and subdomain.site.com.
Everything works as desired, except both 'home pages' show as '/' and all the stats are combined.
I only have access to GTM and GA, with no access to make changes on the site. Any advice on how I can change the page name for only the subdomain home page in GA using GTM?
In the "fields to set" section of your Analytics tag (works for both Universal Analytics and GA4), you can overwrite the default value of the "page" field by adding a value to the page path when the user is on a subdomain. There are several more or less elegant ways to do that, but from the top of my head one would be to create a custom javascript variable (which is always and anonymous function that returns a value. Do not confuse it with the "javascript" variable type, which just returns the value of a variable from the global namespace).
function() {
if({{Page Hostname}} === "subdomain.mydomain.tld") {
return [{{Page Hostname}},{{Page Path}}].join("/");
}
return {{Page Path}};
}
You have to enable the built-in page path and hostname variables for that to work. Then you drop this new variable into the page field. It will return the page path with the subdomain prepended if the user is on the subdomain, else just the regular page path.
Or you use the same principle to just change the subdomain homepage
function() {
if({{Page Hostname}} === "subdomain.mydomain.tld" && {{Page Path}} == "/") {
return [{{Page Path}},"subdomain-home"].join("/");
}
return {{Page Path}};
}
Instead of the array with a join you can just as well concatenate with the plus sign ({{Page Path}}+"/subdomain-home"), that's just personal preference.
Related
I want to create a variable in GTM which returns the element which is closest. In a javascript tag it can be done this way:
function() {
return function(target, selector) {
while (!target.matches(selector) && !target.matches('body')) {
target = target.parentElement;
}
return target.matches(selector) ? target : undefined;
}
}
To make our website CSP compliant custom JS tags aren't allowed and we should create gtm variable templates.
The issue with a GTM template is you are not able to pass {{click element}} so I am looking for a method on how to access gtm.click from the datalayer and execute the closest function on that.
https://www.simoahava.com/analytics/custom-templates-guide-for-google-tag-manager/#restrictions-to-what-type-of-data-you-can-handle
Is the only way I am able to do this by injecting a script? I would rather fix this by using one of the gtm template api's.
In the dashboard of the new GA4, if I go to Engagement, Page and Screens, then press Page path and screen class I see repeated urls with query parameters with "?"
example.com/?utm_source=...
example.com/
I would like to ask how to unify the page paths
Query parameter removal with App + Web is a bit different because of the automatic pageview tracking. If you need to remove parameters from your page paths, you can use the page_location field in your Configuration tag in GTM. Keep in mind that there are no filters or view settings to strip query parameters in the Google Analytics interface as we saw for Universal Analytics.
i.e. If you want to remove all query parameters from your page path, we'll use the same method but a different Custom Javascript Variable.
In a new Custom Javascript variable paste the following:
function() {
return document.location.hostname + document.location.pathname;
}
https://www.bounteous.com/insights/2020/05/15/excluding-url-query-parameters-google-analytics/
You can use the config object in your measurement code to override the location string that is reported. You should see a line of code that goes like gtag('config', '...your id...') or gtag('config', '...your id...', { /* some config */ }). You need to either add the 3rd config parameter, or if it is already there you need to add a new attribute into it, so your code should look something like this after all:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=...your id..."></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '...your id...', {
'page_location': location.protocol + '//' + location.host + location.pathname,
/* other options if you have anything else */
});
</script>
Please note that this will remove all URL parameters so everything after the ?. If you only need to remove some, you need to implement a bit more logic and set page_location to the modified URL with only the unwanted parameters removed.
I have a SPA, I want to use routing for ng-view.
I have the code included in a page at domain.com/folder/dashboard.aspx
This is just a piece of that existing page, I can't move it elsewhere.
When I use route /list it alters my url to domain.com/folder/list/ which works, but breaks the ability to refresh the page (and gives a 404 since dashboard.aspx is not a default page, nor can it be)
How can I keep the url as domain.com/folder/dashboard.aspx/list?
I did try to setup my routes as dashboard.aspx/list and other various similar adjustments, but didn't have any luck.
Just like what #Claies said, it should be handled in your server config, just gonna drop my route config here in case you haven't tried this yet
var routeWithoutResolving = function (template: string, title?: string, style?: string) {
var name;
var slashIdx = template.indexOf('/');
if (slashIdx !== -1) {
name = template.substring(0, slashIdx);
template = template.substring(slashIdx + 1);
} else {
name = template;
}
var templateUrl = '/folder/' + template + '.aspx/';
return {
templateUrl: templateUrl,
title: title,
style: style,
area: _.capitalize(name),
page: template,
reloadOnSearch: false
}
}
Usage
.when('/domain.com/folder/dashboard.aspx/list', routeWithoutResolving ('folder/dashboard.aspx'))
I figured it out.
You can't use HTML5 mode, you have to be using Hashbang.
I set my routes as normal, /list and /list/item
For my links, I just used full urls, with the Dashboard.aspx#!/list/item and /list
I also removed the base tag from the html page
Experience Manager (XPM) (user interface update for SDL Tridion 2011 SP1) lets administrators create Page Types, which have component presentations just like pages, but also add rules on how to create and allow additional content types.
For a given page type, I'd like to simplify an author's options by limiting content type choices.
I understand we can:
Limit the content types, so that for a given page type authors can only create certain predefined content types
In the Dashboard, completely restrict the above to just predefined content types, by un-selecting Content Types Already Used on the Page
Use regions which specify combinations of schemas and templates along with quantity restrictions. Authors can only add (drag-and-drop) certain types and quantity of components to these region. For example, we can output the following on Staging to create a region:
<div>
<!-- Start Region: {
title: "Promos",
allowedComponentTypes: [
{
schema: "tcm:2-42-8",
template: "tcm:2-43-32"
},
],
minOccurs: 1,
maxOccurs: 3
} -->
<!-- place the matching CPs here with template logic (e.g. TemplateBeginRepeat/ TemplateBeginIf with DWT) -->
</div>
Authors may still see components they might want to insert (image below), but won’t be able to add them if regions control what’s allowed
However, folder permissions can reduce what components authors can see/use in the Insert Content library
Did I get them all? Any other ways in XPM functionality or possible extensions to consider on how to limit the allowed content for a given Page Type?
Alvin, you pretty much provided most of the options in your question. Another option, if a custom error message is desired or even finer level of control is to use the Event System. Subscribe to a Page's save event Initiated phase and write some validation code that throws an exception if an unwanted component presentation is on the page.
Since Page Types are really a combination of a page template, any metadata on the page and the types of component presentations on the page, we would need to check that we are dealing with the wanted page type and if encounter an CP that doesn't match what we desire, we can simply throw the exception. Here is some quick code:
[TcmExtension("Page Save Events")]
public class PageSaveEvents : TcmExtension
{
public PageSaveEvents()
{
EventSystem.Subscribe<Page, SaveEventArgs>(ValidateAllowedContentTypes, EventPhases.Initiated);
}
public void ValidateAllowedContentTypes(Page p, SaveEventArgs args, EventPhases phases)
{
if (p.PageTemplate.Title != "My allowed page template" && p.MetadataSchema.Title != "My allowed page metadata schema")
{
if (!ValidateAllowedContentTypes(p))
{
throw new Exception("Content Type not allowed on a page of this type.");
}
}
}
private bool ValidateAllowedContentTypes(Page p)
{
string ALLOWED_SCHEMAS = "My Allowed Schema A; My Allowed Schema B; My Allowed Schema C; etc"; //to-do put these in a parameter schema on the page template
string ALLOWED_COMPONENT_TEMPLATES = "My Allowed Template 1; My Allowed Template 2; My Allowed Template 3; etc"; //to-do put these in a parameter schema on the page template
bool ok = true;
foreach (ComponentPresentation cp in p.ComponentPresentations)
{
if (!(ALLOWED_SCHEMAS.Contains(cp.Component.Schema.Title) && ALLOWED_COMPONENT_TEMPLATES.Contains(cp.ComponentTemplate.Title)))
{
ok = false;
break;
}
}
return ok;
}
}
I have set up external link tracking as Goals in Google Analytics according to the GA documentation.
Here is the page in question: http://playmoreatthey.org/ - the external links on the page are formatted such as
Bayside Family YMCA
I set up the goal as a "head match" to the URL: /G1/bayside_family.com
I checked back four days later, and there are no results in the goals or pageviews for the phony "pagename" (/G1/bayside_family.com) specified in the JavaScript attached to each external link.
Looks like on your page you are using GA's async style code _gaq.push(...) but in your onclick you are using their old, "traditional" style code. You need to use
onclick="_gaq.push(['_trackPageview','/G1/bayside_family.com']);"
If you are using jQuery you can automatically track all the links on your site using this script:
// Outbound Link Tracking with Google Analytics
// Requires jQuery 1.7 or higher (use .live if using a lower version)
$("a").on('click', function(e){
var url = $(this).attr("href");
if($.trim(url).indexOf("javascript:") == 0) return;
if (e.currentTarget.host != window.location.host) {
_gaq.push(['_trackEvent', 'Outbound Links', e.currentTarget.host, url, 0]);
var target = $(this).attr("target");
if (e.metaKey || e.ctrlKey || target == "_blank") {
var newtab = true;
}
if (!newtab) {
e.preventDefault();
if(target) {
setTimeout('window.open("' + url + '", "' + target + '");', 100);
} else {
setTimeout('document.location = "' + url + '"', 100);
}
}
}
});
I found the script here: http://wptheming.com/2012/01/tracking-outbound-links-with-google-analytics/comment-page-1/#comment-39716
At the site you can find a debug version that will let you confirm that the script is working correctly.
I deviated from the original script by adding support for links with javascript (aka href="javascript:..."). Also I added code to honor the target attribute.
Here is a jsFiddle so you can see the script in action: http://jsfiddle.net/luisperezphd/45NPe/
One recommended way of doing this is through Events. That way your pageviews metric will not be inflated by the virtual pageviews tracked using the _trackPageview method.
http://support.google.com/analytics/bin/answer.py?hl=en&answer=1136920
I add this as an answer because Crayon Violent's comment above contains a broken link. At least someone will be able to edit this answer if the link needs to change again in the future.