I have my website hosted on github pages and I wanted to add Google Analytics to count views on it.
I created a Google Analytics account, created a new UA property and added full path to my website ( username.github.io/reponame/ ).
Then I added global site tag to head of my index.html ...
I waited for some time but still I can see 0 active viewers in analytics page even if I active on my website using 2 devices...
Since I found various answers about setting up analytics with Jekyll, I added Cayman theme, edited _config.yml, added _includes and did whatever said in that blog but still it didn't work ( I am not used to github actually )... So, I removed whatever changes I made for that Jekyll thing and now my repository consists of only stuff which I added in the beginning.
Why is it not working on my website ? Did I go wrong somewhere ?
How do I add Google Analytics if my repository currently consists of only index.html, css files and JS files ?
Make sure to have included {% include analytics.html %} in your website somewhere. The best practice is to put it into the head of your HTML.
Inspect your webpage, for instance with Chrome tools, to check that the script containing your Analytics ID is indeed loaded.
You should see something like:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-ZKGE3RWEMU"></script>
I have a website where I want to track opening of my emails. I've added google analytics image like this:
<img src="https://www.google-analytics.com/collect?v=1&tid=UA-XXXXXXXXX-X&cid={{analyticsCID}}&t=event&ec=email_open&ea=come_back_3&ni=1"/>
And I'm getting double email open event on first open of the letter. If I open email on mobile, only 1 event fired.
Is there any solution for this? Is it because of google proxy for images? Can I disable it to get CORRECT analytics data?
Likely because of email providers caching the image through a proxy: https://developers.google.com/analytics/devguides/collection/protocol/v1/email#gmail-image-proxy
Most hosts come with softwares or google analytics which allows you to know how a person got to your site, for example: a link on yelp.com or a facebook.com page link.
But it is impossible for the software to know what method of marketing got a person to visit your site if he directly typed the url (those analytic softwares show them as "direct url").
I need a creative idea where I can refine this broad term "direct url".
One way would be to use flyers with QR codes (links to the website) but instead of the website itself I direct them to clickemart.ca/flyer1_referrer which in turn sends him to the website clickemart.ca but a different flyer distributed to a different location would have a QR code which can be scanned to direct a mobile user to clickemart.ca/flyer2_referrer
So my question is, is this possible, will I be able to figure out which flyer 1 or 2 was more effective based on visits to the redirect urls? If it is possible can you give me a brief idea on how to implement it?
I know a lot of you will say add a form field with "source of referrer" on the site but from my experience this is never filled or filled with incorrect values (typically the closest to the mouse pointer or the top most option or "other" - you get it, something useless).
Any help or guidance is really appreciated!
Solved it here is how:
Connect your site to Google Analytics (www.google.ca/analytics)
Create a campaign URL (support.google.com/analytics/answer/1033867?hl=en)
OPTIONAL: shorten the URL (www.bitly.com)
Create a QR code to the URL (www.qrstuff.com/)
Scan the QR code and watch it appear as a campaign referral under Google Analytics
Here is an explanation to the different steps:
Once you create an account on Google Analytics, you can connect the site by copying a PHP script or a JavaScript onto every page or in my case (magento) the user code can simply be connected through the configuration settings
The campaign URL adds information to the URL link of your website just like the current link on stackoverflow.com variables such as noredirect="..." contains info for your server to process, so using the campaign URL could be used as a tag to determine the source of the referral
Shortening the URL is recommended because the QR code becomes less dense and this in turn reduces the chance of error while scanning the code, the shortened URL links directly to the campaign URL link you provided so it is a seamless process
QRStuff is a good place to download the QR code image at a high resolution
So when you scan this is what happens:
CODE SCANNED >> PHONE COMMAND TO GO TO SHORTENED URL LINK >> REDIRECT TO CAMPAIGN URL >> GOOGLE ANALYTICS RECEIVES INFO ABOUT CAMPAIGN REFERRAL >> YOU CAN SEE IT BY LOGIN INTO GOOGLE ANALYTICS
Could be a simple question but I am full of doubts right now about adding Google Analytics Tracking ID to GitHub page.
I am using GitHub automatic page generator to create my GitHub page but it asks for "Google Analytics Tracking ID". I tried to sign up with Google Analytics but there on it asks for website URL.
Now what I am supposed to do?
One more ques: can we add Google Analytics Tracking ID later on after GitHub Page has been created?
Update: Added steps descriptions for others
Solved it:
had to include username.github.io (link that I want to track) in Google Analytics website section.
you can check GitHub help page here
After that I was provided with an Tracker ID.
Note: You can easily change or add more websites on Google Analytics page from your Google Analytics admin panel.
Update 2: - Adding Google Analytics Tracking ID to Already created Github pages (As requested by #avi-aryan )
Browse to your github pages branch - which would be something like - ( https://github.com/YourUserName/YourRepository/tree/gh-pages )
Then edit index.html from listed files
Now in within HEAD tag of index.html - paste your Google Analytics Tracking ID Script ( if have already signed up for Google analytics then you can browse it under admin and then tracking info tab )
For anyone interested, if you are using Jekyll with GitHub pages, I just wrote a post showing how to correctly add Google Analytics Tracking ID to Jekyll.
You will find your Universal Analytics tracking code under Admin > Property > Tracking Info > Tracking Code.
Create a new file called analytics.html in the _includes folder found in your Jekyll website’s directory.
Add Google Analytics Tracking ID code to analytics.html.
Finally, open _layouts/head.html, and add {% include analytics.html %} just before the end </head> tag. Google recommends this placement to track all of the pages on your website correctly.
If you are using the minima template provide by Jekyll then -
Add google_analytics: UA-xxxxxxxx-x to your _config.yml
Create a file _includes/google-analytics.html and add the google analytics js code in it.
Replace
ga('create', 'UA-xxxxxxxx-x', 'auto');
with
ga('create', '{{ site.google_analytics }}', 'auto');
and you are set!
The google analytics code will now display if your site is built in production environment. For reference see the template's source code here - https://github.com/jekyll/minima
You can follow the same approach if you are using a different template by referencing the template's source code and replacing the corresponding files.
Is better to use GA-Beacon for that. GA-Beacon can track all your GitHub repo, even if the visited link isn't an html document.
Please check: https://github.com/igrigorik/ga-beacon
Adding analytics via _config.yml.
All GitHub themes (supported themes) natively support google analytics.
You just have to provide a tracking code (UA-XXXXXXXXX-X).
Google analytics comes in two flavours - Google analytics 4 (GA4), and Universal analytics. You will have to use the latter for this. GA4 will not work #.
Create a new Universal google analytics property (and not GA4 property). By default the tracking property you create will be of type GA4. You will have to select "Create a Universal Analytics property" for the property to be universal.
Once a GA4 property is created it cannot be converted to Universal property. You can only do this while creating a new property.
1.1 Turn Universal analytics on in the advanced options.
1.2 Configure Universal analytics options.
1.3 Copy the tracking ID for this newly created property.
Add this tracking ID to your gh-pages sites's _config.yml.
google_analytics: UA-XXXXXXXXX-X
The following is from modernist's readme - the theme I was using for my site.
Commit and Push the changes to github, and after few minutes navigate to your site's URL.
Verify that everything went fine.
If you search the source code now for the tracing ID, you will be able to find it.
Google analytics dashboard too will start showing activity.
The above steps show how to add google analytics to an existing gh-pages site. You can use the same code while creating a new gh-pages site too. Although it seems automatic page generator no longer exists - Can't locate "automatic page generator" button in Github
# Maybe there is a way to use GA4 natively by configuring _config.yml. I wasn't able to do that, and had to resort to universal analytics.
Reference(s)
https://www.analyticsmania.com/post/downgrade-from-google-analytics-4-to-universal-analytics/
You can add Google Analytics to a Jekyll site the same way you would any other site.
First, after setting up your Google Analytics account, navigate to the admin tab.
Next, under the accounts panel, on the left, click: Create New Account.
In Google Analytics, an account represents a set of pages that you would like to track. Set up the website's account as desired.
After your account has been created you will be sent to a page which tells you your Tracking ID and has a JavaScript snippet for you to put on the pages you would like to track. Simply put this snippet in all the pages you would like to track. Or, if you use a default layout put this snippet somewhere in it.
By the way, since you are hosting on GitHub Pages you don't need Google Analytics unless you want very detailed analytics. If all you care about is page views GitHub has this.
I use the README.md file as a source for my GitHub personal page. I also use one of the GitHub supported themes 'cayman'. No more files is required in the repository apart from _config.yml (unless you want to modify your supported theme).
To add Google Analytics, I just followed the advice in the 'cayman' repository (https://github.com/pages-themes/cayman):
Cayman will respect the following variables, if set in your site's _config.yml:
google_analytics: [Your Google Analytics tracking ID]
Full stop! Anything else! Everything works on the side of Google Analytics!
It may be a viable option for those who look for a quick set up of GitHub Pages with Google Analytics.
If you're using an automatically generated github page from your github README.md I found this to be the easiest way:
Just edit your _config.yml to look like this (with your own google analytics UA id):
theme: jekyll-theme-cayman
title: My Site
description: My site description
url: https://example.com
author: MyName
plugins:
- jekyll-seo-tag
google_analytics: UA-xxx
Then add a new file to your repository root named Gemfile with this content:
source "https://rubygems.org”
gem "github-pages", group: :jekyll_plugins
gem 'jekyll-seo-tag'
Then wait a bit and refresh your github page and show page source code. Verify that the SEO plugin has inserted your analytics java script.
More info here: https://github.com/jekyll/jekyll-seo-tag
From the installation instruction, I didn't have to add the {% seo %} in the html, luckily, because I have no html. Github seems to have thought of that.
With me, I was unable to configure Google Analytics 4 (prev Web+App) via adding google_analytics: UA-xxxxxxxx-x to your _config.yml as mentioned previously in one of the answers.
So I had to put the js recommended by the Google Analytics in the .md file.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXXX');
</script>
Anything you put in the script tag in .md will not be rendered.
Include a Global site tag in the html output <head>
Once you setup a Google Analytics account, detailed instructions are included under the "Data Streams" tab- select your data source, and then "Tagging instructions" for Global site tag(gtag.js)
Global site tag
the script will look something like this (with id replaced by XXXXXXXXXXX in my example):
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=XXXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'XXXXXXXXXXX');
</script>
Save the html script within a file in your Project directory (e.g. as "GA_script.html")
Add html file to the header
in the Rmarkdown YAML, add the reference to your specific script (see ref here):
output:
html_document:
includes:
in_header: GA_script.html
This appears to be a bug in Jekyll Minima. See these GitHub issues for reference:
feat: Support GA4 - Google Analytics 4 properties
Google Analytics data not received
Set google_analytics at _config.yml with tracing-id started with UA- rather than G-,tracing-id like G-xxxx is of Google Analytics 4. and Jekyll does not support Google Analytics 4.
Use
google_analytics: UA-xxxxxx-x
Do not use
google_analytics: G-xxxxxx
However,Google Analytics(Universal Analytics) is no longer supported by Google until 2023.7.1.
I'm having problem publishing actions (using OpenGraph) with tagged Google Places instead of Facebook Place. It should be straight forward according to the following document:
https://developers.facebook.com/docs/opengraph/location_tagging/#third_party
But every time I try to publish an action with place=http://GOOGLE_PLACE_URL I get the following error message:
The action you're trying to publish is invalid because the specified place 'http://GOOGLE_PLACE_URL' is invalid.
I've tried to put Google Maps, Google Places and Google+ Local URLs but all with the same problem.
Note: I could successfully publish actions when I set "place=Facebook_Place_ID".
Any help or hint is greatly appreciated!
Thank you,
I don't think Google's place pages have the markup necessary to support Open Graph
From the documentation:
Publishing actions with 3rd party places is similar to the location
tagging example above, except that you will pass in the url to another
site's place object.
The foursquare example in the documentation is defined as a place, as well as having the metadata foursquare uses:
https://foursquare.com/v/eataly/4c5ef77bfff99c74eda954d3
See Facebook's Debug Tool for that URL at https://developers.facebook.com/tools/debug/og/object?q=https%3A%2F%2Ffoursquare.com%2Fv%2Feataly%2F4c5ef77bfff99c74eda954d3 - it clearly shows that foursquare's place is defined as og:type playfoursquare:venue and has location data available for Facebook - i suspect Google does not have this on their place pages