forked from ckan/ckanext-googleanalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
19 changed files
with
234 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 24 additions & 14 deletions
38
ckanext/googleanalytics/templates/googleanalytics/snippets/_gtag.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
<!-- Google tag (gtag.js) --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id={{googleanalytics_id}}"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
{% block main %} | ||
<!-- Google tag (gtag.js) --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id={{googleanalytics_id}}"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
|
||
gtag('set', 'linker', ); | ||
gtag('js', new Date()); | ||
{% block setup %} | ||
gtag('set', 'linker'); | ||
|
||
gtag('config', '{{googleanalytics_id}}', { | ||
anonymize_ip: true, | ||
linker: { | ||
domains: {{ googleanalytics_linked_domains|tojson }} | ||
} | ||
}); | ||
</script> | ||
gtag('js', new Date()); | ||
|
||
gtag('config', '{{googleanalytics_id}}', { | ||
anonymize_ip: true, | ||
linker: { | ||
domains: {{ googleanalytics_linked_domains|tojson }} | ||
} | ||
}); | ||
{% endblock setup %} | ||
|
||
{% block extra %} | ||
{% endblock extra %} | ||
|
||
</script> | ||
|
||
{% endblock %} |
7 changes: 7 additions & 0 deletions
7
ckanext/googleanalytics/templates/googleanalytics/snippets/_gtm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- Google Tag Manager --> | ||
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': | ||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], | ||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= | ||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); | ||
})(window,document,'script','dataLayer','{{googleanalytics_id}}');</script> | ||
<!-- End Google Tag Manager --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% ckan_extends %} | ||
|
||
{% block page %} | ||
{% block googleanalytics_body_script %} | ||
{% if h.googleanalytics_tracking_mode() == "gtm" %} | ||
{% with id = h.googleanalytics_id() %} | ||
<!-- Google Tag Manager (noscript) --> | ||
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id={{ id }}" | ||
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> | ||
<!-- End Google Tag Manager (noscript) --> | ||
{% endwith %} | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{{ super() }} | ||
{% endblock page %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
|
||
from ckanext.googleanalytics import config | ||
|
||
|
||
@pytest.mark.parametrize(("tracking_id", "mode"), [ | ||
("UA-123", "ga"), | ||
("G-123", "gtag"), | ||
("GTM-123", "gtm"), | ||
("HELLO-123", "ga"), | ||
]) | ||
def test_tracking_mode(tracking_id, mode, monkeypatch, ckan_config): | ||
monkeypatch.setitem(ckan_config, config.CONFIG_TRACKING_ID, tracking_id) | ||
assert mode == config.tracking_mode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.usefixtures("clean_db") | ||
@pytest.mark.usefixtures("with_plugins", "clean_db") | ||
def test_script(app): | ||
resp = app.get("/") | ||
assert "GoogleAnalyticsObject" in resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
import six | ||
import ckan.plugins.toolkit as tk | ||
from ckanext.googleanalytics import config | ||
|
||
|
||
def _render_header(mode, tracking_id): | ||
return tk.render_snippet("googleanalytics/snippets/_{}.html".format(mode), { | ||
"googleanalytics_id": tracking_id, | ||
"googleanalytics_domain": config.domain(), | ||
"googleanalytics_fields": config.fields(), | ||
"googleanalytics_linked_domains": config.linked_domains() | ||
}) | ||
|
||
|
||
@pytest.mark.usefixtures("with_plugins", "with_request_context") | ||
class TestCodeSnippets: | ||
@pytest.mark.parametrize("mode", ["ga", "gtag", "gtm"]) | ||
@pytest.mark.parametrize("tracking_id", ["UA-123", "G-123", "GTM-123"]) | ||
def test_tracking_(self, mode, tracking_id, app, ckan_config, monkeypatch): | ||
snippet = tk.h.googleanalytics_header() | ||
monkeypatch.setitem(ckan_config, config.CONFIG_TRACKING_ID, tracking_id) | ||
monkeypatch.setitem(ckan_config, config.CONFIG_TRACKING_MODE, mode) | ||
snippet = _render_header(mode, tracking_id) | ||
resp = app.get("/about") | ||
assert six.ensure_str(snippet) in resp |
Oops, something went wrong.