Google Analytics Implementation - google-analytics

I'm looking at implementing Google Analytics and was wondering:
Can the tracking code be put in an external file, with the rest of my js then minified? If not, can the js be minified to one line then used on my page?
Or does the code have to go in my ? In some examples I've seen it after the body tag at the bottom of the page, why is this?

yes you can put it in your external .js file.
No It doesn't matter really where in the page you place it. Some people put it in the Head tag others in the footer. Personally I place it in the head tag that way I can add event tracking and custom dimensions though out the page as its built. But its really personal preference where you place it.

Related

Dynamic open graph tags in Single Page Application

I am trying to inject op:tags in my reactjs App. I came across https://github.com/nfl/react-helmet and it dynamically inject the tags ion my index.html header juts like i wanted it. The problem is, it injects the tags at the end of the head and thus was not recognised by facebook debugger here. It works when the ogen graph tags appear right in the beginning of the header before the script tags. With reac-helmet however, it injects them at the extreme end. Please how do i best fix this ? I am trying to have article preview on social media and this is failing just because of the arrangement. Any help would be appreciated.
well, I don't think it is because of the arrangement.
As far as I remember FB doesn't execute javascript code in the provided URL.
Facebook’s scraper just looks at the HTML code of your page; it’s not a full-fledged “browser” that would execute any client site code.
with that being said.whatever meta tags you need there it can't be done via JS on the client-side. it must be server-side rendered.
I am not sure what technology you are using to serve this app, but I can assume it is a react app. and it would be easy to handle this via a small express server. that serves the app with the right meta tags in place even.

SEO and anchor link "onclick"

I'm working on a page where links are added with JavaScript. This is according to my knowledge not optimal when it comes to SEO.
Example added by DOM-manipulation/jQuery:
Go To Page
So I have added a correct href attribute and creates the tag server side, like this:
Go To Page
Will google and other search engines accept the href even though the navigation is done by the JavaScript function, or will anchor tag be "down-prioritized" due to containing a link that cant be accessed? The link itself will lead to the same page as the JavaScript event. However it is not actually used in this case.
Crawlers will see the href links and try to use them. Google crawlers are capable of using javascript to follow links as per the blog here with few gotchas. http://www.searchenginepeople.com/blog/onclick.html. If you want your link to crawled, then there are other alternatives as google will follow text urls on page source.

where to include google analytics tracking code

I want to use google analytics in my website, but I don't understand where I have to put the tracking code. I built my web page using Yii and php, and I am also using templates. I read the google page about the tracking code, and it says:
If your website uses templates to generate pages, enter it just before
the closing tag in the file that contains the the section.
I tried to put the tracking code before </head>, but it didn't work. Please, someone could help me? I don't understand what google means.
Thanks.
You should be placing it within your views, preferably before the </head> tag. When you say it didn't work, what is it doing? Did it throw an error - if so, what?

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

asp.net web stats - google analytics

i want to add tracking to my website. I saw google analytics which seems to track what i need.
So do i stick the google analytics snippet in each page, in a master page, just in my default page? what is the best practice here to get the best metrics.
The google analytics code snippet has to be on every page you want to track.
Easiest is to put the code into the master page(s) if you use them.
Otherwise put it on every page, or put it into a user control which you can include on the relevant pages or include it using a server-side include, e.g:
<!-- #include file="file_containing_google_analytics_code.js" -->
It depends on the structure of your site. If you have a small number of Master Pages it makes sense in there, or you could put some code to emit it in a base class that you inherit all your pages (or master pages) from, or if you have a standard footer control that you use on all pages you can put it in there.
I generally wrap it in a Placeholder in ASP.Net and have some code the switches it on/off from a web.config setting so it doesn't appear when the site is running in test/UAT/dev machines.
We use Google Analytics, and have incorporated this into our base page - although our first implementation was done with an HttpModule.
I like the base page approach, because it is a common area for some like-minded tasks. It additionally moves the viewstate to the bottom of the form, removes whitespace, etc.
You should take a look here : http://blog.sb2.fr/post/2008/12/21/Google-Analytics-WebControl-for-ASPNET.aspx

Resources