If the chords in the song are GMaj, CMaj and DMaj then you are playing in the key of G. You need to look at the notes that make up the individual chords rather than just the root notes of the chords. A Major chord is made up with the 1st, 3rd and 5th notes of the Major scale.
So for G Major the notes are G, B and D. For C Major the notes are C, E and G. For the D Major the notes are D, F#, A. All of these notes fit into the G Major scale.. but if you add the A Major "chord" to the mix then while you are playing the A Major chord you are no longer in the key of G Major because the notes that make up the A Major chord are A, C#, E. Notice the C#? It's not in the G Major scale, which is:
G, A, B, C, D, E, F#
Anyway.. I suggest you have a look at: http://go.guitartricks.com/course.php?input=1
Particular chapters 3 and 4..