I needed the ability to track content blocks so I created this patch.

It adds a config option to enable the tracking of content impressions. A description is included how to alter your content so Piwik is able to track it.

Comments

PatrickScheffer created an issue. See original summary.

patrickscheffer’s picture

hass’s picture

Version: 7.x-2.8 » 8.x-1.x-dev
Status: Active » Needs work
  1. +++ b/piwik.admin.inc
    @@ -272,6 +272,49 @@ function piwik_admin_settings_form($form_state) {
    +    '#markup' => '<div class="description">' . t('Add the attribute <strong>data-track-content</strong> or class <strong>piwikTrackContent</strong> to an HTML element to track it as a content block.<br /><br />Provide block info by applying the following attributes to the corresponding HTML elements:<ul><li><strong>data-content-name:</strong> The name of the content block.</li><li><strong>data-content-piece:</strong> The actual block content.</li><li><strong>data-content-target:</strong> The URL attached to this block.</li></ul>') . '</div>',
    

    Can you use #description, please? I don't know why you use item and markup.

  2. +++ b/piwik.admin.inc
    @@ -272,6 +272,49 @@ function piwik_admin_settings_form($form_state) {
    +      '!docs' => l(t('Piwik Docs'), 'http://piwik.org/docs/content-tracking', array(
    

    We never use l() in translatable strings.

  3. +++ b/piwik.admin.inc
    @@ -272,6 +272,49 @@ function piwik_admin_settings_form($form_state) {
    +          'target' => '_blank',
    

    We never use target.

Uninstall is missing.

patrickscheffer’s picture

Status: Needs work » Needs review
StatusFileSize
new4.62 KB

I've processed your comments. Why have you changed the tag to 8.x-1.x-dev?

hass’s picture

Issue tags: -piwik, -analytics, -content tracking

A patch need to go into D8 very first, than it can be backported to previous versions.

hass’s picture

Status: Needs review » Needs work
  1. +++ b/piwik.admin.inc
    @@ -272,6 +272,43 @@ function piwik_admin_settings_form($form_state) {
    +    '#default_value' => variable_get('piwik_track_content_impressions', 0),
    

    Notpicking, but it should be FALSE I think.

  2. +++ b/piwik.admin.inc
    @@ -272,6 +272,43 @@ function piwik_admin_settings_form($form_state) {
    +    '#type' => 'item',
    

    Why are you using #type item?

  3. +++ b/piwik.admin.inc
    @@ -272,6 +272,43 @@ function piwik_admin_settings_form($form_state) {
    +    '#description' => '
    +      &lt;div <strong>data-track-content data-content-name="My Ad"</strong>&gt;<br />
    +        &nbsp;&nbsp;&lt;img src="http://www.example.com/path/xyz.jpg" <strong>data-content-piece</strong> /&gt;<br />
    +        &nbsp;&nbsp;&lt;a href="/anylink" <strong>data-content-target</strong>&gt;Add to shopping cart&lt;/a&gt;<br />
    +      &lt;/div&gt;',
    

    This a translatable string, isn't it?

  4. +++ b/piwik.admin.inc
    @@ -272,6 +272,43 @@ function piwik_admin_settings_form($form_state) {
    +    '#markup' => t('See the !docs for full documentation.', array(
    

    Incorrect code style/translatable string as noted before.

patrickscheffer’s picture

1. All the other variables are saved as 0, so I just go with the flow.
2. I'm using the #type item to prevent overflowing the description of the previous element and to make the code more readable.
3. It's a code example so it's not translatable.
4. What should it look like? I'm afraid I don't see it.

hass’s picture

patrickscheffer’s picture

Thanks for the link, learned something new. I've updated the translatable string to match the standards.

hass’s picture

+++ b/piwik.admin.inc
@@ -272,6 +272,43 @@ function piwik_admin_settings_form($form_state) {
+      &lt;div <strong>data-track-content data-content-name="My Ad"</strong>&gt;<br />
...
+        &nbsp;&nbsp;&lt;a href="/anylink" <strong>data-content-target</strong>&gt;Add to shopping cart&lt;/a&gt;<br />

Looks like a translatable string. At least some foreign people who do not speak English may not understand what "Add to shopping cart" should mean.

hass’s picture

Are you planing to fix the remaining issues or should we close the case?

patrickscheffer’s picture

I'm not going to fix the remaining issues so you can close the case.

hass’s picture

Status: Needs work » Closed (won't fix)