Custom Event - Error [object Object]


#1

Hi all,

I developed a custom event that you can see below.

Thanks to the console.log() function, i succeeded to got the names of the users (the different console.log return a string of characters as you can see below). Indeed, the variable result is well assigned to Jean Tod (the name user).

However when i go on the Events features on countly, i see my events "User name" and the segmentation column doesn't return Jean Tod but [object Object].

I need help please to fix this issue !
Thank in advance

Countly.q.push(['add_event',{
"key": "User Name",
"count":1,
"segmentation": {
"Name":$(document).ready(
window.onload = function () {
var div = document.getElementsByClassName("hl-link")[0];
console.log(div);
let div2 = document.getElementsByClassName("hl-link")[0].innerText;
console.log("div2: " + div2);
console.log("typeof(div2):" + typeof(div2));
console.log("div2.toString(): " + div2.toString());
var result = div2.toString();
return result ;
}),
}
}]);

div:
div2: Jean Tod
typeof(div2):string
div2.toString(): Jean Tod


#2

Hello,
you can't really provide the result of jquery event like that. What would work for you, is something like this:

$(document).ready(function () {
    var div = document.getElementsByClassName("hl-link")[0];
    console.log(div);
    var div2 = document.getElementsByClassName("hl-link")[0].innerText;
    console.log("div2: " + div2);
    console.log("typeof(div2):" + typeof(div2));
    console.log("div2.toString(): " + div2.toString());
    var result = div2.toString();
    Countly.q.push(['add_event',{
        "key": "User Name",
        "count":1,
        "segmentation": {
            "Name":result
        }
    }]);
});

#3

Thank you so much !!
it works perfectly :slight_smile: