melissaguyre / mixpanel-segmentation-google-spreadsheets

Mixpanel Segmentation Data Export script for report automation into Google Spreadsheets
46 stars 31 forks source link

Special Characters #2

Closed ccardiel closed 9 years ago

ccardiel commented 9 years ago

Hi!

I'm trying to use special characters but... it doesn't work :/ I've followed you instructions (Add URL Encoding). I tried adding the special characters to as a line: urlParams = urlParams.replace(/\í/g, '%C3%AD');

And also added in the API PARAMETERS: 'Vinculaci%C3%B3n de cuenta', '(properties ...

Any idea? Thanks in advice :)

melissaguyre commented 9 years ago

Hey there,

IDEA #1 - Since you added your url encoding for special characters to the API Parameters directly, they are immediately losing their leading % because that is the first regex line (url encoding of any % characters) I have in my script as seen at line 112 in the github example. :) So at that point it becomes 'Vinculaci%25C3%25B3n de cuenta', '(properties ... and your own regex will not catch it at that point because the string has been transformed. You can look at the log in Google script to see this as my script does log the created URL so you can see the query being created. --- To be clear, just enter an event name string in the API_PARAMETERS section as it is seen in Mixpanel.

I may also be misinterpreting your note and you are saying you tried these two things independent of each other rather than together.

If you did try the urlParams = urlParams.replace(/\í/g, '%C3%AD'); by itself, I would make sure you tried it as the last replace rather than as the first. Because again, my replace of the % (which is currently the first replace at line 112 in the github example) would again transform this to '%25C3%25AD' and then it would again be something different.

IDEA #2 - When in doubt, go to your segmentation report in the Chrome web browser, set the segmentation properties you want, open up the Javascript console and reload the page to see how Mixpanel is handling the query for this event. You can see this in the console by toggling it to the XHR tab (in the line of toggles across the second line of the console) and looking at the Name Path called "segmentation?event=". This is generally helpful to me if I'm having trouble crafting a query to the Mixpanel APIs based on their available documentation.


Finally, on my part, I am not available this weekend but in the near future I will see if I can modify this script to handle URL encoding better than I do now for your use case. All of my Mixpanel events have had no special characters so I had not tested against this use case....and also this was my first javascript script so I am sure there is a way to do this better than a bunch of regex's that I should learn about for self improvement. :)

Thanks for letting me know and please keep me updated on your progress. I would love to know what you find out.

Cheers! Melissa

ccardiel commented 9 years ago

Hi Melissa!

I tried your idea #2 (since idea #1 was the one that I already used :) ) and looking closely to the "segmentation?event=" using Firebug I discovered that the parameters are the same... but for some reason the API stills give me an "Invalid API signature"... it has no sense :/ ... I'll keep digging, thanks for your help!

ccardiel commented 9 years ago

Hi Melissa! Here's the sample of the URL's (obviously edited for security). Hope it's helpful:

MixPanel Version: https://mixpanel.com/api/2.0/segmentation?event=Registro&type=unique& where=(properties%5B%22Plataforma%22%5D+%3D%3D+%22iOS%22)+and+(properties%5B%22Pa%C3%ADs%22%5D+%3D%3D+%22MXN%22)&to_date=2014-12-09from_date=2014-11-10&unit=day&api_key=XXXXX& expire=XXXX&sig=XXXXX

Your code version: http://mixpanel.com/api/2.0/segmentation?api_key=XXXXX&expire=XXXX&event=Registro& where=%28properties%5B%22Plataforma%22%5D%29%20==%20%22iOS%22%20and20%28properties%5B%22Pa%C3%ADs%22%5D%29%20==%20%22MX%22&type=unique&unit=day&from_date=2014%2D09%2D1&to_date=2014%2D12%2D09&sig=XXXX

Thanks! :)

ccardiel commented 9 years ago

Melissa, good news! A programmer in our team helped me with this one and he did the next modification (with the guidance of one cool guy in the supoport team of Mixpanel):

var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, sortedParameters,Utilities.Charset.UTF_8);

With this, the issue is solved, thanks for your help, may the force be with you :)