After Effects incorporates a motion tracker as part of its standard tools.
However before tracking can begin, there are several elements that need to be explained. In professional film production, tracking begins even before the cameras are rolling. Match movers will place markers around the studio set (or on location set etc) however for a large cgi shot it likely will be filmed in a studio. This is important practice, as exact measurements are needed to compute the cameras location and get a correct match. These marked points on set can be selected later inside the computer program for motion tracking.
This picture from a movie set is a great example, you can see the blue screen marked with clear white dots at intervals.
However it is also possible to camera track without pre-marking the scene, of course a smaller production or perhaps personal work might use video not privy to the luxury's of a 100 million dollar film set. After Effects (and indeed most tracking software) can still track by having the user select key points that remain in frame for the duration of the track. Usually areas of high-contrast are best, as the tracker has an easier time picking them up, of course this is not as perfect as matched moved film, as such some tracking might be needing a manual user tweek.
These are the After Effects tracker controls and track point. You can add multiple track points and edit targets that the tracking data will be applied to. Important to note here are the Position and Rotation settings, each referring to how the camera behaves in the footage. Position might only be required if the camera is locked off on a straight pan, but rotation is needed if the camera is shaky or hand held. If the tracker does not get these specific settings then the end result will not match the footage correctly.
This is the track point, placed on the footage (on your match move point if you have one) but if not, its up to the user to find a good area of high-contrast for a track. The first square is the feature region, it defines the element in the layer to be tracked. While defining feature region make sure that feature region should surround a distinct visual element in the shot.
The search region square defines how far the tracker will look for the feature region, larger might increase tracking processing times, but higher safety threshold.
Heres an example of the tracker applied to a good area of footage, the buoy, red over the constant ocean colour, gives the tracker a great spot to track from.
Heres a picture of a finished track, each frame is visible, this track is just a position track with a locked off straight pan camera, you can see it clearly moving across the screen, quite simple but it works.
Finally the tracking data can be applied to a null object, this is an invisible object but can used to contain important data. The reason the data is applied to a null, is because then composition elements can be parented to the null to match the scene perfectly. For example, in a set extension, the matte image, would be parented to the null object, making it copy the position and rotation data from the track, allowing the image to move in time and place with the camera, lining up perfectly and giving the desired visual effect.