Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Matomo user commands #191

Closed

Conversation

kesara
Copy link

@kesara kesara commented Jul 7, 2021

Ability to push custom commands to Matomo (#190)
Might be a work around for #141

Copy link
Member

@bittner bittner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your effort! I just had a few comments, then I think this is ready for merging.

for var_code in ['_paq.push(["setIgnoreClasses", "no-tracking"]);',
'_paq.push(["setDocumentTitle", "foobar"]);',
'_paq.push(["tackGoal", 1, 1000.01]);']:
assert var_code in r
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this up into 3 separate assert statements. Then the actual failing test will be easier to spot. Thank you!

Comment on lines +119 to +121
'matomo_commands': [['setIgnoreClasses', 'no-tracking'],
['setDocumentTitle', 'foobar'],
['tackGoal', 1, 1000.01]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe like this?

Suggested change
'matomo_commands': [['setIgnoreClasses', 'no-tracking'],
['setDocumentTitle', 'foobar'],
['tackGoal', 1, 1000.01]]
'matomo_commands': [
['setIgnoreClasses', 'no-tracking'],
['setDocumentTitle', 'foobar'],
['tackGoal', 1, 1000.01],
]

@SilverStrings024
Copy link

SilverStrings024 commented Jul 12, 2021

I actually have this in my PR to fix #141 but for some reason git isn't letting me push.
edit: The fix is in my PR #193 it should do what you were talking about here if you utilize the new analytical.utils.build_paq_cmd.
You can also use analytical.utils.get_event_bind_js() to get a piece of javascript that gwets all elements with the classname you provided then it loops those elements binding an event to each one and each event simply pushes the _paq command you want.
So, you would make your own template tag and use those two commands (or just the one to get JS for binding events) to push/bind anything to elements. You can provide enableHeartbeatTimer to analytical.utils.build_paq_cmd() and it will give you this back "_paq.push(['enableHeartbeattimer', ])"

You would also, if you wanted to bind events that push matomo events to _paq you can simply make a call to analytical.utils.get_event_bind_js(matomo_event="contentInteraction", class_name="yourTagClassName", args=['eventCategory', 'eventName']) which returns something like this which you can inject into your template

var elems = document.getElementByClassName('yourTagClassName'); for (var i=0; i++; i < elems.length){{ elems[i].addEventListener("click", function(){{ _paq.push(['contentInteraction', 'eventCategory', 'eventName']); }} ); }}

@kesara
Copy link
Author

kesara commented Jul 13, 2021

@bittner Thanks for looking at my PR. Looks like #193 implements this in more generic way. So I'll close this PR.
@SilverStrings024 Can you add documentation with an example for on your PR?

@kesara kesara closed this Jul 13, 2021
@SilverStrings024
Copy link

@bittner Thanks for looking at my PR. Looks like #193 implements this in more generic way. So I'll close this PR.
@SilverStrings024 Can you add documentation with an example for on your PR?

Yeah, I just need to get the points Bitner hit before I can merge. If you want, you can just take the code and install the package locally then modify it to use my PR. Until I have to time to hit all Bitners points, I can't work on this.

@SilverStrings024
Copy link

@bittner Thanks for looking at my PR. Looks like #193 implements this in more generic way. So I'll close this PR.
@SilverStrings024 Can you add documentation with an example for on your PR?

Yeah, I just need to get the points Bitner hit before I can merge and I'll add in the docs before pushing next. If you want, you can just take the code and install the package locally then modify it to use my PR. Until I have to time to hit all Bitners points, I can't work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants