Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In the process of upgrading the module to dev to use UA code, I wanted to add some custom code snippets that relay of some tokens. in order to do so, i had to add token_replace after the variable_get and thought that this could be a gread addition to the module so everybody can add tokens there.
Comment | File | Size | Author |
---|---|---|---|
#25 | Screenshot from 2018-05-03 16:46:54.png | 172.62 KB | vakulrai |
#25 | Screenshot from 2018-05-03 16:46:54.png | 172.62 KB | vakulrai |
#21 | allow-tokens-in-and-before-js-2207089-21.patch | 3.92 KB | harsha012 |
#9 | Issue-2207089-Allow-tokens-in-before-and-after-js-fi.patch | 3.82 KB | hass |
Comments
Comment #1
ymeiner CreditAttribution: ymeiner commentedComment #2
ymeiner CreditAttribution: ymeiner commentedComment #3
ymeiner CreditAttribution: ymeiner commentedComment #4
hass CreditAttribution: hass commentedThanks for sharing. Please add some tests with examples. And do not forget to add the input validation we used in custom variables.
Comment #5
hass CreditAttribution: hass commentedThese also need to call
drupal_json_encode
callback for every value or code injection is possible and JS code can break.TAB
Comment #6
KeyboardCowboyThis patch adds the token tree to the admin page, validates against PII tokens (like v1.x variables did) and runs the tokens through drupal_json_encode.
Comment #7
hass CreditAttribution: hass commentedThanks a lot for the patch. Can you port this to D8 too, please?
Comment #8
KeyboardCowboyI would love to port this to D8 as well, however I am pretty far behind in my D8 training and my time is very scarce right now. If I can find the time to clean up the issues on my own modules I will make this a higher priority.
Comment #9
hass CreditAttribution: hass commentedI'm not really sure about the use cases here if I look into the token list. Can you share some examples that make it worth adding the performance penalty, please?
There is also a known problem I have not tested myself if taxonomy/term pages are overridden with a view. I have optimized and re-roled the patch a bit. "user" seems not required as token_tree shows current-user by default.
The rest of the code looks really good, but we need tests for this. May also add a test with views as it's documented to be an issue.
Comment #10
KeyboardCowboyThanks, @hass.
Our use case is that we wanted to track progress through multi-page webforms and we were using 'events' or 'custom dimensions' to get the data to GA since the URL for a multipage webform does not change. The only way I could find to do this was to create a custom token to represent the page of the webform the user was on and pass that into the GA Before field. It's working great for us.
I based the solution on the way custom variables worked in the older GA version.
Comment #11
hass CreditAttribution: hass commentedAre you able to share these code examples so we may use it later in a tests?
Comment #12
KeyboardCowboyThe following code generates the tokens.
Then I add this into the GA "Code snippet (before)" UI:
ga('send', 'event', 'webform', 'progress', [node:webform-page]);
Comment #13
hass CreditAttribution: hass commentedComment #14
Plazik CreditAttribution: Plazik as a volunteer commentedThis event will be sent to GA on every page view.
It's better to send this event only on webform pages using custom hook which we are developing at #231451: Add hook to alter data before sending it to browser.
Comment #15
harsha012 CreditAttribution: harsha012 as a volunteer and at Red Crackle commentedAdded patch as per 8.2x version
Comment #21
harsha012 CreditAttribution: harsha012 as a volunteer and at Red Crackle commentedimproved patch
Comment #22
hass CreditAttribution: hass commentedHas someone tested if the
clear => TRUE
may destroy JS code?e.g.
[name*='man']
may look like a token.Comment #23
hass CreditAttribution: hass commentedComment #24
hass CreditAttribution: hass commentedDo you plan to update the patch with tests or should we close the case because of inactivity?
Comment #25
vakulrai CreditAttribution: vakulrai as a volunteer and at gai Technologies Pvt Ltd for gai Technologies Pvt Ltd commentedi have applied the patch give by #21 but it is breaking when applied.
My working drupal branch is 8.6.0
Comment #26
japerryWith the sunset of legacy google analytics, the 8.x-2.x module is now unsupported. If this is still an issue with the 4.x version, please file a new issue in the queue.