I'm using the new Google Analytics Measurement Protocol and running into a problem where all my events are coming is as "new visitor" even though I'm sending the same client ID for all of the requests.
I assume Google is using the client ID to determine if a visitor is new or not, but it appears to be ignoring this value.
Here's the variables I'm sending in the POST request:
Array
(
[v] => 1
[tid] => *OBFUSCATED*
[cid] => E19A0922-ABDF-D704-E4D4-620FB7AD7885
[t] => event
[sr] => 1280x720
[ec] => Video%20Plays
[ea] => Sample
[el] => Roku%20App
[ev] => 1
)
Other events are similar, where the cid remains the same but the event category and values change.
It looks like after waiting a full day and sending some events again, they are showing as returning visits.
Your cid is wrong I guess. it should be a 32bit id separated from a dot. Find a actual case study in my blog post http://www.niroshan-samuel.com/google-universal-analytics-isnt-linking-offline-and-online-user-properly/
Related
I am using the Google Analytics API and want to know the average session duration of a spezific content site.
To get the metrics I am using this PHP Code:
$result = $analytics->data_ga->get(
'ga:XXXXXXX',
'2012-01-01',
date("Y-m-d"),
'ga:visits',
array(
'filters' => 'ga:pagePath==MY_URL',
'dimensions' => 'ga:pagePath',
'metrics' => 'ga:pageviews,ga:sessions,ga:uniquePageviews,ga:avgSessionDuration,ga:bounces',
'sort' => '-ga:uniquePageviews',
'max-results' => '25'
)
);
I get the following result:
[0] => Array
(
[0] => MY_URL
[1] => 8966
[2] => 7434
[3] => 7434
[4] => 17.15496368038741
[5] => 6245
)
Numbers 0-3 and 5 are exactly the same like Google Analytics Dashboard numbers (when I am logged in with my browser in google analytics)
But average duration time on site doesn't fit. API shows me 17.15 seconds and Google Analytics dashboard shows me 1 minute and 23 seconds.
Are these the same metrics? I want to have the "average duration time on site" (like standard Analytics Dashboard shows me).
Thanks!
There is no average duration time on site dimension. There is Avg. Time on Page and Avg. Session Duration. The confusion might be that you are looking at Time on Page in your dashboard, rather then session duration.
You might want to try ga:avgTimeOnPage instead of ga:avgSessionDuration.
I use Prestashop 1.6.2 and I have a problem trying to add this function.
I am a little bit new trying to mod prestashop, the thing is that I have some products that can be bought only for professionals. Everytime a user registers it's assigned to a user group (professional and no-professional).
I know I can hide the categories for specific user groups, but this method is not perfect, due to if they know the name of the product or search it, they can still access the product page and buy it.
Is there any smarty variable to edit the product.tpl so it displays the button with the conditions above? Or a module or another way to do this?
I don't know exactly is there is a variable already set in smarty or not, but your can define your customer variable with object of customer:
Find controllers/front/ProductController.php file, find method assignPriceAndTax and in the end of it you will find something similar to this:
$this->context->smarty->assign(array(
'quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (float)$tax, $ecotax_tax_amount),
'ecotax_tax_inc' => $ecotax_tax_amount,
'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2),
'ecotaxTax_rate' => $ecotax_rate,
'productPriceWithoutEcoTax' => (float)$product_price_without_eco_tax,
'group_reduction' => $group_reduction,
'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address),
'ecotax' => (!count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((float)$this->product->ecotax) : 0),
'tax_enabled' => Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'),
'customer_group_without_tax' => Group::getPriceDisplayMethod($this->context->customer->id_default_group),
));
Add to this array
'customer_object' => $this->context->customer,
This variable you can use on the product page.
You can use the same way to close those buttons for all 'buy-windows' on your site.
Im trying to track an event that has 3 dimensions (user id, widget id,post id). Every click event must have its own row with a unique post id, user id and widget id so i can track the number of clicks per post. Extra: All the dimensions are set to have a scope of 'user'.
ga('send', 'event', 'widget', 'click', 'uwp',
{
'dimension1': $user_id,
'dimension2': $widget_id,
'dimension3': $post_id
}
);
I later query using the reporting api.
$result = Analytics::query(
$start_date,
$end_date,
'ga:totalEvents',
array(
'dimensions' => 'ga:dimension3,ga:pagePath,ga:date,ga:eventAction',
'sort' => '-ga:date',
'filters' => 'ga:eventAction==click;ga:eventLabel==uwp;ga:dimension1=='.$user->id,
'max-results'=> '100'
));
The result is incorrect all the clicks are being bundled up into 1 dimension, being dimension3 the post id.
Ex) If i click on a post of id 30 (dimension3 is set to 30) and a post of id 10 it will report that post of id 30 has 2 clicks or some older id has 2 clicks.
Google Analytics Dashbaord Picks:
As you can see from the pick i have 1 row with post id of 2 and 7 clicks, yet i sent events with many different post ids. (dimension3 == post id).
The problem here is that you are setting all of these dimensions to have a scope of user. Because of this, each dimension can only have one value per user. This is fine for the user id dimension, but for a dimension like post id, this is likely incorrect. Presumably, a user can view many post ids. Setting post id to user scope will cause the post id value to be overwritten with the latest post each time a new post is seen (which is why only one value is appearing in your report). You'll instead want to set post id to have a scope of hit, which will allow a different value to be sent on each event hit.
You can change the scope via the interface.
Read more about custom dimension scope.
I have data stored in the Second Dimension Google Analytics Events. The field is called Custom Variable (Value 01).
How can I use the GA api to get the values from Custom Variable (Value 01).
I'm using the GA explorer http://ga-dev-tools.appspot.com/explorer/ and can't figure out how to get the Custom Variable.
I see these options:
ga:dimensionXX
ga:customVarNameXX
ga:customVarValueXX
I tried replacing the xx with 01 but I had no luck. Anyone know how I can get the info for GA via API?
Thanks to #Blexy. This was my code at the end:
$params = array(
'metrics' => 'ga:visitors',
'dimensions' => 'ga:customVarValue1,ga:eventLabel,ga:deviceCategory,ga:operatingSystem',
'max-results' => 1000,
'start-date' => $start_date,
'end-date' => $end_date,
);
Try removing the 0.
For example, I have a query like this:
ga:customVarName4=~Previous-Purchases;ga:customVarValue4==1
This gets my custom variable name that matches regex Previous-Purchases AND the custom variable value is equal to 1.
I'm using WordPress, specifically WooCommerce, creating a new plugin to allow the user to store multiple shipping addresses. I'm currently storing these new shipping addresses as meta data in the user meta data table as a serialized array. I need a way to store these with some sort of ID.
What's the best way to do this -- give each a key ID with a unique number? Try to increment the last highest ID? Not sure what to do.
Why not just keep the serialized array but extend it to multidimensional?
array(
0 => array(city => 'Dallas', state => 'TX'),
1 => array(city => 'Madison', state => 'WI')
);