Canonicalizing Paginated Collection Pages but not Tagged Collections

I want to canonicalize paginated collection pages. So this page https://mightylinetape.com/collections/industrial-safety-floor-tape-solid?page=9 would canonicalize to https://mightylinetape.com/collections/industrial-safety-floor-tape-solid. I know how to set that up with this:

{% if template contains ‘collection’ %}

{% else %} {% endif %}

However, that code also canonicalized my tagged collections. So now this page https://mightylinetape.com/collections/industrial-safety-floor-tape-solid/blue canonicalizes to https://mightylinetape.com/collections/industrial-safety-floor-tape-solid, which I don’t want.

How do I canonicalize paginated pages but not tagged collections? I’ve tried multiple routes and nothing seems to be working. I end up with two canonicals or a code error.

Thank you!