django-google-analytics icon indicating copy to clipboard operation
django-google-analytics copied to clipboard

Added settings key and removed need to use quoted template tag arguments

Open dessibelle opened this issue 11 years ago • 1 comments

I modified this app in order to suit my needs, and thought I might as well share my modifications. They can be considered add-ons only, as the app stil retains all of its current functionality. I didn't want to put my GA account code in my template, so I thought I'd just supply the analytics template tag with a variable holding my key. That didn't work since the tag required input to be quoted in double quotes. I therefore ended up making the following to modifications to the app:

  1. Quoting of the template tag input argument is no longer required. Instead leading/trailing quotes (single and double) are regexed away if present.
  2. If the settings key GOOGLE_ANALYTICS_KEY is present in your project its value will be used as code by the template tag if no code is supplied. At the moment this setting also takes precedence over the Sites-framework based solution (as that is what suited my needs).

This has the following implications (improvements if you ask me):

  • {% analytics %} will return the code specified in settings.GOOGLE_ANALYTICS_KEY if present, and otherwise use the Sites framework.
  • {% analytics my_code %} is now also an options (my_code being a template variable holding the code).
  • {% analytics "UA-123456-7" %} still works fine, as does {% analytics 'UA-123456-7' %} and {% analytics UA-123456-7 %}.

dessibelle avatar Jan 25 '14 12:01 dessibelle

Haha, could've checked the existing PR's beforehand :smile:

dessibelle avatar Jan 25 '14 12:01 dessibelle