Let $g\colon X\to Y$ be a morphism of schemes, and let $D=(U_i,f_i)$ be a Cartier Divisor on $Y$. I've seen the following definition of the pullback of $D$: $g^*D\colon=(g^{-1}(U_i),f_i\circ g)$, as long as $g(X)\not\subseteq \operatorname{supp} D$. The problem is that I don't understand what the composition $f_i\circ g$ should mean. For any open $U\subseteq Y$, there is a bijection between $O_Y(U)$ and the functions $U\to \mathbb{A}_{\mathbb{Z}}^1$, so I guess the idea is to identify each $f_i$ as a quotient of two functions like that for some open $U$, compose and then go back through the same identification in $X$.
However, this procedure requires a lot of identification, and I wonder if there is a better characterization of the pullback of Cartier divisors. I've looked in some books but all I can find is the pullback of Weil Divisors. Also, by the characterization I found, I don't think it is clear why we should put the hypothesis $g(X)\not\subseteq \operatorname{supp} D$ to define the pullback.
Could you please give me a light on this, maybe also with some concrete examples of calculating pullbacks of Cartier divisors, so I could understand this a little better?