Help with Invariance of Euler-Lagrange equations under a gauge transformation? I'm presented with the following question:

From the Lagrangian for a relativistic particle in an electromagnetic field:
  $$L=-\frac{m}{\gamma} - eV + e\vec A \cdot \vec v$$
  show that the gauge transformation $\vec A \rightarrow \vec A + \vec \nabla \phi$ and $V \rightarrow V - \partial_{t}\phi$ does not change the EL equations. Explain this invariance from the point of view of the action.

As far as I know, $V, A, \phi$ depend on $(r(t), t)$- it really isn't explicit.
So, I began by transforming $L$, and got the following:
$$L' = L + e(\partial_{t}\phi + \vec \nabla\phi \cdot \vec v)$$
I realised that the second term could be rewritten as an exact derivative (I think this is right?):
$$L'=L+e\left(\frac{d\phi}{dt}\right)$$
From here, I then substituted $L'$ into the EL equations:
$$\frac{\partial L'}{\partial r_i}=\frac{\partial L}{\partial r_i} + \frac{\partial}{\partial r_i} \left(\frac{d\phi}{dt}\right)$$
$$\frac{d}{dt} \frac{\partial L'}{\partial \dot r_i}=\frac{d}{dt}\frac{\partial L}{\partial \dot r_i} + \frac{d}{dt}\frac{\partial}{\partial \dot r_i} \left(\frac{d\phi}{dt}\right)$$
Now, I know these things are supposed to be equal $$\frac{\partial L'}{\partial r_i} = \frac{d}{dt} \frac{\partial L'}{\partial \dot r_i}$$
Implying that:
$$\frac{\partial L}{\partial r_i} + \frac{\partial}{\partial r_i} \left(\frac{d\phi}{dt}\right)=\frac{d}{dt}\frac{\partial L}{\partial \dot r_i} + \frac{d}{dt}\frac{\partial}{\partial \dot r_i} \left(\frac{d\phi}{dt}\right)$$
In there, I can see the original EL equations (which I can then cancel)

What I'm stuck with, is how to prove that:
  $$\frac{\partial}{\partial r_i} \left(\frac{d\phi}{dt}\right) = \frac{d}{dt}\frac{\partial}{\partial \dot r_i} \left(\frac{d\phi}{dt}\right)$$
Is it as simple as just treating it as a set of EL equations in themselves, thereby being equal to $0$ ?

Further, to finish the question:
$$S = \int L' dt = \int L dt + \int e\left(\frac{d\phi}{dt}\right)dt = S + e\int \frac{d\phi}{dt} dt$$
Which is just S plus some extra term.

Just as a sanity check, is the (physical) reason this becomes invariant (and the extra term plays no role in the variational principle) just because it (the extra term) is fixed? Or is there more to it? 



*

*I can see that this term should just be $0$ due to $S$ cancelling from both sides, but I'm thinking more contextually here.


Thanks in advance, and any help / clues / further resources will be much appreciated! 
 A: The new action is
$$
S' = \int_{t_1}^{t_2}L' \text{d}t = \int_{t_1}^{t_2}\left(L + e\frac{\text{d}\phi}{\text{d}t}\right)\text{d}t = S + e\left[\vphantom{1_1^1} \phi\right]_{t_1}^{t_2}.
$$
Since the extra term is constant, the variation of the action hasn't changed: $\delta S' = \delta S$, and therefore the EL equations remain the same.
A: How about this. We wish to show $$\frac{\partial}{\partial r_{i}}\left(\frac{d \phi}{d t}\right)=\frac{d}{d t} \frac{\partial}{\partial \dot{r}_{i}}\left(\frac{d \phi}{d t}\right).$$
Consider the right hand side.
$$\frac{d}{d t} \frac{\partial}{\partial \dot{r}_{i}}\left(\frac{d \phi}{d t}\right)=\frac{d}{d t} \frac{\partial}{\partial \dot{r}_{i}}\left(\frac{d \phi}{d r_i}\frac{d r_i}{d t}\right)$$
by the chain rule
$$=\frac{d}{d t} \frac{\partial}{\partial \dot{r}_{i}}\left(\frac{d \phi}{d r_i}\dot{r_i}\right)$$
$$=\frac{d}{dt}\left(\frac{\partial}{\partial \dot{r}_i}\left(\frac{d\phi}{dr_i}\right)\dot{r}_i+\frac{d\phi}{dr_i}\frac{\partial \dot{r}_i}{\partial \dot{r}_i}\right)$$
$$=\frac{d}{dt}\left(\frac{\partial}{\partial \dot{r}_i}\left(\frac{d\phi}{dr_i}\right)\dot{r}_i+\frac{d\phi}{dr_i}\right).$$
If $\phi=\phi(r(t),t),$ then$^1$ $$\frac{\partial}{\partial \dot{r}_i}\left(\frac{d\phi}{dr_i}\right)=\frac{d}{dr_i}\left(\frac{\partial\phi}{\partial\dot{r}_i}\right)=0,$$
so the right hand side reduces to
$$\frac{d}{dt}\left(\frac{d\phi}{dr_i}\right)=\frac{d}{dr_i}\left(\frac{d\phi}{dt}\right),$$
if we allow ourselves to interchange the order of differentiation. The right hand side is then the same as the left hand side (up to a $\partial/\partial t \leftrightarrow d/dt$) and we are done. I'm not sure about the subtleties of $\partial/\partial t$ vs. $d/dt$, but maybe you can come up with an argument. I hope this helps.
$1.$ In general if $\phi=\phi(r(t),\dot{r}(t),t))$ this step is not obvious and I'm not sure what the argument would be for this term to vanish.
A: Ok, so after many months I could finally come back to this and answer the problematic section properly.
Starting from the transformed Lagrangian:
$$L' = L + e(\partial_{t}\phi + \vec \nabla\phi \cdot \vec v)$$
I then applied the E-L equations:
$$\frac{\partial L'}{\partial r_i}=\frac{\partial L}{\partial r_i} + e\frac{\partial}{\partial r_i} \left(\partial_{t}\phi + \vec \nabla\phi \cdot \vec v\right) =\frac{\partial L}{\partial r_i} + e\left(\partial_i\partial_{t}\phi + \vec \nabla(\partial_i\phi) \cdot \vec v\right) $$
$$\frac{d}{dt} \frac{\partial L'}{\partial \dot r_i}=\frac{d}{dt}\frac{\partial L}{\partial \dot r_i} + e\frac{d}{dt}\frac{\partial}{\partial \dot r_i} \left(\partial_{t}\phi + \vec \nabla\phi \cdot \vec v\right)$$
Performing a little bit of a notational change on the second of these, to write everything in terms of components (re-expressing v):
$$\frac{d}{dt} \frac{\partial L'}{\partial \dot r_i}=\frac{d}{dt}\frac{\partial L}{\partial \dot r_i} + e\frac{d}{dt}\frac{\partial}{\partial \dot r_i} \left(\partial_{t}\phi + \partial_i\phi \cdot \dot r_i\right)$$
$$\frac{d}{dt} \frac{\partial L'}{\partial \dot r_i}=\frac{d}{dt}\frac{\partial L}{\partial \dot r_i} + e\frac{d}{dt}\left(\partial_i\phi \right)$$
Now applying the full derivative wrt time:
$$\frac{d}{dt} \frac{\partial L'}{\partial \dot r_i}=\frac{d}{dt}\frac{\partial L}{\partial \dot r_i} + e\left(\partial_t\partial_i\phi +\vec v \cdot \vec\nabla(\partial_i\phi) \right)$$
Which, using the E-L equations, we can see that following the transformation to $L$, they are unchanged.
Turns out reducing $\phi$ to a total derivative so early caused problems!
