Skip to content

Jinja2 macro for placing Google Tag Manager code in templates.

License

Notifications You must be signed in to change notification settings

dbarchowsky/django-jinja2-gtm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-jinja-gtm

Jinja2 macro to install your Google Tag Manager account in Jinja2 templates (http://www.google.com/tagmanager/)

Installation and Usage

  1. Run pip install git+https://github.com/dbarchowsky/django-jinja2-gtm#egg=django-jinja2-gtm
  2. Add template directory to the DIRS property of TEMPLATES in yourapp/settings.py:
        os.path.join(DJANGO_ROOT, os.pardir, 'jinja2_gtm', 'jinja2'),
  1. In yourapp/settings.py create a constant to store the Google Tag Manager container id, e.g. GOOGLE_TAG_ID = 'GTM_XXXXXX'
  2. Import the constant into yourapp/jinja2.py, and add it to the Jinja2 environment in order to make it available to all templates.
  3. Add {% from "gtm/gtm.html" import gtm %} to template.
  4. Add {{ gtm(GOOGLE_TAG_ID) }} right after the <body> tag.

The template that defines the macro is gtm/gtm.html, if for any reason it needs to be overridden.

About

Jinja2 macro for placing Google Tag Manager code in templates.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published