Google Analytics: Tracking multi categories where a page belongs - javascript

I have a content driven website, where each content item belongs to many different categories.
For example, article "A" belongs to the categories "cat1", "cat3", "cat4" and article "B" belongs to the categories "cat2", "cat3", "cat4".
The number of categories is very big (around 800) and the number of articles more than 10.000.
I want to know all the pageviews of articles that belong to a given category.
Researching google analalytics I didnt find any tool that allows me to do that.
I investgated if I could misuse the campaigns to do it, but the only way would be to rewrite the urls (in order for the campaigns to work), and I dont want to touch my very nice urls.
I tried doing it with events, but it was messing up my bounce rate (since an event meant that the users were actually doing something, so the page was not counted as "bounced").
Has anyone any idea of what I could do to record my categories?
The same solution could be applied to tags in a blog post. (Lets say you wanted to know all the pageviews of all blog posts that have the tag "travel").
Thanks
Koyan

Ok, I didnt manage to do exactly what I wanted, but canibalising the custom fields I managed to do something very close.
I put in my ga code the following:
_gaq.push(['_setCustomVar', 1, 'Cat', '-coats-winter-red-used-light-pockets-', 3 ]);
Where coats, winter, red, used, light, pockets are the tags (categories) of that page.
I use php to produce this string.
An other page would have the following for example:
_gaq.push(['_setCustomVar', 1, 'Cat', '-dress-winter-blue-new-light-pockets-', 3 ]);
And all these got pushed to a single variable. Now, I cannot find which of the tags has the most hits (the one part of the report I wanted), but I can find how many hits a certain tag has.
To do that, I created a custom report, where I put the metric group "pageviews" and the Dimension drilldowns "Custom Variable (Key 1)", "Custom Variable (Key 1)
Custom Variable (Value 01)", "Page"
Then I run the report, click on the variable "Cat", and filter for -winter- and it gives me how manypageviews I had for articles with the tag "winter".
Dissadvantages:
a) There is a limit of 64 bytes for the combination of custom variable name and value. I have overcome this by not using actually the tags, but their id's
(so, in my real scenario, the values look like -31-39-45-130-168-206-249- but this is good enough for me).
b) You cannot find from inside google analytics which category/tag has the most pageviews.
(you can always export it though to a csv and work on it in an other script).
Hopefully Google will add a "tags" functionality sometime in the future (am I the only one needing this?)

One potential solution would be to use custom variables. For example:
Category1 = Coats
Category2 = Winter
Category3 = Red
The two limitations of this solution are that you are limited to five custom variables per page and that your google analytics queries would get fairly complex as you would need to search across all the category variables to find the specific value you're looking for.

Related

Is it possible to display WP posts that only have both categories

I have a rather challenging project where a finance magazine using WP wishes to digitalize their print offering. As you could expect all articles are uploaded manually by them and divided into various subcategories (e.g. economy, politics etc.). These are then displayed on various category pages. The articles uploaded consist mainly of all the articles that are also found in that months issue.
The aim is to display a table of contents for that issue, allowing readers to directly see a list of the articles published. Basically an identical copy of Bloombergs businessweek: https://www.bloomberg.com/magazine/businessweek/20_23 (side question: anyone can guess how BB does this?)
Now lets say all articles belonging to that issue are given an extra category or possibly term, such as issue 20/05, using a wp_query you could pull in a list of all articles from that issue. In order to then divide them into subcategories, which already exist since thats how they are displayed online, I could then have an extra loop that would pull in all articles that contain the term 20/05, as well as economy.
Is that possible using:
'taxonomy' => 'category',
'term' => 'category-1'
As techincally the term would be the parent category.
This method would require the page to be duplicated and the new term inserted every month, but apart from that its quite easy. Very new to php and wondering if this challenge is maybe beyond me. Any pointers or tips much appreciated.
If I understand correctly, you need to use categories in their default way but also group them by another taxonomy "Issue", for example.
You could register a custom taxonomy: https://developer.wordpress.org/reference/functions/register_taxonomy/ and call it "Issues" for example and then each post can belong to one of the issues.
Then you can use tax_query to filter posts that belong to specific issue:
https://developer.wordpress.org/reference/classes/wp_tax_query/
You can also have a Taxonomy archive template https://developer.wordpress.org/themes/template-files-section/taxonomy-templates/ where you can display issues.

modifying HTML page "on the fly"

