MarkEdmondson1234 / googleMeasureR

Send tracking hits to Google Analytics from R code using the Google Analytics Measurement Protocol
MIT License
17 stars 1 forks source link

E-commerce product data encoding issues #5

Open martijnvv opened 4 years ago

martijnvv commented 4 years ago

Whenever I send in product values as part of an e-commerce transaction hit, they are showing up in my reports encoded. If I send them through a browser hit (copy pasted from debug) they show up decoded in my GA reports. See example of report here. Top one through browser, bottom one through R. Prefixed a z to differentiate the hits in GA.

hits_GA

Hit sent: /debug/collect?ds=googleMeasureR&cid=1e8c4cea-f8b7-11e9-845e-5f049fc04066&dp=%2Ftracks_submitted&pa=purchase&ti=z123456789&pr1id=z4321_1%202&pr1nm=zThis%20is%20a%27test_hit%21&pr1ca=zcategory%20123%20%21&pr1pr=1200&fl=0&v=1&tid=UA-30688293-8&t=pageview

Output in R debug mode:

List of 13
 $ ds   : chr "googleMeasureR"
 $ cid  : chr "1e8c4cea-f8b7-11e9-845e-5f049fc04066"
 $ dp   : chr "%2Ftracks_submitted"
 $ pa   : chr "purchase"
 $ ti   : chr "z123456789"
 $ pr1id: chr "z4321_1%202"
 $ pr1nm: chr "zThis%20is%20a%27test_hit%21"
 $ pr1ca: chr "zcategory%20123%20%21"
 $ pr1pr: chr "1200"
 $ fl   : chr "0"
 $ v    : chr "1"
 $ tid  : chr "UA-XXX-XX"
 $ t    : chr "pageview"
$`hitParsingResult`
  valid parserMessage
1  TRUE          NULL
MarkEdmondson1234 commented 4 years ago

Does this occur with other hits? The payload data is encoded before being sent via utils::URLencode(x, reserved=TRUE) but perhaps it is not working for nested hits?

martijnvv commented 4 years ago

I've only seen this occur to values in the e-commerce object. Pageview and event values seem to work fine.for example, in this example the dp parameter is returned as /tracks_submitted.

MarkEdmondson1234 commented 4 years ago

I'm trying to replicate the issue. Does this code look similar to your example?

  ee <- gmr_enhanced_ecom("purchase",
                          transaction_id = "rerer",
                          revenue = 4300.23,
                          product_sku = c("sku4","sku23","sku7"),
                          product_name = c("prod A",
                                           "prod B",
                                           "prod C/yeah"))

  req <- gmr_hit_page(url_path = "/checkout",
                      enhanced_ecom = ee)

which gives

Debug mode
List of 15
 $ ds   : chr "googleMeasureR"
 $ cid  : chr "d378217a-fa91-11e9-80c1-ac87a30fc0b7"
 $ dp   : chr "%2Fcheckout"
 $ pa   : chr "purchase"
 $ tr   : chr "4300.23"
 $ ti   : chr "rerer"
 $ pr1id: chr "sku4"
 $ pr2id: chr "sku23"
 $ pr3id: chr "sku7"
 $ pr1nm: chr "prod%20A"
 $ pr2nm: chr "prod%20B"
 $ pr3nm: chr "prod%20C%2Fyeah"
 $ v    : chr "1"
 $ tid  : chr "UA-XXXX"
 $ t    : chr "pageview"
martijnvv commented 4 years ago

Yes, in this format, only used one product with more additional variables.

martijnvv commented 4 years ago

This appears to happen with all variables, also when firing events (label, action, category). I only see the page value (ie "page value") looking fine in GA.

martijnvv commented 4 years ago

It appears that the utils::URLencode(x, reserved=TRUE) function is causing issues with eec and regular events. Once this is commented out, the events and pageviews are sent to GA just fine. Might be an easy fix. Seems contradictory to the GA documentation (https://developers.google.com/analytics/devguides/collection/protocol/v1/reference#encoding), but works nonetheless

jerrroen commented 3 years ago

Hi there. Very late to this party (Nice to see you here @martijnvv). I am also seeing encoding issues for the non-eec variables. So for instance event category will show "%20" in GA when I include spaces.

martijnvv commented 3 years ago

It's kind of an old issue, but if I remember this correctly, I fixed it locally by updating the gmr_hit_event function:

`gmr_hit_event <- function(category, action, label = NULL, value = NULL, interaction = TRUE,

enhanced_ecom = NULL,

                      ...){

payload_data <- list( ds = "googleMeasureR", cid = gmr_uuid(), ec = category, ea = action, el = label, ev = value, dp = "/event", ni = if(interaction) 0L else 1L # is 1 if NOT interactive... )

payload_data <- add_enhanced_ecom(payload_data, enhanced_ecom)

payload_data <- override_list(payload_data, ...)

gmr_post(payload_data, hittype = "event")

}`

Might be helpful.

jerrroen commented 3 years ago

Not just 'gmr_hit_event' for me. Also 'gmr_post'. For example: gmr_post(list(t= "pageview", cid = gmr_uuid(), tid = "UA-999999-1", dp = "/mpr", dt = "Hello 001")) will result in "Hello%20001" in GA.

martijnvv commented 3 years ago

That could be. Only used it for events, not pageviews. I can imagine, the utils::URLencode(x, reserved=TRUE) part is causing issues for all events though. As mentioned earlier in this issue

jerrroen commented 3 years ago

Thanks.