Using setKeyframe on only the transform and not the shape [Maya]

So I ended up with a few issues when attempting to set the keyframe on an object using the layout specified in the python command, I was trying to do something like:

cmds.setKeyframe("pCube1", value=True, attribute="visibility")

However as I was using instancing, this would also keyframe the visibility on the pCubeShape1 which I didn’t want, even if I explicitly passed in only the name of the transform, to avoid this you need to pass in the transform name and the attribute in the same go, so something along the lines of:

cmds.setKeyframe("pCube1.visibility", value=True)

and this should only change it on the transform.

Good Luck!