# lucianfialho/30-seconds-gtm architecture

> Architecture diagram of the GitHub repository lucianfialho/30-seconds-gtm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lucianfialho/30-seconds-gtm
- Repository: https://github.com/lucianfialho/30-seconds-gtm

## Overview

##### Main System Components

a) Snippet Collection Layer
- Divide into three main categories:
- GA4 Conversion Snippets (Facebook Integration)
- Utility Snippets (Device Detection, AdBlock Detection, etc.)
- Legacy UA Conversion Snippets (Deprecated)

b) Integration Points
- Google Tag Manager Interface
- Analytics Platforms:
- Google Analytics 4
- Facebook Pixel
- Universal Analytics (marked as deprecated)

**[GTM Implementation Environment]**
- ↑
**[30 Seconds GTM Library]**
- ↓
**[Snippet Categories]**
- /    |    \
- /     |     \
**GA4    Utility  UA**
**Conv.  Scripts  Conv.**
- ↓     ↓      ↓
**[Target Platforms]**

##### Component Details

a) Snippet Transformations:
- Conversion flows:
- GA4 → Facebook Pixel
- UA → GA4 (deprecated)
- Raw Data → Formatted Objects

b) Utility Functions:
- Client/Session ID retrieval
- Device detection
- Form data capture
- AdBlock detection

##### Implementation Notes
- Use rounded rectangles for processes
- Version/deprecation indicators where applicable

##### Additional Elements

A small section showing:
- Snippet template structure
- Contribution flow
- Documentation integration

Remember to include a note about the project's primary purpose: providing ready-to-use code snippets for GTM custom JavaScript variables, with emphasis on analytics data transformation and utility functions.

This system design should help developers understand both the overall architecture and the practical application of the snippets in a GTM environment.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph GTM["GTM Implementation Environment"]
        GTMInterface["Google Tag Manager Interface"]
    end

    subgraph Library["30 Seconds GTM Library"]
        Template["Snippet Template"]
        Documentation["Documentation"]
    end

    subgraph Categories["Snippet Categories"]
        subgraph GA4Conv["GA4 Conversion Snippets"]
            AddToCart["GA4 to FB Add to Cart"]
            BeginCheckout["GA4 to FB Begin Checkout"]
            ItemsToPixel["GA4 Items to FB Pixel"]
            Purchase["GA4 to FB Purchase"]
            ViewItem["GA4 View Item to FB"]
        end

        subgraph Utils["Utility Scripts"]
            AdBlock["AdBlock Detection"]
            Slug["String to Slug"]
            Device["Device Detection"]
            FormData["Form Data Capture"]
            ClientID["GA4 Client/Session ID"]
            LegacyID["Legacy Client IDs"]
        end

        subgraph UAConv["UA Conversion Snippets (Deprecated)"]
            ECAdd["EC Add to Cart"]
            ECDetail["EC Detail to View"]
            ECImp["EC Impressions"]
            ECClick["EC Product Click"]
            ECRemove["EC Remove from Cart"]
        end
    end

    subgraph Platforms["Target Platforms"]
        GA4["Google Analytics 4"]
        FB["Facebook Pixel"]
        UA["Universal Analytics"]:::deprecated
    end

    %% Relationships
    GTMInterface --> Library
    Library --> Categories
    GA4Conv --> GA4
    GA4Conv --> FB
    Utils --> GTMInterface
    UAConv --> UA
    Template --> Categories
    Documentation --> Categories

    %% Click Events
    click AddToCart "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/convertGa4AddToCartToFacebookAddToCart.md"
    click BeginCheckout "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/convertGa4BeginCheckoutToInitiateCheckoutFacebook.md"
    click ItemsToPixel "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/convertGa4ItemsToFacebookPixelContents.md"
    click Purchase "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/convertGa4PurchaseToFacebookPurchase.md"
    click ViewItem "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/convertViewItemGa4ToViewContentFacebook.md"
    
    click AdBlock "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/checkAdBlockerPresence.md"
    click Slug "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/convert-string-in-slug.md"
    click Device "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/getDeviceType.md"
    click FormData "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/getFormDataOnFormSubmit.md"
    click ClientID "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/getGa4ClientIdAndSessionId.md"
    click LegacyID "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/getClientsIdsByTrackingId.md"
    
    click ECAdd "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/ecAddToCartToAddToCart.md"
    click ECDetail "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/ecDetailToViewItem.md"
    click ECImp "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/ecImpressionsToViewItemList.md"
    click ECClick "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/ecProductClickToSelectItem.md"
    click ECRemove "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippets/ecRemoveFromCartToRemoveFromCart.md"
    
    click Template "https://github.com/lucianfialho/30-seconds-gtm/blob/main/snippet-template.md"
    click Documentation "https://github.com/lucianfialho/30-seconds-gtm/blob/main/README.md"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef deprecated fill:#e0e0e0,stroke:#999,stroke-width:2px,stroke-dasharray: 5 5
    classDef platform fill:#b3e0ff,stroke:#0066cc,stroke-width:2px
    classDef active fill:#d4edda,stroke:#28a745,stroke-width:2px
    classDef utility fill:#fff3cd,stroke:#ffc107,stroke-width:2px

    class UA,UAConv deprecated
    class GA4,FB,GTMInterface platform
    class GA4Conv active
    class Utils utility
```
