2022-05-06 16:29:58 +02:00
|
|
|
import ckan.plugins.toolkit as tk
|
2022-05-06 18:01:29 +02:00
|
|
|
from ckanext.googleanalytics import utils
|
2022-05-06 16:29:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_helpers():
|
|
|
|
return {
|
2022-05-06 18:01:29 +02:00
|
|
|
"googleanalytics_header": googleanalytics_header,
|
|
|
|
"googleanalytics_resource_prefix": googleanalytics_resource_prefix,
|
2022-05-06 16:29:58 +02:00
|
|
|
}
|
|
|
|
|
2022-05-06 18:01:29 +02:00
|
|
|
|
|
|
|
def googleanalytics_resource_prefix():
|
|
|
|
|
|
|
|
return utils.config_prefix()
|
|
|
|
|
|
|
|
|
|
|
|
def googleanalytics_header():
|
2022-05-06 16:29:58 +02:00
|
|
|
"""Render the googleanalytics_header snippet for CKAN 2.0 templates.
|
|
|
|
|
|
|
|
This is a template helper function that renders the
|
|
|
|
googleanalytics_header jinja snippet. To be called from the jinja
|
|
|
|
templates in this extension, see ITemplateHelpers.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2022-05-06 18:01:29 +02:00
|
|
|
fields = utils.config_fields()
|
2022-05-06 16:29:58 +02:00
|
|
|
|
2022-05-06 18:01:29 +02:00
|
|
|
if utils.config_enable_user_id() and tk.c.user:
|
2022-05-06 16:29:58 +02:00
|
|
|
fields["userId"] = str(tk.c.userobj.id)
|
|
|
|
|
|
|
|
data = {
|
2022-05-06 18:01:29 +02:00
|
|
|
"googleanalytics_id": utils.config_id(),
|
|
|
|
"googleanalytics_domain": utils.config_domain(),
|
2022-05-06 16:29:58 +02:00
|
|
|
"googleanalytics_fields": str(fields),
|
2022-05-06 18:01:29 +02:00
|
|
|
"googleanalytics_linked_domains": utils.config_linked_domains(),
|
2022-05-06 16:29:58 +02:00
|
|
|
}
|
|
|
|
return tk.render_snippet(
|
|
|
|
"googleanalytics/snippets/googleanalytics_header.html", data
|
|
|
|
)
|