let postPropertiesData = {};
if (data.additionalProperties) {
for (let key in data.additionalProperties) {
postPropertiesData[data.additionalProperties[key].key] = data.additionalProperties[key].value;
}
}
const postProperties = JSON.stringify(postPropertiesData);
const setProperties = JSON.stringify({
utk: data.userToken,
eventName: data.eventName,
properties: postProperties,
ocurredAt: getTimestamp(),
});
Now this is the template code I use and then there is a form with an input fields where I can set the property name and the value (it’s set dynamically). It looks like this
In the hubspot log I get no request header or body even though the call goes through and it works otherwise.
In the debug it put it as
properties: {}
For same reason I’m not getting the properties: {‘hs_asset_type’:‘PDF’} and the rest as planned. The table is functioning as you can see that Google Tag Manager is actually reading the variables properly in the table and I"ve checked in preview mode and the variables are functioning correctly.
Something is happening between that, where is isn’t being converted into an object properly containing all the property names and values. And isn’t being set as part of the request body.
Hello @YizSeg , for your first question in order to create the right structure you will need to pass another object inside the object of the propertiesData so it needs to look like this:
let postPropertiesData = {
"properties" : []
};
So with the above you will be able to push all the constructed properties correctly inside the properties object as per the documentation, this will look like the following:
// first we do an iteration of the data and store it temporarily in a variable
var tempProperties = {};
if (data.additionalProperties) {
for (let key in data.additionalProperties) {
tempProperties[data.additionalProperties[key].key] = data.additionalProperties[key].value;
}
}
// then we insert all tempProperties in the correct object inside postPropertiesData
postPropertiesData.properties.push(tempProperties);
You can also add all the other key-value pairs in the same manner:
@miljkovicmisa thanks for that I tried that, but it came back with a TypeError saying that TypeError: Object has no ‘push’ property. Either way, I found the answer.
I imported the API called makeTableMap
const makeTableMap = require('makeTableMap');
and then instead of using a if and for statements,
I used the API to attach it straight to the object
Great news @YizSeg , this is a nice workaround, seems like I had a typo in my code and that’s why you got the “push” error, the “properties” key needs to be an object not a key-value pair so the preformatting of the variable should look like this (I also updated my answer):