Skip to content

Commit

Permalink
Add option to target based on URL
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Jan 18, 2019
1 parent 9d972df commit c105a2f
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 646 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is an open-source alternate to the [Hello Bar](https://www.hellobar.com/) s
![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/AnandChowdhary/hello-bar.svg)
[![Made in Enschede](https://img.shields.io/badge/made%20in-Enschede-brightgreen.svg)](https://cityofenschede.com/)

[![NPM](https://nodei.co/npm/hello-bar.png)](https://nodei.co/npm/hello-bar/)
[![NPM](https://npm.im/hello-bar.png)](https://nodei.co/npm/hello-bar/)

![Hello Bar demo](https://raw.githubusercontent.com/AnandChowdhary/hello-bar/master/demo.gif)

Expand Down Expand Up @@ -45,7 +45,7 @@ new HelloBar({

### Customization

These are the default values, and you can customize them to the values in comments:
These are all the options you can use in the constructor:

```js
new HelloBar({
Expand All @@ -72,14 +72,17 @@ new HelloBar({
params: { // Support for URL param targeting
// Add key-value pairs here
},
// Some examples below
location: { // Add targeting by location
eu: false, // Set to true to only show in EU countries
country: null // Add array of countries to show in,
city: null // Add array of cities to show in,
ip: null // Add array of IP addresses to show in,
postal: null // Add array of postal codes to show in,
region: null // Add array of regions to show in
}
country: ["us", "ca", "in"], // Array of countries to show in,
city: ["New Delhi"], // Array of cities to show in,
ip: ["192.168.1.1"], // Array of IP addresses to show in,
postal: [110048], // Array of postal codes to show in,
region: ["California"], // Array of regions to show in
},
pathName: "/about", // Only show on this path,
href: "https://example.com/about" // Only show on this URL
}
});
```
Expand Down Expand Up @@ -108,7 +111,7 @@ You can show a cookie law message only in the European Union (EU) using somethin
```js
new HelloBar({
text: '🍪 We use cookies and storage on our website. <a class="cta" href="/privacy-policy">Privacy policy</a>',
fixed: true, // Position fixed for this message,
fixed: true,
position: "bottom",
targeting: {
onceUser: true,
Expand Down Expand Up @@ -153,6 +156,15 @@ window.ga("create", "UA-XXXXX-Y", "auto");
bar.on("cta-mouse-click", e => window.ga("send", "event", "ab-test", e.getAttribute("href")));
```

## Methods

You can use the following methods to manipulate the bar:

| Method | Description |
|-------|-------------|
| `showBar()` | Show the bar |
| `hideBar()` | Hide the bar |

## Events

For analytics, you can listen to events like this:
Expand Down Expand Up @@ -204,4 +216,4 @@ You can listen to the following events. They all return the relevant DOM element

## License

MIT (c) [Anand Chowdhary](https://anandchowdhary.com/?utm_source=github&utm_medium=repository&utm_campaign=hello-bar&utm_term=license-link)
MIT &copy; [Anand Chowdhary](https://anandchowdhary.com/?utm_source=github&utm_medium=repository&utm_campaign=hello-bar&utm_term=license-link)
2 changes: 1 addition & 1 deletion build/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/index.css.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><title>hello-bar demo</title><link href="index.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app!</noscript><div id="root"><h1>Look above &uarr;</h1><div class="options"><div><input id="option1" type="radio" name="demoMessage" value="large-star" checked="checked"> <label for="option1">GitHub star message</label></div><div><input id="option2" type="radio" name="demoMessage" value="cookie-law-1"> <label for="option2">Cookie law message (shows everywhere)</label></div><div><input id="option3" type="radio" name="demoMessage" value="cookie-law-2"> <label for="option3">EU cookie law message (shows only if you're in the EU)</label></div><div><input id="option4" type="radio" name="demoMessage" value="random"> <label for="option4">A/B testing message</label></div></div><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris non lorem quam. Nunc at risus auctor felis semper semper. Proin nec consectetur dolor, eu congue tellus. Nulla ac libero viverra, aliquam mi eget, auctor diam. Vestibulum eget leo consequat, tempus eros ac, bibendum ligula. Etiam non lobortis augue, eget eleifend mi. Etiam felis sem, elementum sit amet lacinia ac, dignissim at eros. Mauris tincidunt, arcu ut vulputate maximus, tellus leo rhoncus ante, vitae viverra est lectus a erat. Fusce semper vehicula laoreet.</p></div><script src="index.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><title>hello-bar demo</title><link href="index.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app!</noscript><div id="root"><h1>Look above &uarr;</h1><div class="options"><div><input id="option1" type="radio" name="demoMessage" value="large-star" checked="checked"> <label for="option1">GitHub star message</label></div><div><input id="option2" type="radio" name="demoMessage" value="cookie-law-1"> <label for="option2">Cookie law message (shows everywhere)</label></div><div><input id="option3" type="radio" name="demoMessage" value="cookie-law-2"> <label for="option3">EU cookie law message (shows only if you're in the EU)</label></div><div><input id="option5" type="radio" name="demoMessage" value="evening"> <label for="option5">Evening message (shows only after 8 pm)</label></div><div><input id="option4" type="radio" name="demoMessage" value="random"> <label for="option4">A/B testing message</label></div></div><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris non lorem quam. Nunc at risus auctor felis semper semper. Proin nec consectetur dolor, eu congue tellus. Nulla ac libero viverra, aliquam mi eget, auctor diam. Vestibulum eget leo consequat, tempus eros ac, bibendum ligula. Etiam non lobortis augue, eget eleifend mi. Etiam felis sem, elementum sit amet lacinia ac, dignissim at eros. Mauris tincidunt, arcu ut vulputate maximus, tellus leo rhoncus ante, vitae viverra est lectus a erat. Fusce semper vehicula laoreet.</p></div><script src="index.js"></script></body></html>
Loading

0 comments on commit c105a2f

Please sign in to comment.