Integrating Compass into IMU odometry

Hi guys,
I finally managed the estimation of a mobile robot using an IMU. During some experiments, I found a drift on the yaw angle even if the robot move on a straight direction. Searching on the internet I found the possibility to use a magnetometer for correcting heading estimation, but I'm a bit stuck!
I'm able to estimate position along x and y axes (double integration of accelerometer measurements using gyroscope for projection) but I don't figure how to integrate the compass.
Does someone can help me?

Thanks

Alek