The objectives were to investigate the effect of feeding and visiting behavior of dairy cattle on CH4 and H2 production measured with voluntary visits to the GreenFeed system (GF) and to determine whether these effects depended on basal diet (BD) and 3-nitrooxypropanol (3-NOP) supplementation. The experiment involved 64 lactating dairy cattle (146 ± 45 d in milk at the start of trial; mean ± SD) in 2 overlapping crossover trials, each consisting of 2 measurement periods. Cows within block were randomly allocated to 1 of 3 types of BD: a grass silage-based diet consisting of 30% concentrates and 70% grass silage (DM basis), a grass silage- and corn silage-mixed diet consisting of 30% concentrates, 42% grass silage, and 28% corn silage (DM basis), or a corn silage-based diet consisting of 30% concentrates, 14% grass silage, and 56% corn silage (DM basis). Each type of BD was subsequently supplemented with 0 and 60 mg 3-NOP/kg DM in one crossover, or 0 and 80 mg 3-NOP/kg DM in the other crossover. Diets were provided in feed bins which automatically recorded feed intake and feeding behavior, with additional concentrate fed in the GF. All visits to the GF that resulted in a spot measurement of both CH4 and H2 emission were analyzed in relation to feeding behavior (e.g., meal size and time interval to preceding meal) as well as GF visiting behavior (e.g., duration of visit). Feeding and GF visiting behavior was related to CH4 and H2 production measured with the GF, in particular the meal size before a GF measurement and the time interval between a GF measurement and the preceding meal. Relationships between gas production and both feeding and GF visiting behavior were affected both by type of BD and 3-NOP supplementation. With an increase of the time interval between a GF measurement and the preceding meal, CH4 production decreased with 0 mg 3-NOP/kg DM but increased with 60 and 80 mg 3-NOP/kg DM, whereas type of BD did not affect these relationships. In contrast, CH4 production increased with 0 mg 3-NOP/kg DM but decreased with 60 and 80 mg 3-NOP/kg DM upon an increase in the size of the meal preceding a GF measurement. With an increase of the time interval between a GF measurement and the preceding meal, or with a decrease of the size of the meal preceding a GF measurement, H2 production decreased for all treatments, although the effect was generally somewhat stronger for 60 and 80 mg 3-NOP/kg DM than for 0 mg 3-NOP/kg DM. Hence, the timing of GF measurements next to feeding and GF visiting behavior are essential when assessing the effect of dietary treatment on the production of CH4 and H2 in a setting where a spot sampling device such as a GF is used and where the measurements depend on voluntary visits from the cows.