Skip to content

How to avoid TagManager.initialize() running many times #112

Open
@vanminhquangtri

Description

@vanminhquangtri

Hello.

In my React component, I have to get gtm-ID from another data which change many time. Each time this data changes, my component render. And each time component renders, function TagManager.initialize runs again, this create duplicate gtm scripts (as attached).

My code:

useEffect(() => {
   if (data.gtm_id){
     TagManager.initialize({
      gtmId: data.gtm_id,
     });
   }
}, [data.gtm_id])

Could you please advise me how to avoid function TagManager.initialize() to run if it already run?

Thank you.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions