You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to gaearon, we can set displayName to components. It should be readable by Google Tag Manager with clicked elements' __reactInternalInstance$XXXXX - https://stackoverflow.com/a/48335220
We can set displayName property for components that we want to track usage (click). It helps React devtools debugging in production as well.
The text was updated successfully, but these errors were encountered:
A Google Tag Manager custom variable setup like below will be able to track the React component name (if it's static displayName is set) of the clicked element (or clicked element's ancestor):
function(){varcurrentNode={{Click Element}};varreactInstanceKey=Object.keys(currentNode).find(function(key){returnkey.startsWith('__reactInternalInstance$');});if(!reactInstanceKey)return;varcurrentInst=currentNode[reactInstanceKey];while(currentInst){if(currentInst.elementType&¤tInst.elementType.displayName&&// Ignore names like "WithStyles(ForwardRef(ButtonGroup))"currentInst.elementType.displayName.indexOf('(')===-1){returncurrentInst.elementType.displayName;}currentInst=currentInst.return;}}
However, most components in Cofacts code base do not have displayName -- some buttons we want to track isn't even an isolated component. I am switching to data-ga method property instead of displayName.
We use both data-ga and displayName in the end. data-ga provides greater flexibility because we can set different names for different occurrences, while displayName makes sure all clicks under a component will be recorded no matter where it is rendered.
Discussion: https://g0v.hackmd.io/@johnson/ByAb_n24U#Tracking
According to gaearon, we can set
displayName
to components. It should be readable by Google Tag Manager with clicked elements'__reactInternalInstance$XXXXX
- https://stackoverflow.com/a/48335220We can set
displayName
property for components that we want to track usage (click). It helps React devtools debugging in production as well.The text was updated successfully, but these errors were encountered: