Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Hand-code social media share buttons
colak wrote #312230:
p. Nice omission of the
else
statement!!!
Thanks. I had been looking for an opportunity to try that out since I read etc’s primer.
Would oui_cookie be able to do that?
I think so. I am hoping to come up with something more elegant than this.
Offline
Re: Hand-code social media share buttons
michaelkpate wrote #312231:
Thanks. I had been looking for an opportunity to try that out since I read etc’s primer.
I think so. I am hoping to come up with something more elegant than this.
Yes, you can do that with oui_cookie if you want a purely php-based method. That said, Jukka’s code is almost as minimal as it gets.
If you don’t mind javascript/jquery, I have an experimental fork of jquery.cookiebar. The original almost met my needs of being small, customisable and flexible. I expanded it slightly to properly cater for explicit opt-in, and added the ability to also honour do not track settings by automatically reverting to “decline cookies” while showing a message on first load. You can also do half-way arrangements and explicitly test for do not track or cookies. Its biggest drawback is it requires jquery (though more recent jquery libraries are much smaller), so it’s big if that’s your only use of jquery or small if you are already using jquery. I’m not expert enough yet to rewrite it as pure javascript. Also: it is just for universal cookie consent, not granular consent.
I use it in conjunction with oui_cookie to make a cookie preferences page to allow visitors to revert their decision and to disable google analytics. It works in javascript requirejs setups too.
TXP Builders – finely-crafted code, design and txp
Offline
#15 2018-06-02 22:47:18
- singaz
- Member
- Registered: 2017-03-12
- Posts: 150
Re: Hand-code social media share buttons
Such code:
<div class="analitics">
<script>
if (jQuery.cookieBar('cookies')) {
// Google Analytics code
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'XX-XXXXXXXX-X', 'auto');
ga('send', 'pageview');
}
</script>
</div><!-- endanalitics -->
Click the button “Disable cookies”, but the code analitics displayed all time.
How to do it right?
Sorry my horror English. I’m learning textpattern, I’m learning English
Offline
Re: Hand-code social media share buttons
Hi singaz
It will be much easier to use the oui_cookies plugin:
<txp:oui_cookie name="accept_cookies" values="yes" />
<txp:oui_if_cookie name="accept_cookies">
<txp:hide>your normal google analytics code</txp:hide>
<txp:else />
<a rel="nofollow" href="?accept_cookies=yes">Accept cookies to continue</a>
</txp:oui_if_cookie>
Amend to your liking.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#17 2018-06-05 01:43:52
- singaz
- Member
- Registered: 2017-03-12
- Posts: 150
Re: Hand-code social media share buttons
Hi,
Thanks, kolak!
It is working.
Sorry my horror English. I’m learning textpattern, I’m learning English
Offline