Question

How to add data to an event or user property using js dictionary

  • 3 August 2020
  • 1 reply
  • 162 views

  • New Participant
  • 1 reply

I am working on implementing mixpanel tracking for the first time. I am tracking events/users correctly and they are showing up within the live view just fine.

 

However when I assign a value to a property (say $email) from a dictionary by accessing the key that I’m interested in, no data is sent to mixpanel about that property. I have only successfully sent property data to mixpanel when assigning a variable that was assigned to by accessing the key from the dictionary. 

 

Here’s a sample script that I set up demonstrating what I wrote above.  Is this approach not possible? Will I need to assign the value of the key that I’m interested to a variable each time and then assign that variable to the property I’m interested in? 

 

Thanks for your time in helping with this.  

 

<script>


var newUserDict = {
    "email" : "adrian@awesome.com",
    "howHeard" : "facebook"
}

var emailVar = newUserDict["email"]
var howHeardVar = newUserDict["howHeard"]

console.log("email var " + emailVar);
console.log("howHeard var " + howHeardVar);

var mixpanelButton = document.getElementById("test-button")
mixpanelButton.setAttribute('onClick', 'AccountCreated("'+newUserDict+'")')

function AccountCreated(newUserDict) {

        mixpanel.track("Sign Up Test",{
        //not successfully sending to mp
         "$email": newUserDict["email"],
        "How Heard": newUserDict["howHeard"],
        "email222": newUserDict.email,
        "How Heard222": newUserDict.howHeard,
        //successfully sending to mp    
    "email3": emailVar,
    "hh": howHeardVar
    });
}


</script>
 

 


1 reply

Userlevel 6
Badge +3

@jrow —

Have you already seen the dev docs here?

 

It sounds like Mixpanel is ingesting the event, but the properties are not getting sent as you would expect?

I’m not a developer, but I don’t see any issue with sending your data to Mixpanel in this way — maybe there is a race condition between the event getting triggered and loading the library? It seems like while the formatting of the event & property is correct, it is having trouble connecting the property value to the library, so no property value is getting sent with the event. 

Have you tested sending the event with a simple format, to confirm that the issue is from formatting? (an example event is below). If you can confirm that the issue is from the format, then you can start simple and build to your current format, knowing that Mixpanel is ingesting your data as expected. 

// Send a "Played song" event to Mixpanel
// with a property "genre"
mixpanel.track(
    "Played song",
    {"genre": "hip-hop"}
);

 

If you've already resolved this, please let us know what ended up fixing your issue! We’d love to know.

 

Thanks,

 

Cherise

Reply


Mixpanel