Social action tracking in Google Analytics - google-analytics

I want to track social actions in Google Analytics. I know I must use the following snippet, placed within the current analytics tag:
ga('send', {
'hitType': 'social',
'socialNetwork': 'facebook',
'socialAction': 'like',
'socialTarget': 'http://mycoolpage.com',
'page': '/my-new-page'
});
My question is this: Where do I place the snippet within the tag?
Correct placement might be after _gaq.push(['_trackPageview']); and before (function() but I am not certain.
Also, will I need to repeat this snippet per social network?

This code is only for the new GA API version (Universal Analytics).
You should use this documentation:
https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSocial
The correct placement of this code is with trigger of each social network.
Here is an example for Facebook and Twitter:
http://analytics-api-samples.googlecode.com/svn/trunk/src/tracking/javascript/v5/social/facebook_js_async.html
And as the example, there is a code for each social network.

Related

Google Analytics Custom Dimensions Not Tracking

I want to split test different layouts on my site, and to track this I want to use a Custom Dimension which is named Split and equal to 1 or 2.
I've configured the Custom Dimension in Google Analytics and added the code like this:
// Google Analytics
gtag('config', 'UA-70465331-1'), {
'custom_map': {'dimension3': 'Split'}
});
// Sends the custom dimension to Google Analytics.
gtag('event', 'SplitTest', {'Split': "2"});
However, when using the Google Tag Assistant, the Custom Dimension isn't appearing under Events.
The live page is: https://www.travelden.co.uk/mindblowing-new-hotels-in-the-maldives
Can anyone see where the error is?
Much appreciated!
It is coming through:
You need to be careful to set the event to "non-interaction",
I would also suggest you to not send an event if you don't need it...so something like this:
gtag('config', ''UA-70465331-1', { 'dimension3': '2' });
Doing it this way the dimension is applied when the page is loaded, which is really what you're testing, the layout.

How to track Outbound links without breaking links to affiliate templates with no GA code

I have hundreds of affiliate templates and when I change the GA file, it applies to all the templates.
If I want to track outbound links, I have no choice but to put the GA javascript code in all my templates, as well as the outbound links.
Javascript is this:
<script>
var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
</script>
My understanding is that the outbound link (like below) will break if the GA tracking code is not included on a template (i.e. UA-#######-#) :
Track this link
Some of the affiliates do not have or want their GA code (i.e. UA-#######-#) included in the template.
Is there a way to set up outbound tracking without breaking the links on templates without GA code?
Thank you.
Yes, you can create a Measurement Protocol hit to send the data without using GA code.
The Google Analytics Measurement Protocol allows developers to make HTTP requests to send raw user interaction data directly to Google Analytics servers
The hit looks something like this
www.google-analytics.com/collect?v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fhome
Where tid =Tracking ID / Property ID.
Learn more about the measurement protocol here: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide

How to send traidtional GA event in GTM's custom HTML tag

I'm using GTM in my company's online shop, and I installed some other tag via GTM's custom HTML tag, like this:
<script>
//some JS code...
var customParam=[{"key":"value"}];
var jsElm=document.createElement("script");
jsElm.type="text/javascript";
jsElm.async=true;
jsElm.src="https://some_tags.com/tag.js?s=CV";
document.body.appendChild(jsElm);
if(today < some date)
{
SEND GA EVENT here.....
}
</script>
The traditional GA event script
ga('send', 'event', 'XXX', 'pageview', 'some description', 1);
isn't working anymore here.
How do I did this ?
And I heard someone said that I should put data into DataLayer and do some bla bla bla... but I was understanding that too few to try. Is that a right way ?
I am going to answer with another question. Why are you sending events through HTML tags instead of Google Analytics Tag that are build just for that purpose?
I ll work with the assumption that you are new with this tool but the idea is that GTM replaces all old GA code on site.
Just create a new Tag and select 'Universal Analytics' and after that you can choose which kind of information you want on Google Analytics.
Its pretty self explanatory as a tool so i strongly recommend you to forget about those old GA codes and work with what you got.
In addition to this have in mind that you can use custom javascript variables to scrap DOM values in case you need to.
Here is our guru Simo Ahava: https://www.simoahava.com/
If you need anything else just ask.

E-Commerce tracking with Google Tag Manager and DataLayer

UPDATE: I've disabled the enhanced ecommerce from the tag
configuration. The problem I see is that my datalayer is correctly
created, all the rules fire, in GA I can see the event Purchase but I
don't see the information related to the order value and products
ordered. Am I missing something that should map my custom variables to
the GA ones?
Hi all,
our GA + GTM worked fine since the end of May due to a problem with the google tag manager account we've lost all the configuration in the GTM. Now I'm trying to reconfigure it considering that 1) This is my really first experience with these tools 2) I don't have documentation on how the GTM was configured.
What I'm doing is to reverse engineering the GTM configuration starting from what I can see in the HTML and in the Google Analytics reports.
One of the reports that stopped working is the one related to E-commerce.
From the HTML I see the following instruction:
dataLayer.push({
"event":"Purchase",
"customerEmail":"alexio#mysite.com",
"orderNumber":"OIT00019938",
"orderRevenue":"31,97",
"orderShippingValue":"4,92",
"orderDiscountValue":"0,00",
"orderShippingCountry":"IT",
"orderShippingZip":"20141",
"orderInvoiceCountry":"IT",
"orderInvoiceZip":"20141",
"orderPaymentMethod":"cash_on_delivery",
"orderShippingMethod":"standard",
"orderCouponLabel":"",
"orderAffiliate":"(not set)",
"items":
[{"sku":"00080988",
"fullSku":"00080988-IT_48-ffffff",
"orderNumber":"OIT00019938",
"itemBrand":"C'N'C COSTUME NATIONAL Long-sleeve-shirts",
"itemMacro":"camicie",
"itemMicro":"camicie maniche lunghe",
"itemGender":"man",
"itemSeason":"spring-summer",
"itemSize":"IT_48",
"itemColor":"bianco",
"itemPrice":"31,97","itemQuantity":"1"}]});
I've tried to configure the GTM with differente ways but none of them worked. I have a rule that fires whenever an event "Purchase" happens (and I see that it really fires with the GTM debug view) and I've created different tags playing with type (event, page view), enabling Enable Enhanced Ecommerce Features and DataLayer etc. Unfortunately it never worked so far. Since I'm using a lot of custom variables in the datalayer I think that somewhere in the GTM I should map them with the ones used by Google Analytics, but, if true, I don't know where...
Since everything worked fine until the end of May and that the only thing that changed is the suddenly disappear of GTM, I assume that configuring in the right way the GTM everything should start work again.
Any idea?
Alexio
You either need to use the defined GA naming convention in you dataLayer object then GTM will pass these automatically to a GA tag (Universal GA) or you need to trigger a JS tag that will push the values into the dataLayer in the correct format. You can get the values using dataLayer macros and use them in your JS.
Once done, you can push an event into the dataLayer and use that as a rule to file the GA tag once the values are all there.
https://support.google.com/tagmanager/answer/3002596?hl=en
If you are going to use the enhanced ecommerce features in Google Analytics you need to add the ec.js library. It should be placed before the GTM container. Also, in your Google Analytics property a view for Enhanced Ecommerce needs to be created. My advice, if you are learning from scratch go with enhanced ecommerce enabled. More difficult to implement but provides a lot more data gathering options.
Here is the Enhanced E-commerce data layer for purchase event -:
<script type="text/javascript">
//<![CDATA[
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': '100000191', // Transaction ID. Required for purchases and refunds.
'affiliation': '',
'revenue': '199.9900', // Total transaction value (incl. tax and shipping)
'tax': '15.2400',
'shipping': '0.0000',
'coupon': ''
},
'products': [
{
'name': 'AT&T 8525 PDA', // Name or ID is required.
'id': '8525PDA',
'price': '184.7500',
'brand': 'At&t',
'category': 'Cell Phones',
'quantity': 1.0000 }]
}
}
});
//]]>
</script>

