I am currently working on a site that uses hashsignaling for page loads. This means there are very few page "loads", but rather lots of ajax content changes and template manipulation.
My question is: how do I track this using Google Analytics? Is there a way I can trigger a GA call in my code that captures the entire url including the hash and any other parameters?
It depends how you want to represent your site activity in GA, but you could decide what you want to qualify as a "pageview" and call the _trackPageview() method with URL included as a parameter any time that activity happens:
_gaq.push(['_trackPageview', 'YOUR URL HERE']);
Hashsignaling fire a hashsignal.hashchange event on window object when a page is updated :
$(window).trigger('hashsignal.hashchange', [subhash]);
So you can bind a Google Analytics tracking call to this event with something like :
$(window).on('hashsignal.hashchange', function(event, subhash){
_gaq.push(['_trackPageview', subhash]);
});
Related
I have a search bar on my website and there is 2 ways of getting search results
When they type keyword in the search bar and they press enter button. They will be redirected to the page with the url address with query. For example: /?s=test - I have this in GA but...
In the same time when user is typing keyword he gets search results in real-time via AJAX under search bar in the form of a list . When
the displayed result is clicked user will be redirected straight to the result page
https://imgur.com/L7aqOfM
And I want to know how to track this second option because Google Analytics is not able to collect this type of searching via AJAX.
Google Tag Manager and VirtualPageView? How to do it guys cuz Im a newbie
In your AJAX's success callback, you can fire a virtual pageview or an event with Google Analytics. Since you have used Google tag manager, you can push a dataLayer event
success: function(data) {
dataLayer.push({
'event': 'searchEvent',
'keyword': 'keyword'
})
.........
Then you can use this in GTM to create a trigger and fire an event or a virtual pageview. If you are using Virtual pageview, override your location parameter with something like /?s={{keyword}}, where {{keyword}} is a dataLayer variable and it would work
When using the Google Tag Manager, is it possible to track some things the old way in addition to using the GTM?
For example, I use GTM in order to fire a page view.
However, I want to fire another page view, when a user clicks a button, also known as a virtual page view.
The button in question doesn't have an ID and I don't trust the othet agency, which handles these buttons to consistently keep the same IDs for these elements. So I would rather have them be responsible for these types of page views.
The code for the virtual page view would look something like that:
ga('send', {
hitType: 'pageview',
page: 'button2'
});
Since the tracker is already initialized by GTM, I would only have this code outside GTM.
Would this work if all other google analytics related things run over gtm and where should I put this code in this case? Somewhere after the GTM code on the page I'd imagine?
Google Tag Manager (GTM) by default uses a random name for each tracker, generated for each Universal Analytics tag. There is a possibility to use fixed name for trackers, which is highly discouraged. This means, that you might have difficulties to identify the proper tracker to use, when sending your additional pageview data.
There are however other methods to send virtual pageviews using GTM, where you can benefit from your existing Analytics settings, defined in Google Tag Manager. (Preferably by using Google Analyitcs Settings variable.)
As far as I understand, you have control over the code, to run some JavaScript on the relevant click event.
So instead of directly invoking the ga object, you can send the desired data to GTM, with a call like this:
dataLayer.push({
event : 'virtualPageView',
virtualPagePath : 'button2'
});
Obviously, there are a couple of things you need to set up in GTM, which will be able to act on this event, and send the pageview to Google Analytics.
Create a variable that points to virtualPagePath dataLayer variable, so the newly pushed value could be reused
Create a custom event trigger, that can be used with one or more tags. The event name should match your given event name, virtualPageView in my example.
You need an Universal Analytics tag, which will send the pageview. This tag should be fired by your new custom event trigger, and should have an extra setting compared to your regular pageview tag. Namely, page variable within the Fields to set block should point to the newly created dataLayer variable, that contains your virtual page path.
This way, Google Tag Manager will take care of creating the tracker for you, sending the hit to Google Analytics, and using the virtual page path variable provided by you, instead of the URL in the browser address bar.
I've deployed a customer service JS code (Tidio) <script>http://code.tidio.io/ab/abcd.js</script> via GTM custom HTML tag.
I want to pass information to GA and track event clicks on the chat custom code i.e. when a person clicks on the chat button, correlate that to the number of sales in GA.
I'm struggling how to set up the trigger to fire the event to send to GA.
Since the JS code loads custom HTML, is there a way to get it to track when the script is clicked on somehow so I know it's been used and send this info to GA?
Any ideas?
I basically want to know: "Did Customer service aid the user to make a purchase".
Thanks!
Nitesh
You can use Tidio API to trigger a dataLayer event when the Tidio window was opened: "To be able to use the API, you just need to insert Tidio Chat code into your website. You don't need any external libraries."
So for example to fire GTM dataLayer event when the Tidio window shows you just need to include this code on your page:
tidioChatApi.on('popUpShow', function(){
// Your dataLayer event code
dataLayer.push({
'event': 'yourCustomEvent'
});
});
Alternatively you can use "messageFromOperator" or "messageFromVisitor" events to only track visitors that interacted with an operator.
Current tracking of the checkout funnels is done through Pageview using virtual pageviews via
_gaq.push(['_trackPageview', '/checkout/login']);
_gaq.push(['_trackPageview', '/checkout/address']);
which has been hardcode into the webpage.
We are now updating to UA through GTM with enhanced Eccomerce. I would still like to continue to track the checkout funnels with the current method while implementing the Enhanced Eccomerce step 1 / step 2 codes.
My question is If i can fire a datalayer push to overwrite the url which the {{url path}} macro in GTM will track so instead of using /pws/secure/CheckOut.ice?&checkout=true&secure_from=checkout as a goal URL I can use the virtual urls "/checkout/login" and "/checkout/address".
*for some reason only the login and address pages of the checkout are on the same URL.
Would something like this work
dataLayer.push({
'url path':'/blah/blah'
});
If not is there a way I can use the lookup macros in GTM to do Document Path = {{Virtual URL}} (IF it not empty) or {{url path}}. Basically I dont want to have to create multiple tracking codes for each of the checkout funnels with the virtualURL in the Document path. Not to mention how I would get GTM to recongise that one second the URL is a login page and the next it an address page.
Any ideas would be really appreciated
That's correct, you can use the data layer to push your own URL path to Google Tag manager. First you need to set the path in the data layer as you mentioned.
dataLayer.push({
'url':'/foo/bar'
});
Then, in Google Tag Manager, you can do the following :
Go to the tag that handles your GA "page views"
In "More settings", look for "Fields to set"
In the field name, pick {{url}}
For the value, you should create a macro that gets your "url" from the data layer:
As I understand, you can use basic virtual page view behavior by creating GA tag with rewrited url. This tag will be fired, when two events will happen - one for every page view that you want to track. You will only need to add two pushes to dataLayer for events - event itself and dataLayer veritable with url. For example, it can be something like that: dataLayer.push ({'event':'first-event','custom-url':'/my/custom/url1'}).
In GTM you should create a macro, that gets the value of 'custom-url' dataLayer veritable, and use it to rewrite url in your GA tag.
I have a site using Google Analytics. On one page clicking a button changes everything about the page. However, it does not change the page's URL. I would like to track it as a separate page in Google Analytics. So I would assume I would trackPageview("/new") (or really _gaq.push(['_trackPageview',"/new");), however before I implement this I want to make sure events and such are not counted twice.
That is to say, if I were to load the page / (and have the default trackPageview call occur) then call trackPageview("/new") and finally call trackEvent("Test",…) would the Test event be reflected on the /, /new or both?
In your example, 'Test' would be reflected on '/' because that is the window.location.pathname.
There is an undocumented GA function called _set where you can override the variable like the code below:
_gaq.push(['_set','page','/new']);
_gaq.push(['_trackPageview']);
$("#submit-button).click(function () {
_gaq.push(['_trackevent']); // tracks to '/new'
});
After doing some testing it looks as though the Test event shows up on / regardless of pushing a new pageview.