Google Tag Manager dataLayer integration

I’m trying to set up GTM and use the dataLayer to pass data from my pages to Analytics & Facebook for tracking purposes. Things like page title, price of the product, etc. To do this, I need to push to the GTM dataLayer.

Docs say to instantiate the dataLayer before the GTM code (which itself goes right after the opening tag.

My issue is how to do this in Jekyll with includes, etc. because, depending on the specific page (landing page asking for an email sign up vs a product purchase page), the dataLayer key/value pairs will be different.

I think an IF this page type (landing page), THEN this dataLayer code, ELSE the other type. But I’m not getting it put together correctly.

Anyone have a working example of how they set this up that they’d be willing to share? Or general ideas on an approach. I’m afraid I’m over thinking it but can’t simplify.

not sure I am following but maybe like this?

   {% if page.og-type == 'product' %}
    <meta property="fb:app_id" content="767572333356577" />
    <meta property="og:locale" content="en_US" />
    <meta property="og:type" content="product" />
    <meta property="og:title" content="{{ page.title }}" />
    <meta property="og:description" content="{{page.description}}" />
    <meta property="og:url" content="https://prolabprints.com{{page.url}}" />
    <meta property="og:site_name" content="ProLabPrints.com Photo Lab" />
    {% if page.og-image %}
    <meta property="og:image" content=" {{page.og-image}}" />  {% endif %}
    {% endif %}

that is in my head include.
og-image and og-type are page variable in the front matter of a page.

You also can check if the page url is equal to something or if it contains something.

I’ll get in my computer in a bit and work through that more carefully but on reading through it, I think that’ll get me there. Thanks. Just couldn’t get it fixed in my head how to construct it.