I looked at "Generating HTML Page on the fly" on this website, but most of it was over my head.
I have a 2 part question that I would like assistance with please.
I want to fill a narrow vertical container, <div id=”counter”> with the numbers 1 .. <xx>.
<xx> is determined by the record count of a database, filtered “on-the-fly”, by the user choosing a category (no problem there – I have an SQL background)
Eg. Category1: 1 .. 200
Category2: 1 .. 6
These numbers could change over time, as I want to allow users to add content to the database (vetted of course).
I have viewed a number of website source code pages (of similar ideas eg. Surgicalexam.com), but they have all been hard-coded and are distinct pages per category.
I have created a small website of a similar nature to that, hard-coding all the images and links, but I am looking at 3000+ images (as a starting point here), and they differ per page.
I have created this scenario many times in stand-alone apps and from past experience, I thought perhaps, I could create a javascript routine which would use a loop to
• print the numbers to the <div> using the getelementbyID ( ).
• Fill an array with the record number, a title and an image link.
Question 1: Is this possible or am I beating a “dead horse”?
If it is possible, any suggestions would be gratefully accepted.
Part 2:
My current idea is that, as the user hovers the mouse over any number, a mouseover ( ) event will occur that will read the appropriate array record and display the <title> as a tool-tip-text.
If the user clicks the number, a function (I have yet to write) will read the appropriate array record and attach the image link to an <a> tag, and subsequently display the appropriate image to the screen.
Question 2: repeat of question 1.
I have viewed a number of website source code pages (of similar ideas eg. Surgicalexam.com), but they have all been hard-coded and are distinct pages per category.
Why are you so sure about that? You can't see php-code, because it is executed on the server. There is no way to know if it was hardcoded or by php
Answer:
It is possible.
If I understand this correctly, you want to read some data from a database and if the user clicks / hovers something, you want to load more data?
You have to splitt this into two things:
Load data with PHP from the db (Server side)
If you want a live, visual feedback you need JavaScript (and/or CSS3) to do changes. (Client side)
One possible solution is to create a API with php (maybe REST-like) and then call that api with JavaScript.
You could also do everything with PHP but this will require a reload of the website on every click. PHP cannot do changes On-The-Fly.
First of all you should learn the basics about web development.
And most important: If you decide to learn Web-Programming: learn about security, too. For example things like Cross Site Scripting and SQL-Injection. Never trust data coming from a client (e.g. JavaScript)!

Omniture - Is it possible to count number of clicks per special tagged link?

I'm trying to figure out is it possible to track number of clicks per special links via Omniture.js (s_code.js). For example -
Set of links should have something like tag_1, others tag_2 etc.:
Menu link 1
Menu link 2
Menu link 3
<div class="some-wrapper">
Some button
</div>
On click I need to +1 for special tag, that's way counting number of clicks per different classes of links.
Official documentation is really confusing, should I somehow do this by specifying eVars or props?
Different variables can be used to populate different reports. Which variables you want to populate depend on what business questions you are trying to answer. For example, if you simply want a running count of # of clicks and that's it, all you really need is the answer provided by #BrettAHale. But if you are looking for more robust reporting, e.g. correlating clicks with other activities or data, then you're going to want to populate some of the other variables.
Providing general training for the variables and what reports they populate is outside the scope of Stack Overflow. If the documentation is too confusing then I suggest you enroll in some of the training courses Adobe offers. But, if you have a specific question about a specific variable that you are confused about, feel free to ask.
<a href="#" onClick="s.tl(this,'o','tag_1');”>Menu link 1</a>
This makes some assumptions:
Your Omniture object is named "s"
You don't need any additional props and evars set
This method will surface data in the custom links report with tag_1, tag_2 etc as the line items.

How to pass multiple custom field values to Analytics

In my site, like most, pages can be tagged with tags/categories.
We have an internal rule / sanity check that a piece can only have a max of three tags.
The issue is being able to determine which are the most popular in terms of pageviews as Google Analytics doesn't allow you to pass multple values as a custom field value or as an event value.
What I'd like to achieve is to add a dimension to Analytics so as to be able to report which are the most popular categories/tags.
Our tag structure is hierarchical like so:
-Top Level Tag
--Secondary Level Tag 1
--Secondary Level Tag 2
--Secondary Level Tag 3
-Top Level Tag
--Another Tag
and so on...
At the moment, it seems the only way is to pass single values, ala:
_gaq.push(['_setCustomVar',4,'categories','culture theatres',3]);
Where as I'd like to pass an array of values, like:
_gaq.push(['_setCustomVar',4,'categories', ['culture', 'theatres'],3]);
Anyone know a workaround or whether it's possible to do so? The docs don't give me hope...

WooCommerce tracking variable product views/selects

I'm just working on the tracking of woocommerce variable products with google analytics. Tracking simple products is not a big deal, because every page view is a product. However for me it's pretty interessing to know which product variations users looked at.
I need some similar stats for variable products. Which variable products did the users look at? My products do have quite some variations since one product has about 7 attributes.
I think it shouldn't be to hard to hook into the drop down selects of woocommerce variable products with js and fire on select.
How would you track the product variation views with google analytics?
I don't want to mix page views, sales and on the other hand view of product variations too much. I'd rather prefer to track the views of variations through events into a different view (or property). How you get those events into one view and everything else in the default view?
How would you track the parameters to be able to analyse them? My main filter will be product, than I want to filter on different attributes and see how the other attributes cluster on user impressions.
Anyone already has a script for this?
You can just add event handler for 'found_variation' in JS. That is woocommerce event for selecting variation.
And then use analytics built in function:
https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
jQuery(document).ready(function($) {
$(this).on('found_variation', function(event, variation) {
_gaq.push(['_trackEvent', 'Variation', 'Select', variation.variation_id]);
});
});
Haven't tested it but in theory it should work.
And just check variable 'variation' to see what info is available.

Categories