Skip to content

Commit 74a9bc4

Browse files
committed
updating README
1 parent 4d37ba7 commit 74a9bc4

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,19 @@ The status and response from the server are passed to the callback function, whi
179179
};
180180
```
181181

182+
You can also use this to track outbound links on your website. For example you would have a link like this:
183+
184+
<a href="javascript:trackClickLinkA();">Link A</a>
185+
186+
And then you would define a function that is called when the link is clicked like this:
187+
188+
```javascript
189+
var trackClickLinkA = function() {
190+
amplitude.logEvent('Clicked Link A', null, function() {
191+
window.location="LINK_A_URL";
192+
});
193+
}
194+
```
182195
You can also pass a callback function to init, which will get called after the SDK finishes its asynchronous loading. Note: no values are passed to the init callback function:
183196

184197
amplitude.init("YOUR_API_KEY_HERE", "USER_ID_HERE", null, callback_function);

test/browser/amplitudejs.html

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,27 @@
5252
var city = prompt('Input city', 'San Francisco, CA');
5353
amplitude.setUserProperties({city: city});
5454
};
55+
var addToPhotoCount = function() {
56+
var photoCount = parseInt(prompt('Input amount to increment photo count by', '2'), 10);
57+
amplitude.identify(new amplitude.Identify().add('photoCount', photoCount));
58+
}
5559
var clickOnLinkA = function() {
5660
amplitude.logEvent('Clicked on link A', null, function() { window.location='https://www.google.com'; });
5761
};
62+
var setPhotoCount = function() {
63+
var photoCount = parseInt(prompt('Input photo count to set', '2'), 10);
64+
amplitude.identify(new amplitude.Identify().set('photoCount', photoCount));
65+
}
66+
var setOncePhotoCount = function() {
67+
var photoCount = parseInt(prompt('Input photo count to setOnce', '2'), 10);
68+
amplitude.identify(new amplitude.Identify().setOnce('photoCount', photoCount));
69+
}
5870
</script>
5971
<script>
6072
amplitude.init('a2dbce0e18dfe5f8e74493843ff5c053');
6173
amplitude.setVersionName('Web');
6274
amplitude.identify(new amplitude.Identify().add('photoCount', 1));
63-
//amplitude.identify(new amplitude.Identify().add('photoCount', 1).set('gender', 'male').unset('karma'););
75+
amplitude.identify(new amplitude.Identify().add('photoCount', 1).set('gender', 'male').unset('karma'));
6476
amplitude.logEvent('pageLoad');
6577
</script>
6678
<body>
@@ -71,13 +83,16 @@ <h3>Amplitude JS Test</h3>
7183
<li><a href="javascript:logEvent();">Log event</a></li>
7284
<li><a href="javascript:amplitude.logEvent('clicked button', {color: 'red;', shape: 'triangle', sides: 3});">Log
7385
event with event properties</a></li>
74-
<li><a href="javascript:amplitude.setUserProperties({age: 30, city: 'San Francisco, CA'});">Set user properties</a>
75-
</li>
86+
<li><a href="javascript:amplitude.setUserProperties({age: 30, city: 'San Francisco, CA'});">Set user properties</a></li>
7687
<li><a href="javascript:amplitude.options.batchEvents = !amplitude.options.batchEvents;">Toggle batch events</a></li>
7788
<li><a href="javascript:setEventUploadThreshold();">Set event upload threshold</a></li>
78-
<li><a href="javascript:amplitude.identify(new amplitude.Identify().add('photoCount', 1));">Increment photo count</a></li>
79-
<li><a href="javascript:setCity();">Set city via setUserProperties</a></li>
80-
<li><a href="javascript:amplitude.identify(new amplitude.Identify().unset('photoCount'));">Unset photo count</a></li>
8189
<li><a href="javascript:clickOnLinkA();">Click on link A</a></li>
90+
<br><br>Testing Identify calls<br>
91+
<li><a href="javascript:addToPhotoCount();">Add to photo count</a></li>
92+
<li><a href="javascript:amplitude.identify(new amplitude.Identify().unset('photoCount'));">Unset photo count</a></li>
93+
<li><a href="javascript:setPhotoCount();">Set photo count</a></li>
94+
<li><a href="javascript:setOncePhotoCount();">Set photo count once</a></li>
95+
<li><a href="javascript:setCity();">Set city via setUserProperties</a></li>
96+
8297
</body>
8398
</html>

0 commit comments

Comments
 (0)