Can I use Google Tag Manager with the new Google Sites? - google-tag-manager

I have a new Google sites and already use Google analytics with it but I also would like to use Google Tag Manager. Any one know a way to make that work?

Not really. You could technically add an "Embed" element to the site and add your GTM snippet there. But you can really only trigger tags when the embedded element loads similar to a page view. I believe these elements are similar to iFrames so I don't think you could get any data from the parent URL either.
Otherwise, you can still add Google Analytics by going to "Settings".

Related

How do I Add 2 GA4 instances to a website

I have a domain that has several sites sitting underneath it.
ie
My.domain.com/firstsite
My.domain.com/secondsite
My.domain.com/thirdsite
I have created new GA4 properties under a central account for each site. The GA4 is applied to the relevant pages via tag manager and the inbuilt GA4 tag, the trigger was the specific url of the page and everything is currently tracking as expected without issue.
I would like however to add an overriding GA4 account to collect the events for all pages.
Is this as simple as me adding another GA4 property to all pages or is there anything I need to mindful about.
Many thanks in advance for your help.
You dont have to create seperate property for each site. You can add one property(or configuration) to each site.

GTM Not Writing to Page With Custom HTML Tag

I'm trying to implement schema markup on my site using Custom HTML tags in Google Tag Manager. When I preview my changes, it works perfectly. However, when I push the tag live, it does not appear on my page.
I've had a similar issue with tags in preview appearing differently than in live. But when I tried looking into it, it I couldn't find an answer on why that would happen.
So I'm wondering if you have any insights into why this tag works in preview, but does not work live?
I figured it out. We had an X-XSS-Protection header set to 1;mode=block which was limiting Google Analytics from injecting scripts that could be considered an XSS attack.
This could have also happened with an incorrectly configured Content-Security-Policy.
The correct way to set up a Content-Security-Policy that allows Google Analytics and Google Tag Manager to inject scripts is outlined in this Lunametrics article (take note of Simo Ahava's comment after the post).

WixCode Opting out of Google Analytics

Can anybody help me to find a solution how to make this code work on my Wix-Site:
Click here to opt-out of Google Analytics
I have this code from Google itself (At the bottom of the page see "example"):
https://developers.google.com/analytics/devguides/collection/gajs/
Here is a Screenshot of this code from the google website:
Google Analytics Opt Out Code
I tried this:
$w("#text1").html = "<a href='javascript:gaOptout()'>Click here to opt-out of Google Analytics</a>";
But I was told that in Wix it is not possible to add events to a-tag elements in text element. Here you will find the little discussion that I had on Wix Forum:
https://www.wix.com/code/home/forum/questions-answers/how-to-link-text-to-a-url-using-w-link
I also asked on Reddit, Facebook and WixSupport. But nobody could help me with that issue.
You might want to take a look at the new wix feature called "tracking and analytics". It lets you embed custom scripts in your html's body, header, or footer.
https://support.wix.com/en/article/about-tracking-tools-analytics
You cannot access the HTML directly via Wix Code. Wix Code exposes a dedicated API for you to manipulate their controllers and elements on screen but not further under the hood.
You can use wix-fetch to call external API calls to google analytics (if they have an API to opt-out, not familiar enough to say here is the post)
anyway, your code in Wix should be something like this:
(as example API taken from their docs)
import {fetch} from 'wix-data'
fetch('https://analyticsreporting.googleapis.com/v4/...', options) // returns a Promise

How to run Google Experiment within Google Tag Manager

I have been trying to get this to work for sometime and there seems to be very little information on how this works.
First, I would like to say that I tried the below method to get it working, so please read this before posting a solution.
What I tried:
I added the google analytics experiment code in a custom HTML block and had it fire only of the original page as stated by google. This doesn't work and seems to create a loop for users. A white page appears when users get to the experiment pages.
Does anyone know how to get this to work? Much appreciated
The Javascript versions of Google Content Experiments are not actually supported in GTM at the moment (they have do do either redirects or change the site on the fly and since it's hard to say in advance at which point during page load the tags fire, and it which order, this does not work very well - in the very best case the original page would load completely before the visitor is redirected to a variation).
The features page for GTM lists A/b testing tags as "coming soon" but does so since at least a year ago, so I wouldn't hold my breath.
However you can do variations serverside (you'd have to implement your own logic to display the proper variation to each users) and pass and experiment id and the variation number to GA via GTM. I do not think there is another (reliable) way to do this, at least not yet. If you need to do it with javascript you should add the experiment scripts to the page code instead of deploying them via tag managemement.
Having said that, there are descriptions for hacking around the GTM limitations using the Experiments Javascript API and some jQuery (here is one). When Google says that something is "not supported" it might just mean they didn't want to test all possible edge cases and err on the safe side. So you if you absolutely have to use GTM for Content Experiments you would have to test if something like this would work for you.
I hope that I understand your problem well. If yes, you can use Google Optimize instead of Google Experiment. The Google Optimize works with Google Tag Manager by default.
Here's what worked for me
For the pages in the Experiment, I implemented Google Analytics the "old fashioned way" with analytics.js instead of GTM.
I tested (with Realtime analytics) this and the Experiment page and the Google Tag Pages both report data.
I did post asking if there might be conflicts from ths.
It's possible to modify the Google Tag Manager (GTM) snippet to run synchronously by removing the j.async=true; line and placing it at the top of your page, immediately after the opening <head> element. Like so:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>
<!-- End Google Tag Manager -->
You can also retain support for users without Javascript by inserting the <iframe> part of the code in the original location specified by GTM (after your opening <body> element).
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe</noscript>
It's then possible to insert the Google Analytics Experiments code as a Custom HTML tag in GTM. Just make sure you check the 'support document.write()' checkbox.
Just don't forget to update GTM-XXXX with your container ID.

Adding CSS to Google Calendar iFrame

I'm working on a site that needs a basic calendar, and thought of adding in Google Calendar. The thing is that I would really like to style the whole embedded calendar, but it's in an iframe and even adding !important to the targeted classes does not work.
Is there any way of adding some css to that iframe? Through some JavaScript or something?
Thanks!
You are not going to be able to do any styling on the iFrame, if you do you'll get the cross-domain origin error. Essentially, you are locked out of tampering with an iframe for security reasons. You should look into pulling the feed/json of the google calendar and creating the entire view yourself.
The settings offered by Google are only basic, however, and so for it to fit the unique style of your site, you’ll want a bit of extra editing power. Unfortunately adding CSS rules to the parent document doesn’t work, even when adding an !important directive to each rule.
https://www.webdesignerdepot.com/2012/04/integrating-google-calendar-with-your-website/
Because of the same-origin policy, it isn't possible to inject CSS into an iframe.
However, these days there are a number of third party apps that make it easy to style and embed Google calendars.
Here is a short list of options:
Styled Calendar
Tockify
ChronoFlo Calendar
Or, if you'd rather use something open source, FullCalendar is a great solution. Here is some documentation on how to use their Google Calendar plugin: https://fullcalendar.io/docs/google-calendar
*Full disclosure, I'm a member of the Styled Calendar team

Resources