I have a HTML single page application (it is a single HTML file, where i show page navigation as hiding and showing multiple div elements, so page navigations are not actual page loads, just switching divs)
I have created some 5 custom dimensions of "Session" scope, so they will be always present and tracked with some value.
However, I need a 6th dimension which will be populated only upon doing a particular operation such as clicking a button. So i have created 6th dimension and set its scope as "Hit". In the HTML application, as soon as the user clicks the button, i set the value for that dimension and do a send for that request (it is actually an 'ec' tracking), i can see that the 6th dimension value is also set.
The problem is, After this tracking, if i track any other event tracking or page view tracking, the same value is being passed for the cd6 parameter.
Could you please let me know if i am doing anything wrong here?
If you set a custom dimension via set it will apply to all hits that follow:
ga('set', 'dimension1', 'mydata');
will attach the dimension to all following tracking calls (especially bad on a single page app).
You can pass a JSON object as second parameter to the ga("send") call instead and set the dimension there:
ga('send', {
'dimension1': 'mydata',
});
That way the dimension is only sent with that pageview, later interactions will not be affected.
Related
On a single page app, my problem is I'm subscribing to the hashchange event to render the content (create and destroy widgets that represent my pages), but the function only gets fired when the hash actually changes, such as when the browser back and forward buttons are clicked.
My main javascript file that always gets loaded on first time and also on refresh contain the following
topic.subscribe("/dojo/hashchange", function(newhash){
//set content based on hash
});
When refresh is clicked, it doesn't get fired and I'm left with a blank page (all my logic to render the page lies inside the anonymous function for that topic I subscribed to)
your subscribe isn't being called on a refresh as the hash didn't actually change. you're subscribing to hash changes, changes that happen after the page as loaded.
using this subscribe method things can get out of hand quickly. you may want to look at using route. some links -
https://developer.mozilla.org/en-US/docs/Web/Events/hashchange
https://dojotoolkit.org/documentation/tutorials/1.9/hash/
https://dojotoolkit.org/reference-guide/1.10/dojo/router.html
https://www.sitepen.com/blog/2014/06/18/dojo-faq-does-dojo-have-routing-like-backbone-and-embe/
First off, I'm not sure if the title I came up accurately describes what I'm trying to do.
I have a table of tasks, with an assign action for each. Basically, in normal cases, the user would click the link, in which a call would be made to assign them to the task and then redirect them to the task details page. That can be done with a simple ng-click to call the assign function, and then using the $location.path() function for the redirect on success. Doing it this way, there is no need for the href attribute.
But, this also takes away the ability to open the link in a new tab by "middle clicking" or "ctrl + clicking" because there's no href value. For example, some users would typically assign themselves to multiple tasks at a time. On a typical site, it would just be a regular link that does some processing, finishes, and then loads the page they were intending to go to. So they could get away with opening multiple tabs, because all of them would process the request and then return the page as the response.
So I've added an ng-href attribute since I have an ID in there, and it kind of works. Middle clicking (or ctrl + clicking) will still call the ng-click function, and the ng-href will let the new tab open. But now the issue I have is that since the assign function call is async, sometimes the tab will load up not showing that they're assigned, since the page loaded before the assignment was processed.
Does anyone have an idea of what I can do to make this more reliable and accurate?
Can you not just use
$window.open(LOCATION);
instead of $location.path() ?
I have a site where I track click outs, one user may click out several times so if I have 100 users I may have 300 click out events. This is ok for a rough guide but ideally I would like to know how many users have clicked out so 100 users 85 users clicked out.
I could write some js on my site to handle this store in a cookie but I was wondering if there is anything in ga.js that will allow me to fire an event once per session.
You can use Custom Dimensions to scope things to the session (or even the user). Create a dimension in the Google Analytics admin tab under Property within Custom Definitions.
Set the scope to session, then copy the ga('set', 'dimension1', 'Description Here'); and paste it before sending the event (obviously, change "Description Here" to your own explanation. Also, make sure 'dimension1' matches the index it gives you.
Custom dimensions (and metrics) are tied to hit types, so simply setting them does nothing until a hit type is sent- so either a pageview or an event.
Once you've created the dimension, you can use it for anything you would a standard dimension in reporting- including segments and custom reports.
Hope that helps!
This question is based on a misconception, please see this question instead.
Subject
I am trying to create some context menu options via a Google Chrome extension that allow you to modify the contents of editable fields on certain web pages. My extension works perfectly on StackOverflow, where the DOM is nice and simple, but Youtube has been giving me trouble for some time now.
Problem
Many of the editable fields on Youtube are hidden in Iframes, so if I try to access document.activeElementfrom the top frame, I get the Iframe itself.
I am trying to get around this by injecting chrome.runtime.onMessage() listeners into every page.
Then, I can presumably compare the value returned by info.frameURL in the chrome.contextMenus.onClicked() event listener in the event page, with window.location.href in the content scripts to see if the message is addressing the correct frame or not. (See this question)
The problem is that the value returned by info.frameURL does not seem to be consistent.
For example, if you go to the home page and use the main search box as the test element, sometimes the value is simply, www.youtube.com...., but other times it is plus.google.com..... or apis.google.com..... or accounts.google.com... and I am not sure why this is.
Can someone explain why the value returned by the info.frameUrl would not remain constant each time you click the same frame?
I am working on Google Universal Analytics and I see that our Dimensions are being captured by Google about 60% of the time. I see that the Dimensions are being set and I have verified in the Network that the Dimension is being sent to Google. Someone suggested that I look into setting {'nonInteract': 1}. I am confused where I should set the nonInteract flag to (ie - should I be setting this to GA() when I am setting the Dimension, or should it be set to the GA() when I am sending the event?
I have tried the following below, but I am confused with the result. In the Network tab, I do see that the Dimension is being sent to Google. When I inspect the Console with the GUA Debugger Tool, trying to set the dimension results in a Command ignored. Unknown target: undefined.
//Two variations I have tried when implementing the `nonInteraction` flag:
ga(u.name + '.send', 'event', category, action, label, {'nonInteraction': 1});
ga('set', 'dimension' + cvSlot, label, {'nonInteraction': 1});
Screenshot of console when cannot set Dimension15:
Source of where I got the nonInteract code:
https://developers.google.com/analytics/devguides/collection/analyticsjs/events
My question is how do I attach the nonInteraction flag to my Dimension?
Setting a non-interaction flag on a set call for a dimension would be pointless since the set call is not an interaction in the first place. An Interaction is a hit that sends information to the Google servers (send pageview, event, timing, ecommerce item and transactions). You need to have an interaction hit to send a custom dimension. The only hit type you can set to non-interactive is event. However a set call after an event is pointless since the hit has already been sent and the dimension cannot be added to the hit (and it might even be harmful, since a set call attaches the dimension to all subsequent hits, interactive or not).
So the best way would be to use a non-interaction event and attach the dimension to it via it's configuration object.
ga('send', 'event', 'category', 'action', {
'nonInteraction': 1}
'dimension': myvalue
});
Non-Interaction means that the event will not affect the bounce rate, so it's not like the setting will have a huge effect (it will only affect people who trigger an event on their first pageview and then leave without looking at more pages).