Several Google Analytics tag on a same page

Here is my problem: our client has 2 websites, A and B.
They have 1 google analytics account with 2 properties :
Account: CLIENTNAME
Properties :
SITEA with ID UA-XXXXXX-1
SITEB with ID UA-XXXXXX-2
Additionally, we also have 1 analytic account with 1 property:
Account: OURNAME
Property :
SITECLIENT with ID UA-111111-1
We would like to put the client's google analytics tags on each website along with our tags (OURNAME), so that each site would have two codes.
After some searches on the support site, I found that :
"Installing multiple instances of the Google Analytics Tracking code on a single web page is not a supported implementation"
But, after searching again and trying (yes I know it's bad...), I found that it works with code like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', ACCOUNT_#1_ID],
['_setAllowLinker', true],
['_setAllowHash', false],
['_trackPageview'],
['b._setAccount', ' ACCOUNT_#2_ID '],
['b._setAllowLinker', true],
['b._setAllowHash', false],
['b._trackPageview']
(nothing for first tag, b for second, etc...).
So, I have few questions about theses tags because the tracking seems to be correct:
can we skip a letter on the tracking? For example, we have 3 accounts, and we want 3 codes, a,b and d (but not c)
can we add 2 or more tracking for one page with Google Tag Manager? (for exemple with 2 GA's type tag with the rules "for all pages")
can I have both 1 google analytics tags and 1 GTM tag on the same page? (Not really usefull, but is it possible?)
yes could have the more that one GA tracking code on the page of the domain.
Example for 2 GA code on the same page:
<scirpt> (function(i,s,o,g,r,a,m)......)
ga('create', 'UA-XXXXX-Y', 'auto');
ga('create', 'UA-XXXXX-Z', 'auto', 'clientTracker');
ga('send', 'pageview');
ga('clientTracker.send', 'pageview');
</script>
more: https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers#working_with_multiple_trackers
yes, the letters/names are up to you... you can prefix accounts with whatever you wish. They are there simply for individual addressing.
yes, though keep in mind that order in which they load can not be guaranteed. You don't need to reload the actual ga.js for each one, a single instance is fine.
yes, that's not an issue.
As a side note, if you are collecting data for more from more than one hostname into a single web property, you will need to set the domainname in your GA object.

Resources