Instead of changing your tags to add / remove cookieDomain when moving between localhost and yourdomain.com, I do the following to automatically set cookieDomain based on hostname.
- Create a custom JS variable that will be used to set the cookieDomain value.
- Variable Name: XYZ-JS-CookieDomain (or whatever your naming convention)
- Type: Custom JavaScript
Code (debugging stuff is how I execute all my custom JS variables, this is not required):
function() { var result = {{Page Hostname}} == 'localhost' ? 'none' : 'auto'; if ({{Debug Mode}}) { console.warn('XYZ-JS-CookieDomain', result); } return result; }
- Customize the tag.
- Advanced Settings> Fields for Installation
- Field Name: cookieDomain
- Value: {{XYZ-JS-CookieDomain}}
Now, when you start cookieDomain from localhost, it will be set to "none", and in another place it will be "auto".
stevieg
source share